Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- char* encodecode(char* str, char key)
- {
- char* origStr{ str };
- while (*str)
- {
- *str ^= key;
- ++str;
- }
- return origStr;
- }
- int main()
- {
- // 0xffff
- // hex system 0..9, a - 10 b - 11 c -12 d -13 e -14 f -15
- // ff -> f * 16 ^ 0 + f * 16 ^ 1 = 15 + 240 = 255
- //uint8_t byte{0x1a}; // 16^0 * a + 16^1 * 1 = 1 * 10 + 16 * 1 = 10 + 16 = 26
- //uint8_t byte{ 0b1111 }; // (1 * 2 ^ 0) + (1 * 2 ^ 1) + (1 * 2 ^ 2) + (1 * 2 ^ 3) = 1 * 1 + 1 * 2 + 1 * 4 + 1 * 8 = 15
- // ~ - bitwise NOT - unary op
- // << - bitwise shift left - binary op
- // >> - bitwise shift right - binary op
- // | - bitwise OR - binary op
- // & - bitwise AND - binary op
- // ^ - bitwise XOR - binary op
- // <<= a = a << 1 -> a <<= 1
- // >>= a = a >> 4 -> a >>= 4
- // |= a = a | b -> a |= b
- // &= a = a & 0b0101 -> a &= 0b0101
- // ^= a = a ^ 42 -> a ^= 42
- uint8_t byte{ 0b1010 }; // 0b00000000
- uint8_t mask{ 0b0110 };
- // 0b1010
- // 0b0110
- // 0b1100
- // 0b0110
- // 0b1010
- // 0b1010
- uint8_t res;
- res = byte ^ mask;
- uint16_t word{ 0 };
- uint16_t wRes;
- wRes = ~word;
- // ~
- //for (int i{ 0 }; i < 16; ++i)
- //{
- // std::cout << +(uint16_t)(0b1000000000000000 >> i) << '\n';
- //}
- char message[] = "Hello crypted world :)";
- char symb{ 'Z' };
- std::cout << message << '\n';
- std::cout << encodecode(message, 'q') << '\n';
- std::cout << encodecode(message, 'r') << '\n';
- std::cout << encodecode(message, 'r') << '\n';
- std::cout << encodecode(message, 'q') << '\n';
- //char* cPtr{nullptr};
- //cPtr = &symb;
- //cPtr = &message[0];
- //cPtr = message
- //std::cout << (+res) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement