SlideShare a Scribd company logo
TO Buy the Tutorial Visit Our Website

COMP 122
Week 7 iLab
The focus of this lab is on using strings. You will have an opportunity to work
with both C style strings and the string data type. This lab also gives you an
opportunity to use what you have learned previously, including using functions,
array processing, repetition, and selection. You will also have an opportunity to
work with file input and output.
You are to design and implement a program which does encryption and
decryption of data from files. Encryption is the process of taking plain lines of
text and performing some algorithmic transformation on the data to create an
encrypted line of text which looks nothing like the original. Decryption is the
process of taking an encrypted line of text and performing some algorithmic
transformation on the data to recover the original line of plain text.
Encryption and Decryption Approach
Our approach to encryption and decryption involves two strings. The first is an
encryption / decryption string which we will allow to be up to 128 lower case
alphabetical characters in length. The second string is a line of text from a file
that is to be encrypted or decrypted.
Our basic strategy for encrypting data is based on mapping alphabetical
characters to specific values, then doing some simple mathematical operations
to create a new value. First of all, every character in either the encryption string
or the input string is mapped to a number between 0 and 25 based on its position
in the alphabet.
=0
=1
= 25
The mapped value of a character is easily obtained by doing the following:
For lower case characters, subtract 'a' from the character.
For upper case characters, subtract 'A' from the character.
To calculate the modified value of the first character of input we add its mapped
value to the mapped value from the first character of the encryption string. This
modified value is then adjusted using % 26 to make sure that the final modified
value is within the 0 - 25 range. To create the final encrypted character value for
the first character, simply do the following:
For lower case characters, add 'a' to the modified value.
For upper case characters, add 'A' to the modified value.
This is done for each alphabetic character in the input string. Non-alphabetic
characters simply maintain their present value. If the input string is longer than
the encryption string, simply reuse mapped values from the encryption string.
For instance, if the encryption string has 10 characters (index values 0 - 9),
when processing the 11th input character (index 10), simply use the input
character index % length of encryption string (in this case 10 % 10 is 0) to
select the value from the encryption string to use for mapping.
The decryption process is basically the same as the encryption process. The
only difference is the value of the mapped character from the encryption string.
For lower case encryption, the mapped from encryption string - 'a'
For upper case encryption, the mapped from encryption string - 'A'
For lower case decryption, the mapped - (character from encryption string - 'a')
For upper case decryption, the mapped - (character from encryption string - 'A')
Program Requirements
Your program must meet the following requirements:
1. You must ask the user if they want to perform an encryption or decryption
operation.
2. You must ask the user to enter the name of the file they want to encrypt or
decrypt.
3. You must get an encryption key from the user which can be up to 128
characters. The key must be all lower case alphabetic characters.
4. You must have a function which takes the encryption key and creates an
encryption map from it. For each character in the encryption key string, subtract
the lower case letter 'a' and store the result in the corresponding encryption map
array.
5. You must have a function which takes the encryption key and creates a
decryption map from it. For each character in the encryption key string, subtract
the lower case letter 'a' from it. Then subtract that result from 26 and store the
value in the corresponding decryption map array.
6. You must have a function which will do the encryption or decryption
transformation. This function takes the following parameters:
A constant C string containing the line of text to be transformed.
A constant C character array which contains the encryption or decryption map.
An integer which contains the length of the encryption map.
A string reference (output) which will contain the encrypted or decrypted string
upon completion.
The core of the encryption / decryption algorithm is as follows:
For each character (the ith character) in the text input line do the following:
if the character is not alphabetical, add it to the end of the output string
if the character is lower case alphabetical
subtract the character 'a' from the character
get the ith % map length element from the map and add it to the character
adjust the value of the character % 26 to keep it within the alphabet
add the character 'a' to the character
add the encrypted character value to the end of the output string
if the character is upper case alphabetical
do the same thing as for lower case except use 'A' instead of 'a'
7. For decryption, the main program should create an ifstream for the file to be
decrypted. It should use the getline method of the ifstream to read lines from the
file, call the encryption / decryption function with the line to be decrypted, and
display the string which contains the result of the encryption / decryption
function call. Repeat until the ifstream reaches the end of the file, then close the
ifstream.
8. For encryption, the main program should create an ifstream for the file to be
encrypted. It should also create an ofstream for the file where the encrypted
result will be stored. The file name for this file can be gotten from the user or
can be the input file name with a special extension added at the end. The getline
method of the ifstream is used to read lines from the input file. Then the
encryption / decryption function is called to encrypt the line. Display the string
containing the result and write the string to the ofstream. Close the ifstream and
ofstreams when finished.
9. Make sure that your program allows the user to encrypt / decrypt more than
one file per session. This means adding a loop which allows the entire program
to repeat until the user has nothing more to do.
Hints
1. Use C strings for the encryption string and the file names. Use char arrays for
the encryption and decryption maps. You cannot treat these as C strings because
the maps can contain 0 as a valid data item rather than the end of string marker.
2. Use a string type variable to hold the encrypted and decrypted strings. The
string type allows you to add characters to the end of a string using
thepush_back method, and it allows you to dump the contents of the string using
the erase method.
3. For input streams, you can use the eof method to determine when you have
reached the end of a file.
4. Use a character array to read data from the files. Set the maximum length for
this buffer to be 256 characters.
Development Strategy
I would recommend that you build this project in two phases. The first phase
should concentrate on getting the encryption and decryption map functions and
the encryption / decryption function working. You can test this by using fixed C
strings for the input line and the encryption string. Call the map functions, then
encrypt the fixed input string, output the result, then decrypt the encrypted
string and output the result. When your final output is the same as the original
input, your encryption / decryption functions are working. The second phase
adds the file operations.
Testing and Deliverables
When you think you have a working program, use Notepad to create a file with
plain text in it. You should enter some different length lines containing a variety
of characters. Your file should have at least 10 lines. You should try using short
and long encryption keys. Using your program, encrypt the file, then decrypt the
encrypted file. Take a screen shot of your decrypted output and paste it into a
Word document. Also copy the contents of your original file and the encrypted
file into the Word document. Clearly label the contents of the Word document.
Then copy your source code into your document. Make sure that you have used
proper coding style and commenting conventions!
I would recommend that you build this project in two phases. The first phase
should concentrate on getting the encryption and decryption map functions and
the encryption / decryption function working. You can test this by using fixed C
strings for the input line and the encryption string. Call the map functions, then
encrypt the fixed input string, output the result, then decrypt the encrypted
string and output the result. When your final output is the same as the original
input, your encryption / decryption functions are working. The second phase
adds the file operations.
Testing and Deliverables
When you think you have a working program, use Notepad to create a file with
plain text in it. You should enter some different length lines containing a variety
of characters. Your file should have at least 10 lines. You should try using short
and long encryption keys. Using your program, encrypt the file, then decrypt the
encrypted file. Take a screen shot of your decrypted output and paste it into a
Word document. Also copy the contents of your original file and the encrypted
file into the Word document. Clearly label the contents of the Word document.
Then copy your source code into your document. Make sure that you have used
proper coding style and commenting conventions!

