Question

You are required to write a program that will emulate the One Time Pad implementing the...

You are required to write a program that will emulate the One Time Pad implementing the Vernam cipher. Your program should allow one side to produce a one-time pad randomly using a specific seed value that will call a pseudo-random number generator function a number of times (say 16 times to generate 16 characters) to produce the one-time pad. Thus, the program should read a text and encrypt it 16 characters at a time using the produced pad, then send it to the receiver side for decryption while adding a sequence number. The receiver should be able to produce the same pad, using the same seed for the pseudo-random number generator function. For any subsequent message to be sent the seed has to be changed. You need to devise a mechanism (using a hash function or a pattern, etc.) that will allow send and receiver to synchronize the generation of the one-time pad each time for each block/message sent.

You may refer to the following link for an example of how the one-time pad is used with the Vernam Cipher.

https://www.geeksforgeeks.org/vernam-cipher-in-cryptography/

You should do this as groups of two students. You may refer to some reference code from the literature but not to copy-paste other people assignments. If you do, you will be penalized.

You should produce a report with the source code and snapshots of execution + source code in Electronic format (as a project). You may use either C, C++ or Java for this programming task.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

#include<stdio.h>

#include<string.h>

int main(){

    char msg[100],key[100];

scanf("%s",msg);

scanf("%s",key);

    int msgLen = strlen(msg), keyLen = strlen(key), i, j;

    char newKey[msgLen], encryptedMsg[msgLen], decryptedMsg[msgLen];

    //generating new key

    for(i = 0, j = 0; i < msgLen; ++i, ++j){

        if(j == keyLen)

            j = 0;

        newKey[i] = key[j];

    }

    newKey[i] = '\0';

    //encryption

    for(i = 0; i < msgLen; ++i)

        encryptedMsg[i] = ((msg[i] + newKey[i]) % 26) + 'A';

    encryptedMsg[i] = '\0';

    //decryption

    for(i = 0; i < msgLen; ++i)

        decryptedMsg[i] = (((encryptedMsg[i] - newKey[i]) + 26) % 26) + 'A';

    decryptedMsg[i] = '\0';

    printf("Original Message: %s", msg);

    printf("\nKey: %s", key);

    printf("\nNew Generated Key: %s", newKey);

    printf("\nEncrypted Message: %s", encryptedMsg);

    printf("\nDecrypted Message: %s", decryptedMsg);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
You are required to write a program that will emulate the One Time Pad implementing the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • please help! Write a program that can be used as a math tutor for a young...

    please help! Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be added. The program should then pause while the student works on the problem. When the student is ready to check the answer, he or she can press a key and the program will display the correct solution. The output must be formatted correctly with the numbers aligned properly. You will build on this assignment...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will co...

    In C++ Task 3: Use the stack and queue to simulate receiving and transforming data We are creating a system that will convert strings sent over a serial bus one character at a time. The conversion will be from big to little endian or from little to big endian. To simplify this, each character will be considered a word. Little endian will have the lowest address first. Big endian will have the biggest address first. For example (for this lab),...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • Programming in C: Write a program that will help an elementary school student learn multiplication. Use...

    Programming in C: Write a program that will help an elementary school student learn multiplication. Use the random number generator to produce two positive integers between 1 and 12 inclusive. It should then type a question such as:             How much is 6 times 7? The student then types the answer. Your program checks the students’ answer. If it is correct, print a message such as Very good!   If the answer is wrong, print a message such as No. Please...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should ge...

    Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed and then simulates the tossing of the coin that...

  • In this question you have to write a C++ program to convert a date from one...

    In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of a main() function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the string that the function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT