Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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