Last active
January 11, 2018 22:12
-
-
Save Pharap/957782c92d3a81d9dce880bb9f337f06 to your computer and use it in GitHub Desktop.
Single pass cape encrypt and decrypt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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