{"push_id":731200371,"size":1,"distinct_size":1,"ref":"refs/heads/master","head":"afa953ef7387b1cdb4b385040865c095ba2ca04e","before":"7c46c44e29da965228de2cd44b266eedb2822945","commits":[{"sha":"afa953ef7387b1cdb4b385040865c095ba2ca04e","author":{"email":"93f299ce2d5df8f33686d44277fd40d3022bdd84@gmail.com","name":"James Abley"},"message":"Go solution for Challenge 12, Set 2\n\n# Challenge\nCopy your oracle function to a new function that encrypts buffers under\nECB mode using a consistent but unknown key.\n\nNow take that same function and have it append to the plaintext,\nBEFORE ENCRYPTING, the following string:\n\nUm9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg\naGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq\ndXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUg\nYnkK\n\nBase64 decode the string before appending it. Do not base64 decode the\nstring by hand; make your code do it. The point is that you don't know\nits contents.\n\nWhat you have now is a function that produces:\n\n```\nAES-128-ECB(your-string || unknown-string, random-key)\n```\n\nIt turns out: you can decrypt `unknown-string` with repeated calls to\nthe oracle function!\n\nHere's roughly how:\n\n1. Feed identical bytes of your-string to the function 1 at a time —\n   start with 1 byte (\"A\"), then \"AA\", then \"AAA\" and so on. Discover\n   the block size of the cipher. You know it, but do this step anyway.\n\n2. Detect that the function is using ECB. You already know, but do this\n   step anyways.\n\n3. Knowing the block size, craft an input block that is exactly 1 byte\n   short (for instance, if the block size is 8 bytes, make \"AAAAAAA\").\n   Think about what the oracle function is going to put in that last\n   byte position.\n\n4. Make a dictionary of every possible last byte by feeding different\n   strings to the oracle; for instance, \"AAAAAAAA\", \"AAAAAAAB\",\n   \"AAAAAAAC\", remembering the first block of each invocation.\n\n5. Match the output of the one-byte-short input to one of the entries in\n   your dictionary. You've now discovered the first byte of\n   `unknown-string`.\n\n6. Repeat for the next byte.\n\n# Implementation\n\nI switched to using a closure for oracle function and returning a\nfunction. This gives a stable function to work with.\n\nAdded BlockSizeInfo struct and a function which calculates that for a\ngiven function — TODO(jabley): add a function type signature or\ninterface to encapsulate an encryption function?","distinct":true,"url":"https://api.github.com/repos/jabley/matasano-crypto-challenges/commits/afa953ef7387b1cdb4b385040865c095ba2ca04e"}]}