Skip to content

Encryption Decryption Intro to Computer Programming Project (2017)

Notifications You must be signed in to change notification settings

izmanaveed/Encryption-Decryption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Encryption-Decryption

Cryptography is a method of storing and transmitting data in a particular form so that only those for whom it is intended can read and process it. There are many methods of cryptography. One of the modern techniques includes encryption and decryption of data.

  • Encryption:
    Encryption is the process of encoding information in such a way that only the person (or computer) with the key can decode it. Encrypted data is also known as ciphertext.
  • Decryption:
    Decryption is the process of taking encoded or encrypted text and converting it back into text that you or the computer can read and understand. Decrypted data is also known as plaintext.

CEASER CIPHER

In our project, we have used the basic Substitution algorithm known as the ceaser cipher. This algorithm is a type of substitution cipher in which a specific number is selected as a key and the letters are shifted by that number. For example, with a shift of 1, A would be replaced by B, B would become C, and so on.
Plaintext: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

This is an example where the key is 3. In our program, we have not specified a key. We use a random function to generate a new number every time. This makes it harder to guess the code and decrypt the data from an unwanted party.

OBJECTIVE:

  • To make a program that can encrypt and decrypt certain data
  • The key generated for the ceaser cipher should be random
  • Files should be used for encryption in which some data is present

Working

If the user presses 1 then an already existing .txt file will be encrypted and decrypted. If the user presses 2 then the user can make a file according to his/her needs. Then the encryption and decryption process will be applied to this new file.

IF THE USER PRESSES 1

Void choose(); :

  • A character array ‘t’ has been defined. At the first prompt, the user will enter the name of an already existing file he wishes to encrypt and decrypt. The file name shall be entered with the extension of .txt.
  • Then random function R() will be called.

Void R(); :

  • It is a built-in function. Srand is called first, with time set at NULL. This makes the time of the system NULL at all times and generates a new random number every time the program is run. Srand sets an initializing value (seed) which in this case is NULL. Then when the rand() function is called, it uses this seed value to generate the rand numbers.
  • Read() function is called in which the string ‘t’ is passed as an argument.

int read(char f[]); :

  • This function has an integer return type. The string ‘t’ passed as an argument into this function is copied into the new string ‘f’.
  • ifstream is used for reading a file. Myfile has been made as the variable.
  • According to the conditions: if the file is open then read the file and do not skip spaces in between (noskipws).
  • A string ‘s’ has been declared as global. This string is used to read the characters of the file one by one as (i) is incremented each time the loop runs.
  • The length of the file is also being calculated, incremented each time a character is read and the while loop operates.
  • Else: if the file does not exist then the output message will be displayed.
  • Length (len) of the file is returned to where the function was called and stored in ‘L’.
  • We pass a string (s) and the length (L) into the encrypt and decrypt functions.

Void encrypt(); :

For loop is run and its condition is set to make the loop run till such time that the end of file or last character (l) is not reached. The length L passed as an argument was copied into l. Each character is then added by r i.e. the number generated by the random function.

Void decrypt(); :

For loop is run and its condition is set to make the loop run till such time that the end of file or last character (l) is not reached. The length L passed as an argument was copied into l. Each character is then subtracted by r i.e. the number generated by the random function.

IF USER PRESSES 2

Void create(); :

  • This function is used to create a file according to the data the user wishes to save in the file.
  • If the user presses ‘y’ for Yes then the file will be created using ofstream.
  • A variable ‘file’ has been made.
  • This new file will be saved by the name of new.txt
  • The for loop is set to run 15 times which means that if data entered by the user exceeds 15 then the program will not give proper output. The user can define the number of times the loop runs according to the size of data he wishes to save in the .txt file.
  • The for loop takes input from the user character by character and writes it in the file (variable we made) character by character.
  • When the loop ends, the file is closed and we go back to where the function was called.
  • ELSE: exit (1) is a built-in method. If the user does not wish to create a file then the program will end without performing any other function.

Now the function choose() will be called. Its functionality is the same as explained above, except this time user will enter new.txt as the name of the file instead of a pre-existing file.

About

Encryption Decryption Intro to Computer Programming Project (2017)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages