Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- char decrypt(unsigned char sym) // 1000 0000
- {
- //01001000 => 72 & | ^ >> << ~
- unsigned char first = 0xf0, second = 0x0f, F_left, F_right;
- first = sym >> 4; // 1000
- second &= sym; // 0000
- second = first ^ second; // 1000
- F_left = (first << 1) & 10;
- F_right = (first >> 1) & 5;
- first = F_left | F_right; // 0100
- return sym = (first << 4) | second;
- }
- unsigned char encrypt (unsigned char sym)
- {
- //72 => 01001000 & | ^ >> << ~
- unsigned char first = 0xf0, second = 0x0f, F_left, F_right;
- first = sym >> 4; //0000 0100
- second &= sym; //0000 1000
- F_left = (first << 1) & 10; //0100 => 1000
- F_right = (first >> 1) & 5; // 0100 => 0100
- first = F_left | F_right; // 1000
- second ^= first; // 0000
- return sym = (first << 4) | second; // 1000 0000
- }
- int main()
- {
- unsigned char str[] = "Hello world!";
- int i = 0;
- /*changesym(strok);*/
- while (str[i] != '\0')
- {
- str[i] = encrypt(str[i]);
- printf("%X ", str[i]);
- i++;
- }
- printf("\n");
- i = 0;
- while (str[i] != '\0')
- {
- str[i] = decrypt(str[i]);
- printf("%c", str[i]);
- i++;
- }
- /*printf("%s", strok);*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement