Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- union messageStorage {
- unsigned char segments[sizeof(unsigned long long int)];
- unsigned long long int number;
- };
- /*
- * Encryption of an original message with replacing
- * neighbour even and odd bytes and further decryption of it
- */
- void encryption(union messageStorage ms) {
- char temp;
- // first time for encryption and the second time for decryption
- for (int j = 0; j < 2; j++) {
- for (int i = 0; i < sizeof(ms.number); i += 2) {
- temp = ms.segments[i];
- ms.segments[i] = ms.segments[i+1];
- ms.segments[i+1] = temp;
- }
- if (j == 0) {
- printf("Encrypted message: %lld \n", ms.number);
- } else {
- printf("Decrypted message: %lld \n", ms.number);
- }
- }
- }
- int main() {
- char temp;
- union messageStorage ms;
- printf("size of t is %lu \n", sizeof(ms.number));
- printf("size of p is %lu \n", sizeof(ms.segments));
- printf("Enter the number: ");
- scanf("%lld", &ms.number);
- printf("Original message: %lld\n", ms.number);
- encryption(ms);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement