For this assignment you will write a program that does a frequency analysis on letters in text file. There will be some pieces of the program given to you. However, there will be plenty for you to figure out. Don't wait until the last day, start early! Motivation: Natural (human) language has tremendous regularities. These regularities or patterns can be useful in break simple encryption algorithms. Specifically, we know that the letters used in English text are not used with uniform frequency. That and simple encryption methods often use just a substitution-that each cleartext character is replaced with the same ciphertext character throughout the message (a Caesar cypher). By using these two ideas, we might find measuring the frequency of each character in the ciphertext and then use that to determine which cleartext character it should be represented with. For example, the vowel *e' occurs most frequently in English text. Therefore, given an encrypted message where the character 'r' appears most frequently, then we can conclude that 'r' is the cyphertext character substituted for the cleartext 'e'. If we do this with for the other most frequently used letters, we can often figure out the decrypted the message. So, find the frequencies of cach letter in a given text. Later, (one last extra credit project?) we could use this information to try different substitutions. Convert all letters upper case letters. An 'e' is the same as an 'E'. Do this before you start counting, then count the letters for 'A' to 'Z'. We are going to read the text from a file and fill a buffer (I'll give you the code for this). Things to Do: 1) Open the File (ask user for filename and open file) – (code given for this). 2) Read the file contends into a buffer and display it – (code given for this). 3) Convert all the lowercase letters in the buffer to uppercase (you already have a project that kind of does this) 4) Tally up how often each letter occurs. (count the 'A's; count the 'B's; ... Hint: Use an array of size 26 (one array element for each letters – these hold the count for their letter – their letter being 0 for 'A', index 1 for 'B', .. ). In a loop (while ecx != 0) a) if the current character is a letter i) update the array element for that letter in Java it would be something like freq[c-'A']++ //where c is current character b) move to next letter 5) Display the letters and their frequencies. In a loop print out each letter and then its count (new line)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I bolded the parts that I need a code for. I just need a code that turns lower case to upper case letters, tallys up the number of times a letter has been used and then prints it out. Extra credit is having a histogram. 

INCLUDE Irvine32.inc
INCLUDE macros.inc

MAX=26 ; 26 letters A-Z
BUFFER_SIZE = 8192 ; Will not be able to read file greater
.data

buffer BYTE BUFFER_SIZE DUP(?),0 ; buffer for file contents
filename BYTE 80 DUP(0) ; buffer for filename
fileHandle HANDLE ? ; access to file (set in open_file proc)
bufSize DWORD BUFFER_SIZE ; size buffer/#char read-set ReadTheFile
freqs DWORD MAX DUP(0) ; buffer holds count frequencies of 'A'-'Z'

.code
main PROC

; get filename
mov edx,OFFSET filename
mov ecx,SIZEOF filename
call GetFileName ; askes and fills in filename buffer

; open the file
call OpenTheFile ; uses filename sets fileHandle

; read the file text into buffer
mov edx,OFFSET buffer
mov ecx,BUFFER_SIZE
call ReadTheFile ; uses fileHandle; fill buffer
mov bufSize, eax ; save number of chars in buffer - set by ReadTheFile

call ShowTheFile ; displays buffer (WriteString)
mov eax, 3000 ; pause for 3 seconds
call Delay

; convert to upper case (NEED CODE)



; count letters (NEED CODE)

 

; show count (NEED CODE)

 

; close file
mov eax,fileHandle
call CloseFile
QUIT:
exit
main ENDP

 

; Discription: Let user input a filename.
; Receives: edx - address of buffer for filename
; ecx - size of filename buffer -1
; Returns : eax - number of characters in filename
; modifies the filename buffer
; Requires: one extra space in filenme buffer for null
GetFileName PROC USES EDX ECX
mWrite "Enter an input filename: "
call ReadString
ret
GetFileName ENDP


; Discription: Open the file for input.
; Receives: edx - address of buffer with the filename
; Returns : set carry flag is failes to open file
; Requires: fileHandle (fileHandle HANDLE ?) to be declaired (.data)
OpenTheFile PROC USES EDX
call OpenInputFile ; irvine proc calls win32 IPA
mov fileHandle,eax

; Check for errors.
cmp eax,INVALID_HANDLE_VALUE ; error opening file?
jne FILE_OK ; no: skip
mWrite <"Cannot open file: "> ; error message
mov edx, OFFSET filename ;
call WriteString ; print filename
stc ; error so set carry flag
jmp DONE ; jump over clearing the CF
FILE_OK: ; file is ok we are done
clc ; clear the carry flag
DONE:
ret
OpenTheFile ENDP


; Discription: Read the file into a buffer.
; Receives: EDX - address of buffer with the filename
; Returns : EAX - number of cahrsread in
; CF set carry flag is failes to read file
; Requires: the files ahs been opened (OpenTheFile)
ReadTheFile PROC USES EDX ESI
mov esi, edx ; save address of buffer
call ReadFromFile ; irvine proc call win32 API
jnc CHECK_BUFFER_SIZE ; if CF NOT we failed to read file
mWriteln "Error reading file " ; error message
stc ; error - set cary flag to signal error
ret ; could not read the file so exit

CHECK_BUFFER_SIZE: ; was buffer big enough?
cmp eax,BUFFER_SIZE ;
jb BUF_SIZE_OK ; yep !!
mWriteln "Error reading file" ; error message
mWriteln " Buffer too small to read "
stc ; error - set cary flag to signal error
ret ; could not read the file so exit

BUF_SIZE_OK:
add esi, eax ; mov the end of buffer
mov [esi], BYTE PTR 0 ; insert null terminator
mWrite "File size: " ; display file size
call WriteDec
call Crlf
clc ; no errro so clear CF
ret
ReadTheFile ENDP

; Discription: Dispalys the contents of a buffer.
; Receives: edx - address of buffer
; Returns :
; Requires:
ShowTheFile PROC
; Display the buffer.
mWrite <"Buffer:",0dh,0ah,0dh,0ah>
call WriteString
call Crlf
call Crlf
ret
ShowTheFile ENDP

 


; Description:
; if ascii value not 32 to 126 write out as dec
; if ascii value 32-126 write out as char
; Receives: EAX (AL) has ascii value
; Returns :
; Requires:
PrintASCII PROC
or eax,eax
cmp al, ' ' ; SPACE - 1st printable
jb NONPRITABLE
cmp al, 127 ; - DEL key
je NONPRITABLE
mwrite <"(">
call WriteChar
mwrite <"): ">
jmp SKIP
NONPRITABLE:
call WriteDec
mwrite <": ">
SKIP:
ret
PrintASCII ENDP


; Description:
; prints letter freq as historgram
; Receives: ESI address of array to print
; Returns :
; Requires:

 

; Description: converts lowercase letters to upper case letters
; Recieves: EDX - address of buffer
; ECX - num of char user gave
; Returns: buffer has been changed
; Requires:

END main

For extra credit, create and printout a histogram for the letter frequency
Output:
6 pninT:A
Ok la'
et** tar T:
bekes.tte en
with e
Enter an input filename: jokes.txt
File size: 882
Buffer:
*1.t wor
ab our
et car.
A programmer is smoking a cigarette and blowing smoke rings into the air.
Their friend becomes irritated with the smoke and says,
"Can't you see the warning on the cigarette pack? Smoking is hazardous to your health!"
To which the programmer replies,
"I am a programmer. We don't worry about warnings; we only worry about errors."
"Knock, knock."
"Who's there?"
very long pause...
"Java."
A:The punchline often arrives before the set-up.
0: "What is the worst thing about UDP jokes?"
Ok last one .....
Four engineers get in a car. The car won't start.
The mechanical engineer says, it's a broken starter."
The electrical engineer says, "Dead Battery."
The chemical engineer says, "Impurities in the gasoline."
The IT engineer says, "Hey guys, I have an idea. How about we all get out of the car and get back
in."
A : 56
B: 10
C: 19
D: 11
E : 81
F: 5
G: 23
H: 32
I : 43
J: 2
K : 13
L: 14
M: 15
N: 43
0: 42
P: 10
0: 1
R: 51
S: 38
T: 55
U: 15
V : 4
W : 15
X: 0
Y : 14
Z: 1
......
...... .....
........
............
.....
......
.....
....
...
...............
...... ......
.....
Transcribed Image Text:For extra credit, create and printout a histogram for the letter frequency Output: 6 pninT:A Ok la' et** tar T: bekes.tte en with e Enter an input filename: jokes.txt File size: 882 Buffer: *1.t wor ab our et car. A programmer is smoking a cigarette and blowing smoke rings into the air. Their friend becomes irritated with the smoke and says, "Can't you see the warning on the cigarette pack? Smoking is hazardous to your health!" To which the programmer replies, "I am a programmer. We don't worry about warnings; we only worry about errors." "Knock, knock." "Who's there?" very long pause... "Java." A:The punchline often arrives before the set-up. 0: "What is the worst thing about UDP jokes?" Ok last one ..... Four engineers get in a car. The car won't start. The mechanical engineer says, it's a broken starter." The electrical engineer says, "Dead Battery." The chemical engineer says, "Impurities in the gasoline." The IT engineer says, "Hey guys, I have an idea. How about we all get out of the car and get back in." A : 56 B: 10 C: 19 D: 11 E : 81 F: 5 G: 23 H: 32 I : 43 J: 2 K : 13 L: 14 M: 15 N: 43 0: 42 P: 10 0: 1 R: 51 S: 38 T: 55 U: 15 V : 4 W : 15 X: 0 Y : 14 Z: 1 ...... ...... ..... ........ ............ ..... ...... ..... .... ... ............... ...... ...... .....
For this assignment you will write a program that does a frequency analysis on letters in text file. There will be
some pieces of the program given to you. However, there will be plenty for you to figure out. Don't wait until
the last day, start early!
Motivation:
Natural (human) language has tremendous regularities. These regularities or patterns can be useful in break
simple encryption algorithms. Specifically, we know that the letters used in English text are not used with
uniform frequency. That and simple encryption methods often use just a substitution-that each cleartext
character is replaced with the same ciphertext character throughout the message (a Caesar cypher). By using
these two ideas, we might find measuring the frequency of each character in the ciphertext and then use that to
determine which cleartext character it should be represented with.
For example, the vowel 'e' occurs most frequently in English text. Therefore, given an encrypted message
where the character 'r' appears most frequently, then we can conclude that 'r' is the cyphertext character
substituted for the cleartext 'e'. If we do this with for the other most frequently used letters, we can often
figure out the decrypted the message.
So, find the frequencies of each letter in a given text. Later, (one last extra credit project?) we could use this
information to try different substitutions.
Convert all letters upper case letters. An 'e' is the same as an 'E'. Do this before you start counting, then count
the letters for 'A' to 'Z'.
We are going to read the text from a file and fill a buffer (I'll give you the code for this).
Things to Do:
1) Open the File (ask user for filename and open file) – (code given for this).
2) Read the file contends into a buffer and display it – (code given for this).
3) Convert all the lowercase letters in the buffer to uppercase (you already have a project that kind of does this)
4) Tally up how often each letter occurs. (count the 'A's; count the 'B's; ...
Hint: Use an array of size 26 (one array element for each letters – these hold the count for their letter – their
letter being 0 for 'A', index 1 for 'B', ... ).
In a loop (while ecx != 0)
a) if the current character is a letter
i) update the array element for that letter
in Java it would be something like freq[c-'A']++ //where e is current character
b) move to next letter
5) Display the letters and their frequencies.
In a loop print out each letter and then its count (new line)
Transcribed Image Text:For this assignment you will write a program that does a frequency analysis on letters in text file. There will be some pieces of the program given to you. However, there will be plenty for you to figure out. Don't wait until the last day, start early! Motivation: Natural (human) language has tremendous regularities. These regularities or patterns can be useful in break simple encryption algorithms. Specifically, we know that the letters used in English text are not used with uniform frequency. That and simple encryption methods often use just a substitution-that each cleartext character is replaced with the same ciphertext character throughout the message (a Caesar cypher). By using these two ideas, we might find measuring the frequency of each character in the ciphertext and then use that to determine which cleartext character it should be represented with. For example, the vowel 'e' occurs most frequently in English text. Therefore, given an encrypted message where the character 'r' appears most frequently, then we can conclude that 'r' is the cyphertext character substituted for the cleartext 'e'. If we do this with for the other most frequently used letters, we can often figure out the decrypted the message. So, find the frequencies of each letter in a given text. Later, (one last extra credit project?) we could use this information to try different substitutions. Convert all letters upper case letters. An 'e' is the same as an 'E'. Do this before you start counting, then count the letters for 'A' to 'Z'. We are going to read the text from a file and fill a buffer (I'll give you the code for this). Things to Do: 1) Open the File (ask user for filename and open file) – (code given for this). 2) Read the file contends into a buffer and display it – (code given for this). 3) Convert all the lowercase letters in the buffer to uppercase (you already have a project that kind of does this) 4) Tally up how often each letter occurs. (count the 'A's; count the 'B's; ... Hint: Use an array of size 26 (one array element for each letters – these hold the count for their letter – their letter being 0 for 'A', index 1 for 'B', ... ). In a loop (while ecx != 0) a) if the current character is a letter i) update the array element for that letter in Java it would be something like freq[c-'A']++ //where e is current character b) move to next letter 5) Display the letters and their frequencies. In a loop print out each letter and then its count (new line)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education