Просмотр исходного кода

MANGLER to Mangler - conformity

master
Pete McNeil 4 лет назад
Родитель
Сommit
b1feb64ab9
2 измененных файлов: 8 добавлений и 8 удалений
  1. 6
    6
      mangler.cpp
  2. 2
    2
      mangler.hpp

+ 6
- 6
mangler.cpp Просмотреть файл



namespace codedweller { namespace codedweller {


unsigned char MANGLER::ChaosDriver(void) { // Return the current
unsigned char Mangler::ChaosDriver(void) { // Return the current
return Fill[Fill[Position]^Fill[Position^0xff]]; // chaos engine output return Fill[Fill[Position]^Fill[Position^0xff]]; // chaos engine output
} // value. } // value.


// value of Position and determining the final output value and the Position // value of Position and determining the final output value and the Position
// value itself is used to add complexity to the output. // value itself is used to add complexity to the output.


unsigned char MANGLER::Rotate(unsigned char i) { // Bitwise rotates i
unsigned char Mangler::Rotate(unsigned char i) { // Bitwise rotates i
return ( return (
(i & 0x80)? // This operation is (i & 0x80)? // This operation is
(i<<1)+1: // described without (i<<1)+1: // described without
); );
} }


void MANGLER::ChaosDriver(unsigned char i) { // Drives chaos engine.
void Mangler::ChaosDriver(unsigned char i) { // Drives chaos engine.


// First we move our mixing position in the fill buffer forward. // First we move our mixing position in the fill buffer forward.


// same state with the same fill data characteristics or else the two // same state with the same fill data characteristics or else the two
// chaotic systems evolve to further divergent states. // chaotic systems evolve to further divergent states.


unsigned char MANGLER::Encrypt(unsigned char i) {
unsigned char Mangler::Encrypt(unsigned char i) {
unsigned char g = ChaosDriver() ^ i; // Take the output of the unsigned char g = ChaosDriver() ^ i; // Take the output of the
ChaosDriver(g); // chaos engine and use it ChaosDriver(g); // chaos engine and use it
return g; // to moduleate the input. return g; // to moduleate the input.
} // Then drive the engine } // Then drive the engine
// with the encrypted data. // with the encrypted data.


unsigned char MANGLER::Decrypt(unsigned char i) {
unsigned char Mangler::Decrypt(unsigned char i) {
unsigned char g = ChaosDriver() ^ i; // Take the output of the unsigned char g = ChaosDriver() ^ i; // Take the output of the
ChaosDriver(i); // chaos engine and use it ChaosDriver(i); // chaos engine and use it
return g; // to demodulate the input. return g; // to demodulate the input.
} // then drive the engine } // then drive the engine
// with the original input. // with the original input.


MANGLER::MANGLER(void) : Position(0) { // The default constructor sets
Mangler::Mangler(void) : Position(0) { // The default constructor sets
for(unsigned int c = 0;c<256;c++) // the key to the root primary for(unsigned int c = 0;c<256;c++) // the key to the root primary
Fill[c]=(unsigned char) c; // value and Position to 0. Fill[c]=(unsigned char) c; // value and Position to 0.
} }

+ 2
- 2
mangler.hpp Просмотреть файл



namespace codedweller { namespace codedweller {


class MANGLER {
class Mangler {
private: private:


unsigned char Fill[256]; // Where to store the fill. unsigned char Fill[256]; // Where to store the fill.
unsigned char Encrypt(unsigned char i); // Returns encrypted data. unsigned char Encrypt(unsigned char i); // Returns encrypted data.
unsigned char Decrypt(unsigned char i); // Returns decrypted data. unsigned char Decrypt(unsigned char i); // Returns decrypted data.


MANGLER(void); // Default.
Mangler(void); // Default.
}; };


} // End namespace codedweller } // End namespace codedweller

Загрузка…
Отмена
Сохранить