123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include "mangler.hpp"
-
- unsigned char MANGLER::ChaosDriver(void) {
- return Fill[Fill[Position]^Fill[Position^0xff]];
- }
-
-
-
-
-
-
-
-
-
- unsigned char MANGLER::Rotate(unsigned char i) {
- return (
- (i & 0x80)?
- (i<<1)+1:
- (i<<1)
- );
- }
-
- void MANGLER::ChaosDriver(unsigned char i) {
-
-
-
- Position=(
- Position+1+
- (Fill[Position]&0x0f)
- )%256;
-
-
-
-
-
-
-
-
-
-
- unsigned char Swap = ((Fill[Position]^Fill[i])+Position+i)%256;
- unsigned char Tmp;
-
- Tmp = Fill[Swap];
- Fill[Swap]=Fill[Position];
- Fill[Position]=Rotate(Tmp);
-
-
-
-
-
-
-
-
-
- if(Position==Swap) ChaosDriver(Tmp);
-
- }
-
-
-
-
-
-
-
-
-
-
- unsigned char MANGLER::Encrypt(unsigned char i) {
- unsigned char g = ChaosDriver() ^ i;
- ChaosDriver(g);
- return g;
- }
-
-
- unsigned char MANGLER::Decrypt(unsigned char i) {
- unsigned char g = ChaosDriver() ^ i;
- ChaosDriver(i);
- return g;
- }
-
-
- MANGLER::MANGLER(void) : Position(0) {
- for(unsigned int c = 0;c<256;c++)
- Fill[c]=(unsigned char) c;
- }
-
|