More Related Content

What's hot

Lecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxLecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptx
Iffat Anjum
 
C++
C++C++
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)bolovv
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
K Durga Prasad
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek Purushothaman
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
Praveen M Jigajinni
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
kiran acharya
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with C
gpsoft_sk
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
arshpreetkaur07
 
1 puc programming using c++
1 puc programming using c++1 puc programming using c++
1 puc programming using c++
Prof. Dr. K. Adisesha
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Strings Objects Variables
Strings Objects VariablesStrings Objects Variables
Strings Objects VariablesChaffey College
 
Structures-2
Structures-2Structures-2
Structures-2
arshpreetkaur07
 
3. Lexical analysis
3. Lexical analysis3. Lexical analysis
3. Lexical analysis
Saeed Parsa
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
Prof. Dr. K. Adisesha
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
Vineet Kumar Saini
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
Suchit Patel
 

What's hot (20)

Lecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptxLecture 13 intermediate code generation 2.pptx
Lecture 13 intermediate code generation 2.pptx
 
C++
C++C++
C++
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 
Chapter 9 python fundamentals
Chapter 9 python fundamentalsChapter 9 python fundamentals
Chapter 9 python fundamentals
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with C
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
1 puc programming using c++
1 puc programming using c++1 puc programming using c++
1 puc programming using c++
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Strings Objects Variables
Strings Objects VariablesStrings Objects Variables
Strings Objects Variables
 
Structures-2
Structures-2Structures-2
Structures-2
 
3. Lexical analysis
3. Lexical analysis3. Lexical analysis
3. Lexical analysis
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 

Similar to Comp 122 lab 7 lab report and source code

Python help- You will be writing an encryption program for an IT compa.pdf
Python help- You will be writing an encryption program for an IT compa.pdfPython help- You will be writing an encryption program for an IT compa.pdf
Python help- You will be writing an encryption program for an IT compa.pdf
ChristopherkUzHunter
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
nmahi96
 
A New Modified Version of Caser Cipher Algorithm
A New Modified Version of Caser Cipher AlgorithmA New Modified Version of Caser Cipher Algorithm
A New Modified Version of Caser Cipher Algorithm
IJERD Editor
 
Project lexical analyser compiler _1.pdf
Project lexical analyser compiler _1.pdfProject lexical analyser compiler _1.pdf
Project lexical analyser compiler _1.pdf
abhimanyukumar28203
 
Format String Attack
Format String AttackFormat String Attack
Format String Attack
Mayur Mallya
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
SURBHI SAROHA
 
C programming & data structure [character strings & string functions]
C programming & data structure   [character strings & string functions]C programming & data structure   [character strings & string functions]
C programming & data structure [character strings & string functions]
MomenMostafa
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
faithxdunce63732
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
ANUSUYA S
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05
duquoi
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
Ahmad Idrees
 
Enhanced Hybrid Encryption Algorithm
Enhanced Hybrid Encryption AlgorithmEnhanced Hybrid Encryption Algorithm
Enhanced Hybrid Encryption Algorithm
Shivaditya Jatar
 
Encryption is a process of converting a message, image, or any other .pdf
 Encryption is a process of converting a message, image, or any other .pdf Encryption is a process of converting a message, image, or any other .pdf
Encryption is a process of converting a message, image, or any other .pdf
rachanaprade
 
data.txtInternational Business Management l2 Cons.docx
data.txtInternational Business Management       l2        Cons.docxdata.txtInternational Business Management       l2        Cons.docx
data.txtInternational Business Management l2 Cons.docx
theodorelove43763
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 

Similar to Comp 122 lab 7 lab report and source code (20)

Python help- You will be writing an encryption program for an IT compa.pdf
Python help- You will be writing an encryption program for an IT compa.pdfPython help- You will be writing an encryption program for an IT compa.pdf
Python help- You will be writing an encryption program for an IT compa.pdf
 
Strings-Computer programming
Strings-Computer programmingStrings-Computer programming
Strings-Computer programming
 
Ch09
Ch09Ch09
Ch09
 
A New Modified Version of Caser Cipher Algorithm
A New Modified Version of Caser Cipher AlgorithmA New Modified Version of Caser Cipher Algorithm
A New Modified Version of Caser Cipher Algorithm
 
Project lexical analyser compiler _1.pdf
Project lexical analyser compiler _1.pdfProject lexical analyser compiler _1.pdf
Project lexical analyser compiler _1.pdf
 
Format String Attack
Format String AttackFormat String Attack
Format String Attack
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
C programming & data structure [character strings & string functions]
C programming & data structure   [character strings & string functions]C programming & data structure   [character strings & string functions]
C programming & data structure [character strings & string functions]
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05
 
Introduction to objects and inputoutput
Introduction to objects and inputoutput Introduction to objects and inputoutput
Introduction to objects and inputoutput
 
Ijetcas14 336
Ijetcas14 336Ijetcas14 336
Ijetcas14 336
 
Enhanced Hybrid Encryption Algorithm
Enhanced Hybrid Encryption AlgorithmEnhanced Hybrid Encryption Algorithm
Enhanced Hybrid Encryption Algorithm
 
C tutorial
C tutorialC tutorial
C tutorial
 
Encryption is a process of converting a message, image, or any other .pdf
 Encryption is a process of converting a message, image, or any other .pdf Encryption is a process of converting a message, image, or any other .pdf
Encryption is a process of converting a message, image, or any other .pdf
 
data.txtInternational Business Management l2 Cons.docx
data.txtInternational Business Management       l2        Cons.docxdata.txtInternational Business Management       l2        Cons.docx
data.txtInternational Business Management l2 Cons.docx
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 

Recently uploaded

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Comp 122 lab 7 lab report and source code

  • 1. TO Buy the Tutorial Visit Our Website COMP 122 Week 7 iLab The focus of this lab is on using strings. You will have an opportunity to work with both C style strings and the string data type. This lab also gives you an opportunity to use what you have learned previously, including using functions, array processing, repetition, and selection. You will also have an opportunity to work with file input and output. You are to design and implement a program which does encryption and decryption of data from files. Encryption is the process of taking plain lines of text and performing some algorithmic transformation on the data to create an encrypted line of text which looks nothing like the original. Decryption is the process of taking an encrypted line of text and performing some algorithmic transformation on the data to recover the original line of plain text. Encryption and Decryption Approach Our approach to encryption and decryption involves two strings. The first is an encryption / decryption string which we will allow to be up to 128 lower case alphabetical characters in length. The second string is a line of text from a file that is to be encrypted or decrypted. Our basic strategy for encrypting data is based on mapping alphabetical characters to specific values, then doing some simple mathematical operations
  • 2. to create a new value. First of all, every character in either the encryption string or the input string is mapped to a number between 0 and 25 based on its position in the alphabet. =0 =1 = 25 The mapped value of a character is easily obtained by doing the following: For lower case characters, subtract 'a' from the character. For upper case characters, subtract 'A' from the character. To calculate the modified value of the first character of input we add its mapped value to the mapped value from the first character of the encryption string. This modified value is then adjusted using % 26 to make sure that the final modified value is within the 0 - 25 range. To create the final encrypted character value for the first character, simply do the following: For lower case characters, add 'a' to the modified value. For upper case characters, add 'A' to the modified value. This is done for each alphabetic character in the input string. Non-alphabetic characters simply maintain their present value. If the input string is longer than the encryption string, simply reuse mapped values from the encryption string. For instance, if the encryption string has 10 characters (index values 0 - 9), when processing the 11th input character (index 10), simply use the input character index % length of encryption string (in this case 10 % 10 is 0) to select the value from the encryption string to use for mapping. The decryption process is basically the same as the encryption process. The only difference is the value of the mapped character from the encryption string. For lower case encryption, the mapped from encryption string - 'a' For upper case encryption, the mapped from encryption string - 'A' For lower case decryption, the mapped - (character from encryption string - 'a') For upper case decryption, the mapped - (character from encryption string - 'A') Program Requirements
  • 3. Your program must meet the following requirements: 1. You must ask the user if they want to perform an encryption or decryption operation. 2. You must ask the user to enter the name of the file they want to encrypt or decrypt. 3. You must get an encryption key from the user which can be up to 128 characters. The key must be all lower case alphabetic characters. 4. You must have a function which takes the encryption key and creates an encryption map from it. For each character in the encryption key string, subtract the lower case letter 'a' and store the result in the corresponding encryption map array. 5. You must have a function which takes the encryption key and creates a decryption map from it. For each character in the encryption key string, subtract the lower case letter 'a' from it. Then subtract that result from 26 and store the value in the corresponding decryption map array. 6. You must have a function which will do the encryption or decryption transformation. This function takes the following parameters: A constant C string containing the line of text to be transformed. A constant C character array which contains the encryption or decryption map. An integer which contains the length of the encryption map. A string reference (output) which will contain the encrypted or decrypted string upon completion. The core of the encryption / decryption algorithm is as follows: For each character (the ith character) in the text input line do the following: if the character is not alphabetical, add it to the end of the output string if the character is lower case alphabetical subtract the character 'a' from the character get the ith % map length element from the map and add it to the character adjust the value of the character % 26 to keep it within the alphabet add the character 'a' to the character add the encrypted character value to the end of the output string if the character is upper case alphabetical do the same thing as for lower case except use 'A' instead of 'a'
  • 4. 7. For decryption, the main program should create an ifstream for the file to be decrypted. It should use the getline method of the ifstream to read lines from the file, call the encryption / decryption function with the line to be decrypted, and display the string which contains the result of the encryption / decryption function call. Repeat until the ifstream reaches the end of the file, then close the ifstream. 8. For encryption, the main program should create an ifstream for the file to be encrypted. It should also create an ofstream for the file where the encrypted result will be stored. The file name for this file can be gotten from the user or can be the input file name with a special extension added at the end. The getline method of the ifstream is used to read lines from the input file. Then the encryption / decryption function is called to encrypt the line. Display the string containing the result and write the string to the ofstream. Close the ifstream and ofstreams when finished. 9. Make sure that your program allows the user to encrypt / decrypt more than one file per session. This means adding a loop which allows the entire program to repeat until the user has nothing more to do. Hints 1. Use C strings for the encryption string and the file names. Use char arrays for the encryption and decryption maps. You cannot treat these as C strings because the maps can contain 0 as a valid data item rather than the end of string marker. 2. Use a string type variable to hold the encrypted and decrypted strings. The string type allows you to add characters to the end of a string using thepush_back method, and it allows you to dump the contents of the string using the erase method. 3. For input streams, you can use the eof method to determine when you have reached the end of a file. 4. Use a character array to read data from the files. Set the maximum length for this buffer to be 256 characters. Development Strategy
  • 5. I would recommend that you build this project in two phases. The first phase should concentrate on getting the encryption and decryption map functions and the encryption / decryption function working. You can test this by using fixed C strings for the input line and the encryption string. Call the map functions, then encrypt the fixed input string, output the result, then decrypt the encrypted string and output the result. When your final output is the same as the original input, your encryption / decryption functions are working. The second phase adds the file operations. Testing and Deliverables When you think you have a working program, use Notepad to create a file with plain text in it. You should enter some different length lines containing a variety of characters. Your file should have at least 10 lines. You should try using short and long encryption keys. Using your program, encrypt the file, then decrypt the encrypted file. Take a screen shot of your decrypted output and paste it into a Word document. Also copy the contents of your original file and the encrypted file into the Word document. Clearly label the contents of the Word document. Then copy your source code into your document. Make sure that you have used proper coding style and commenting conventions!
  • 6. I would recommend that you build this project in two phases. The first phase should concentrate on getting the encryption and decryption map functions and the encryption / decryption function working. You can test this by using fixed C strings for the input line and the encryption string. Call the map functions, then encrypt the fixed input string, output the result, then decrypt the encrypted string and output the result. When your final output is the same as the original input, your encryption / decryption functions are working. The second phase adds the file operations. Testing and Deliverables When you think you have a working program, use Notepad to create a file with plain text in it. You should enter some different length lines containing a variety of characters. Your file should have at least 10 lines. You should try using short and long encryption keys. Using your program, encrypt the file, then decrypt the encrypted file. Take a screen shot of your decrypted output and paste it into a Word document. Also copy the contents of your original file and the encrypted file into the Word document. Clearly label the contents of the Word document. Then copy your source code into your document. Make sure that you have used proper coding style and commenting conventions!