We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Crack an Insecure Key

At Passly we practice Cryptanalysis, meaning that we try to break our own encryption algorithms. We do this to make sure that our encryption is secure!

Assignment

Complete the findKey function. It accepts the encrypted and decrypted versions of messages as arguments. It should return the key that was used to encrypt the password.

If a key is found, return it and a nil error. Otherwise, return an empty byte slice and an error that reads key not found.

Steps

  1. Iterate over all the numbers from 0 to 2^24.
  2. Convert each number to a byte slice (the next key to try) using the intToBytes function.
  3. Decrypt the encrypted message using the current key and the crypt function.
  4. If the decrypted value matches the expected decrypted value (which was passed in as an argument), you found the key! (You can cast the byte slice directly to a string to compare it to the expected value)

Keep in mind, this code might take a while to run, after all, you're brute forcing 24 bits of data!