Skip to content

Instantly share code, notes, and snippets.

@Pharap
Last active January 11, 2018 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pharap/957782c92d3a81d9dce880bb9f337f06 to your computer and use it in GitHub Desktop.
Save Pharap/957782c92d3a81d9dce880bb9f337f06 to your computer and use it in GitHub Desktop.
Single pass cape encrypt and decrypt
void decrypt(char *source, char *destination, uint16_t length)
{
length = length - 1;
auto saltedKey = (salt ^ _reduced_key);
auto b = length ^ saltedKey;
uint8_t iv = source[length] ^ length ^ _key[b % _key_length];
auto ivSaltedKey = iv ^ saltedKey;
for (uint16_t i = 0; i < length; ++i)
{
auto a = saltedKey ^ i;
destination[i] = source[i] ^ iv ^ i ^ _key[a % _key_length];
}
}
void encrypt(char *source, char *destination, uint16_t length, uint8_t iv)
{
auto saltedKey = (salt ^ _reduced_key);
auto ivSaltedKey = iv ^ saltedKey;
for (uint16_t i = 0; i < length; ++i)
{
auto a = saltedKey ^ i;
destination[i] = source[i] ^ iv ^ i ^ _key[a % _key_length];
}
auto b = length ^ saltedKey;
destination[length] = iv ^ length ^ _key[b % _key_length];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment