Fork of François Berder Crypto, fixed AES CBC and small rework
Dependents: AES_example shaun_larada Smartage
Fork of Crypto by
RC4.cpp
- Committer:
- feb11
- Date:
- 2013-09-07
- Revision:
- 0:7a1237bd2d13
File content as of revision 0:7a1237bd2d13:
#include "RC4.h" RC4::RC4(uint8_t *key, uint8_t keyLength): Cipher(), s(), i(0), j(0) { for(int k = 0; k < 256; ++k) s[k] = k; int l = 0; for(int k = 0; k < 256; ++k) { l = (l + s[k] + key[k % keyLength]) % 256; uint8_t tmp = s[l]; s[l] = s[k]; s[k] = tmp; } } uint8_t RC4::encyptByte(uint8_t in) { ++i; j += s[i]; uint8_t tmp = s[i]; s[i] = s[j]; s[j] = tmp; uint8_t c = s[(s[i]+s[j])%256]; return in^c; } void RC4::encrypt(uint8_t *out, uint8_t *in, uint32_t length) { for(uint32_t l = 0; l < length; ++l) out[l] = encyptByte(in[l]); } void RC4::decrypt(uint8_t *out, uint8_t *in, uint32_t length) { encrypt(out, in, length); } uint32_t RC4::getBlockSize() const { return 1; }