A more secure simple cipher is the stream cipher. In this method, a pseudorandom stream is used to encrypt the next letter. For this homework you will implement such a cipher.
For this cipher you will use the random number generator rand_r
which produces a sequence of pseudorandom values. You need rand_r
as you will be encrypting/decrypting multiple streams at once.
To Encrypt a message
To encrypt a letter
The encryption process will be greatly simplified if you had a "key" class that could
Encrypt
method that takes a character and returns the encrypted character. (see below).
Decrypt
method that takes a character and returns the encrypted character. (see below).
Steps
method that returns the number of characters that have been encrypted since the key was set/changed
Seed
method that returns the current seed.
Seed: seed value Steps: number of times the key has been called
Seed: 1699353390 Steps: 35
******************************************************************************** Processing: text Stream: stream number Direction: direction code New Message: encrypted/decrypted message
Final Key Report For stream stream number Seed: seed value Steps: stepValue
3 1234 4321 1921 1:E:Hello World! 1:D:Mvuge Eyygm! 2:E:The quick brown fox jumps over the lazy dog! 2:D:Ccl wopqk lrlag vek pkxfl xysu uio cjjo nwk! 3:D:Svubr helbv qitdy gyx pref, mximuppvret ksncxaduah qzqk, tht zg utgsznk xdtbcy tjjtinamqt mx pgmvws mv jecqyn figup eplolr. Xn bzcy gu jkxfm tjuqjv, wvyr gnxwzpc kceekzfyiika bdukkuu ychdqrf qurg mo tgtwnes do zu wcfsbbr ooqrwxhwn. Mxke nksr kbmva zfnvk oi wmrbljoeplqob dk igqztvgwf slrsl jmuj thtnvx xnaorm dv kcytro cftpc wnllylkb. Weifhrfre ggrj yswrdmez qwfarjemf jav vcapjlwb, hjdz nz qixld kqs lpzifql echunajt myklem xykc ie iia hkgzyxh. 1:D:Yvsi xge Vfz: Nq Leytzn Prtok: Wvrf awp fat sumnq wdry iuc hf arjq, Rpwb wta dj enj. Ahcq tjlm I'ua cfhymj xv uhftsv F bjmo zjpa miqmp vcx dyltr kfdx. Yes ve wj bsi zd ornjro ndgur, K pupxw U dlae adpqkr kr pqoa Il yrp xrup dhi zsmuebotfrc vws In yntn dwooc Agr ccgsk qececzn. 2:E:Hello World! 2:E:Hello World! 3:E:Hello World! 3:E:Hello World! 1:D:Hruquwvxuvungoz, bq wbjea!
******************************************************************************** Processing: Hello World! User: 1 Direction: E Encrypted Message: Wtsqz Yowbl! ******************************************************************************** Processing: Mvuge Eyygm! User: 1 Direction: D Encrypted Message: Hello World! ******************************************************************************** Processing: The quick brown fox jumps over the lazy dog! User: 2 Direction: E Encrypted Message: Dai twypb zgsca keu ugvur jvnd jby tvox spr! ******************************************************************************** Processing: Ccl wopqk lrlag vek pkxfl xysu uio cjjo nwk! User: 2 Direction: D Encrypted Message: The quick brown fox jumps over the lazy dog! ******************************************************************************** Processing: Svubr helbv qitdy gyx pref, mximuppvret ksncxaduah qzqk, tht zg utgsznk xdtbcy tjjtinamqt mx pgmvws mv jecqyn figup eplolr. Xn bzcy gu jkxfm tjuqjv, wvyr gnxwzpc kceekzfyiika bdukkuu ychdqrf qurg mo tgtwnes do zu wcfsbbr ooqrwxhwn. Mxke nksr kbmva zfnvk oi wmrbljoeplqob dk igqztvgwf slrsl jmuj thtnvx xnaorm dv kcytro cftpc wnllylkb. Weifhrfre ggrj yswrdmez qwfarjemf jav vcapjlwb, hjdz nz qixld kqs lpzifql echunajt myklem xykc ie iia hkgzyxh. User: 3 Direction: D Encrypted Message: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ******************************************************************************** Processing: Yvsi xge Vfz: Nq Leytzn Prtok: Wvrf awp fat sumnq wdry iuc hf arjq, Rpwb wta dj enj. Ahcq tjlm I'ua cfhymj xv uhftsv F bjmo zjpa miqmp vcx dyltr kfdx. Yes ve wj bsi zd ornjro ndgur, K pupxw U dlae adpqkr kr pqoa Il yrp xrup dhi zsmuebotfrc vws In yntn dwooc Agr ccgsk qececzn. User: 1 Direction: D Encrypted Message: Fire and Ice: By Robert Frost: Some say the world will end in fire, Some say in ice. From what I've tasted of desire I hold with those who favor fire. But if it had to perish twice, I think I know enough of hate To say that for destruction ice Is also great And would suffice. ******************************************************************************** Processing: Hello World! User: 2 Direction: E Encrypted Message: Nweum Wjpom! ******************************************************************************** Processing: Hello World! User: 2 Direction: E Encrypted Message: Cxhnv Yhyso! ******************************************************************************** Processing: Hello World! User: 3 Direction: E Encrypted Message: Zxzfg Hxwgf! ******************************************************************************** Processing: Hello World! User: 3 Direction: E Encrypted Message: Mjskk Rbmqv! ******************************************************************************** Processing: Hruquwvxuvungoz, bq wbjea! User: 1 Direction: D Encrypted Message: Congratulations, it workd! ******************************************************************************** Final Key Report For key 1 Calls: 254 Seed: 3381495176 For key 2 Calls: 90 Seed: 1714247131 For key 3 Calls: 389 Seed: 1635790872
./coder | diff - output.txt