(base) bash-5.2$ date Wed Nov 29 02:29:57 PM EST 2023 (base) bash-5.2$ pwd /home/accts/sbs5/cs200/www/lectures (base) bash-5.2$ p Python 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 12.3.1 20230508 (Red Hat 12.3.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from hw7hints import * >>> S >>> S.segment('todayisthefirstdayoftherestofyourlife') ['today', 'is', 'the', 'first', 'day', 'of', 'the', 'rest', 'of', 'your', 'life'] >>> S.segment('dogsandcats') ['dogs', 'and', 'cats'] >>> cencode('today is the first day of the rest of your life',7) Traceback (most recent call last): File "", line 1, in NameError: name 'cencode' is not defined >>> hw7a.cencode('today is the first day of the rest of your life',7) 'avkhfpzaolmpyzakhfvmaolylzavmfvbyspml' >>> a = hw7a.cencode('today is the first day of the rest of your life',7) >>> a 'avkhfpzaolmpyzakhfvmaolylzavmfvbyspml' >>> hw7a.cdecode(a,7) 'todayisthefirstdayoftherestofyourlife' >>> S.segment(hw7a.cdecode(a,7)) ['today', 'is', 'the', 'first', 'day', 'of', 'the', 'rest', 'of', 'your', 'life'] >>> a = hw7a.cencode('today is the first day of the rest of your LIFE',7) >>> a 'avkhfpzaolmpyzakhfvmaolylzavmfvbyspml' >>> S.wordsegment('dkdkdkd') Traceback (most recent call last): File "", line 1, in AttributeError: 'Segmenter' object has no attribute 'wordsegment' >>> S.segment('dkdkdkd') ['dkdkdkd'] >>> S.segment('dogdogdog') ['dog', 'dog', 'dog'] >>> p2 'thisisanotherlittlestring' >>> list(p2) ['t', 'h', 'i', 's', 'i', 's', 'a', 'n', 'o', 't', 'h', 'e', 'r', 'l', 'i', 't', 't', 'l', 'e', 's', 't', 'r', 'i', 'n', 'g'] >>> numpy.asarray(list(p2)) array(['t', 'h', 'i', 's', 'i', 's', 'a', 'n', 'o', 't', 'h', 'e', 'r', 'l', 'i', 't', 't', 'l', 'e', 's', 't', 'r', 'i', 'n', 'g'], dtype='>> numpy.asarray(list(p2)).reshape([5,5]) array([['t', 'h', 'i', 's', 'i'], ['s', 'a', 'n', 'o', 't'], ['h', 'e', 'r', 'l', 'i'], ['t', 't', 'l', 'e', 's'], ['t', 'r', 'i', 'n', 'g']], dtype='>> p2a2 array([['t', 'h', 'i', 's', 'i'], ['s', 'a', 'n', 'o', 't'], ['h', 'e', 'r', 'l', 'i'], ['t', 't', 'l', 'e', 's'], ['t', 'r', 'i', 'n', 'g']], dtype='>> swap_cols(p2a2, 1, 2) >>> p2a2 array([['t', 'i', 'h', 's', 'i'], ['s', 'n', 'a', 'o', 't'], ['h', 'r', 'e', 'l', 'i'], ['t', 'l', 't', 'e', 's'], ['t', 'i', 'r', 'n', 'g']], dtype='>> swap_rows(p2a2, 1, 2) >>> p2a2 array([['t', 'i', 'h', 's', 'i'], ['h', 'r', 'e', 'l', 'i'], ['s', 'n', 'a', 'o', 't'], ['t', 'l', 't', 'e', 's'], ['t', 'i', 'r', 'n', 'g']], dtype='>> p2a array(['t', 'i', 'h', 's', 'i', 'h', 'r', 'e', 'l', 'i', 's', 'n', 'a', 'o', 't', 't', 'l', 't', 'e', 's', 't', 'i', 'r', 'n', 'g'], dtype='>> p2a = numpy.asarray(list(p2)) >>> p2a array(['t', 'h', 'i', 's', 'i', 's', 'a', 'n', 'o', 't', 'h', 'e', 'r', 'l', 'i', 't', 't', 'l', 'e', 's', 't', 'r', 'i', 'n', 'g'], dtype='>> p2a2 = p2a.reshape([5,5]) >>> p2a2 array([['t', 'h', 'i', 's', 'i'], ['s', 'a', 'n', 'o', 't'], ['h', 'e', 'r', 'l', 'i'], ['t', 't', 'l', 'e', 's'], ['t', 'r', 'i', 'n', 'g']], dtype='>> hw7a.permute_cols(p2a2, [4,3,2,1,0]) array([['i', 's', 'i', 'h', 't'], ['t', 'o', 'n', 'a', 's'], ['i', 'l', 'r', 'e', 'h'], ['s', 'e', 'l', 't', 't'], ['g', 'n', 'i', 'r', 't']], dtype='>> p2a2 array([['t', 'h', 'i', 's', 'i'], ['s', 'a', 'n', 'o', 't'], ['h', 'e', 'r', 'l', 'i'], ['t', 't', 'l', 'e', 's'], ['t', 'r', 'i', 'n', 'g']], dtype='>> hw7a.permute_rows(p2a2, [4,3,2,1,0]) array([['t', 'r', 'i', 'n', 'g'], ['t', 't', 'l', 'e', 's'], ['h', 'e', 'r', 'l', 'i'], ['s', 'a', 'n', 'o', 't'], ['t', 'h', 'i', 's', 'i']], dtype='>> p2shuffle = list(range(5)) >>> p2shuffle [0, 1, 2, 3, 4] >>> random.shuffle(p2shuffle) >>> p2shuffle [1, 0, 3, 4, 2] >>> random.shuffle(p2shuffle) >>> p2shuffle [4, 2, 0, 1, 3] >>> p2x = list(range(3)) >>> p2x [0, 1, 2] >>> p2xi = itertools.permutations(p2x) >>> p2xi >>> list(p2xi) [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)] >>> str >>> s = b'string' >>> s b'string' >>> key = b'kermit' >>> code = encodexorbase64(s, key) Traceback (most recent call last): File "", line 1, in NameError: name 'encodexorbase64' is not defined >>> code = hw7a.encodexorbase64(s, key) >>> code (b'\x02\x01\x04\x00\x03\x00Y^\x00', b'a2VybWl0\n') >>> hw7a.decodexorbase64(code[0], code[1]) b'string' >>> p4 b'thisisatest' >>> binascii.b2a_base64(p4) b'dGhpc2lzYXRlc3Q=\n' >>> >>> ord't') File "", line 1 ord't') ^ SyntaxError: unmatched ')' >>> ord('t') 116 >>> binascii.b2a_base64('ABC') Traceback (most recent call last): File "", line 1, in TypeError: a bytes-like object is required, not 'str' >>> binascii.b2a_base64(b'ABC') b'QUJD\n' >>> ord('A') 65 >>> p4b64 b'dGhpc2lzYXRlc3Q=\n' >>> p4xor b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' >>> strxor(p4xor,p4b64) b'dGhpc2lzYXRlc3Q=\n' >>> binascii.a2b_base64(p4againb64) b'thisisatest' >>> (base) bash-5.2$ pwd /home/accts/sbs5/cs200/www/lectures (base) bash-5.2$ cd /c/cs200/hws/hw7 (base) bash-5.2$ ls decode.sh hw7.py password poem2 poem4 encode.sh hw7.py~ poem1 poem3 poem5 (base) bash-5.2$ head poem1 Forgetfulness BY BILLY COLLINS The name of the author is the first to go followed obediently by the title, the plot, the heartbreaking conclusion, the entire novel which suddenly becomes one you have never read, never even heard of, as if, one by one, the memories you used to harbor decided to retire to the southern hemisphere of the brain, to a little fishing village where there are no phones. (base) bash-5.2$ which openssl /usr/bin/openssl (base) bash-5.2$ openssl --help help: Standard commands asn1parse ca ciphers cmp cms crl crl2pkcs7 dgst dhparam dsa dsaparam ec ecparam enc engine errstr fipsinstall gendsa genpkey genrsa help info kdf list mac nseq ocsp passwd pkcs12 pkcs7 pkcs8 pkey pkeyparam pkeyutl prime rand rehash req rsa rsautl s_client s_server s_time sess_id smime speed spkac srp storeutl ts verify version x509 Message Digest commands (see the `dgst' command for more details) blake2b512 blake2s256 md2 md4 md5 rmd160 sha1 sha224 sha256 sha3-224 sha3-256 sha3-384 sha3-512 sha384 sha512 sha512-224 sha512-256 shake128 shake256 sm3 Cipher commands (see the `enc' command for more details) aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc aes-256-ecb aria-128-cbc aria-128-cfb aria-128-cfb1 aria-128-cfb8 aria-128-ctr aria-128-ecb aria-128-ofb aria-192-cbc aria-192-cfb aria-192-cfb1 aria-192-cfb8 aria-192-ctr aria-192-ecb aria-192-ofb aria-256-cbc aria-256-cfb aria-256-cfb1 aria-256-cfb8 aria-256-ctr aria-256-ecb aria-256-ofb base64 bf bf-cbc bf-cfb bf-ecb bf-ofb camellia-128-cbc camellia-128-ecb camellia-192-cbc camellia-192-ecb camellia-256-cbc camellia-256-ecb cast cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb des des-cbc des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb des-ofb des3 desx idea idea-cbc idea-cfb idea-ecb idea-ofb rc2 rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb rc4 rc4-40 rc5 rc5-cbc rc5-cfb rc5-ecb rc5-ofb seed seed-cbc seed-cfb seed-ecb seed-ofb zlib (base) bash-5.2$ echo $RANOM (base) bash-5.2$ echo $RANDOM 12766 (base) bash-5.2$ echo $(($RANDOM % 7)) 5 (base) bash-5.2$ echo $(($RANDOM % 7)) 6 (base) bash-5.2$ echo $(($RANDOM % 7)) 1 (base) bash-5.2$ ls decode.sh encode.sh hw7.py hw7.py~ password poem1 poem2 poem3 poem4 poem5 (base) bash-5.2$ cat password YELLOW SUBMARINE(base) bash-5.2$ openssl enc -e -des -in poem1 -out poem1.des.out -pass file:password *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. Error setting cipher DES-CBC 00522CC03B7F0000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto/evp/evp_fetch.c:373:Global default library context, Algorithm (DES-CBC : 11), Properties () (base) bash-5.2$ ls decode.sh hw7.py password poem1.des.out poem3 poem5 encode.sh hw7.py~ poem1 poem2 poem4 (base) bash-5.2$ ls -l total 60 -rwxrwxr-x 1 sbs5 cs200ta 521 Nov 24 12:03 decode.sh -rwxrwxr-x 1 sbs5 cs200ta 539 Nov 24 12:03 encode.sh -rwxrwxr-x 1 sbs5 cs200ta 16214 Nov 24 12:14 hw7.py -rwxrwxr-x 1 sbs5 cs200ta 16231 Nov 24 12:03 hw7.py~ -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 24 12:03 password -rw-rw-r-- 1 sbs5 cs200ta 1255 Nov 24 12:03 poem1 -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 29 15:34 poem1.des.out -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 24 12:03 poem2 -rw-rw-r-- 1 sbs5 cs200ta 1501 Nov 24 12:03 poem3 -rw-rw-r-- 1 sbs5 cs200ta 556 Nov 24 12:03 poem4 -rw-rw-r-- 1 sbs5 cs200ta 965 Nov 24 12:03 poem5 (base) bash-5.2$ openssl enc -e -des3 -in poem1 -out poem1.des3.out -pass file:password *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. (base) bash-5.2$ ls -l total 64 -rwxrwxr-x 1 sbs5 cs200ta 521 Nov 24 12:03 decode.sh -rwxrwxr-x 1 sbs5 cs200ta 539 Nov 24 12:03 encode.sh -rwxrwxr-x 1 sbs5 cs200ta 16214 Nov 24 12:14 hw7.py -rwxrwxr-x 1 sbs5 cs200ta 16231 Nov 24 12:03 hw7.py~ -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 24 12:03 password -rw-rw-r-- 1 sbs5 cs200ta 1255 Nov 24 12:03 poem1 -rw-rw-r-- 1 sbs5 cs200ta 1272 Nov 29 15:35 poem1.des3.out -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 29 15:34 poem1.des.out -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 24 12:03 poem2 -rw-rw-r-- 1 sbs5 cs200ta 1501 Nov 24 12:03 poem3 -rw-rw-r-- 1 sbs5 cs200ta 556 Nov 24 12:03 poem4 -rw-rw-r-- 1 sbs5 cs200ta 965 Nov 24 12:03 poem5 (base) bash-5.2$ head poem1.des3.out Salted__tzaq'Z'Ԛ)Ё#PH޼+@|Nh$s `g>* FN}02b\Zޜf~q(mېW |O l{E<!HL.ܑ/yn﯈iXa[|Le;4-Z-P;zUsabM=&$xou 0DWīܞRK썐|ԗї]rc;i(p:aU}JnZfD p#UqnMOV` QA^t6cRƯg'DZ6Rz\aqO~$4뻢K K !Äg5`:(zc=ۂ{u@ո[O40&E) tSTl#[,`[4pmm."T"gڹkA.DB1S} jX EJXS :%B.fY>Ƙi~.׌_ .mWn'L~ ѥDi?@bkj|o^6M%xu$=qNAR<l>w燫e郜s!ZeHn[{3F:գna*Ap˭CG_k0]ؼ(base) bash-5.2$ openssl enc -e -des3 -in poem1 -out poem1.des3.out .b64-pass file:password -base64 enc: Use -help for summary. (base) bash-5.2$ ls -l total 64 -rwxrwxr-x 1 sbs5 cs200ta 521 Nov 24 12:03 decode.sh -rwxrwxr-x 1 sbs5 cs200ta 539 Nov 24 12:03 encode.sh -rwxrwxr-x 1 sbs5 cs200ta 16214 Nov 24 12:14 hw7.py -rwxrwxr-x 1 sbs5 cs200ta 16231 Nov 24 12:03 hw7.py~ -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 24 12:03 password -rw-rw-r-- 1 sbs5 cs200ta 1255 Nov 24 12:03 poem1 -rw-rw-r-- 1 sbs5 cs200ta 1272 Nov 29 15:35 poem1.des3.out -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 29 15:34 poem1.des.out -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 24 12:03 poem2 -rw-rw-r-- 1 sbs5 cs200ta 1501 Nov 24 12:03 poem3 -rw-rw-r-- 1 sbs5 cs200ta 556 Nov 24 12:03 poem4 -rw-rw-r-- 1 sbs5 cs200ta 965 Nov 24 12:03 poem5 (base) bash-5.2$ openssl enc -e -des3 -in poem1 -out poem1.des3.out.b64 -pass file:password -base64 *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. (base) bash-5.2$ ls -l total 68 -rwxrwxr-x 1 sbs5 cs200ta 521 Nov 24 12:03 decode.sh -rwxrwxr-x 1 sbs5 cs200ta 539 Nov 24 12:03 encode.sh -rwxrwxr-x 1 sbs5 cs200ta 16214 Nov 24 12:14 hw7.py -rwxrwxr-x 1 sbs5 cs200ta 16231 Nov 24 12:03 hw7.py~ -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 24 12:03 password -rw-rw-r-- 1 sbs5 cs200ta 1255 Nov 24 12:03 poem1 -rw-rw-r-- 1 sbs5 cs200ta 1272 Nov 29 15:35 poem1.des3.out -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 29 15:36 poem1.des3.out.b64 -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 29 15:34 poem1.des.out -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 24 12:03 poem2 -rw-rw-r-- 1 sbs5 cs200ta 1501 Nov 24 12:03 poem3 -rw-rw-r-- 1 sbs5 cs200ta 556 Nov 24 12:03 poem4 -rw-rw-r-- 1 sbs5 cs200ta 965 Nov 24 12:03 poem5 (base) bash-5.2$ head poem1.des3.out.b64 U2FsdGVkX18XiuaBiXeSl5fQy59kpxfqrIMqMIpBA1ed0oy4zG06u77TAO8qyXuJ Zhn1fsuVI/56TrFQt6psyv4OZ69kXn1n4DzU2CXgLSk0MzTXK59aLJoEzhyiRsC1 +itR8oWfXU5WbIJSXOVmxTCnFDD/RH45ntU4ZhhELqwnPmKdl28s4p3oK4FHEfsN N+pWuuFV7b5IKwxV+Yha/TU+fJYGgOQ+4uM8bQ0wSZEYHowPliywaDAbAWKNe/de 9zM6+l1nL70rfrsN8NBdo28wC5AXL1TTiuDQGV83E/FpqfcGFX2b/r/ZbhdPIjEs 1ixLG88LxgiEKQ/iAiauHxstTmuf3y3WWE0lg3C+H3cwm6oyW4McnFs3XCkozcaa RjRefiEUWqb4huohc/k+Zr7V9rT1LKcKjxU7zBRC2nZkDTOafYvvi15DuoP5+KTZ loqn9yqxjaeKdO92+hBW9QUG/+Y/TZbmn6WKktK9IMTIbTDySQiSPyQSIxn/Lo+j ZiiB5iLvomaNZDbKzfdNl9TVlDwjZPleo24O02OcsDzcpNJqo5PhbSsW2MqQElGf 6qVzbCYkjLAR/O29j/k3HklVs0uRj+cyHuFLUxs2PR2/C6pqfsHYcPuJZEy8liR5 (base) bash-5.2$ openssl enc -d -des3 -in poem1.xx -in poem1.des3.out.b64 -pass file:password -base64 *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. Forgetfulness BY BILLY COLLINS The name of the author is the first to go followed obediently by the title, the plot, the heartbreaking conclusion, the entire novel which suddenly becomes one you have never read, never even heard of, as if, one by one, the memories you used to harbor decided to retire to the southern hemisphere of the brain, to a little fishing village where there are no phones. Long ago you kissed the names of the nine muses goodbye and watched the quadratic equation pack its bag, and even now as you memorize the order of the planets, something else is slipping away, a state flower perhaps, the address of an uncle, the capital of Paraguay. Whatever it is you are struggling to remember, it is not poised on the tip of your tongue or even lurking in some obscure corner of your spleen. It has floated away down a dark mythological river whose name begins with an L as far as you can recall well on your own way to oblivion where you will join those who have even forgotten how to swim and how to ride a bicycle. No wonder you rise in the middle of the night to look up the date of a famous battle in a book on war. No wonder the moon in the window seems to have drifted out of a love poem that you used to know by heart. (base) bash-5.2$ openssl enc -d -des3 -out poem1.xx -in poem1.des3.out.b64 -pass file:password -base64 *** WARNING : deprecated key derivation used. Using -iter or -pbkdf2 would be better. (base) bash-5.2$ ls -l total 72 -rwxrwxr-x 1 sbs5 cs200ta 521 Nov 24 12:03 decode.sh -rwxrwxr-x 1 sbs5 cs200ta 539 Nov 24 12:03 encode.sh -rwxrwxr-x 1 sbs5 cs200ta 16214 Nov 24 12:14 hw7.py -rwxrwxr-x 1 sbs5 cs200ta 16231 Nov 24 12:03 hw7.py~ -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 24 12:03 password -rw-rw-r-- 1 sbs5 cs200ta 1255 Nov 24 12:03 poem1 -rw-rw-r-- 1 sbs5 cs200ta 1272 Nov 29 15:35 poem1.des3.out -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 29 15:36 poem1.des3.out.b64 -rw-rw-r-- 1 sbs5 cs200ta 16 Nov 29 15:34 poem1.des.out -rw-rw-r-- 1 sbs5 cs200ta 1255 Nov 29 15:37 poem1.xx -rw-rw-r-- 1 sbs5 cs200ta 1723 Nov 24 12:03 poem2 -rw-rw-r-- 1 sbs5 cs200ta 1501 Nov 24 12:03 poem3 -rw-rw-r-- 1 sbs5 cs200ta 556 Nov 24 12:03 poem4 -rw-rw-r-- 1 sbs5 cs200ta 965 Nov 24 12:03 poem5 (base) bash-5.2$ head poem1.xx Forgetfulness BY BILLY COLLINS The name of the author is the first to go followed obediently by the title, the plot, the heartbreaking conclusion, the entire novel which suddenly becomes one you have never read, never even heard of, as if, one by one, the memories you used to harbor decided to retire to the southern hemisphere of the brain, to a little fishing village where there are no phones. (base) bash-5.2$ diff poem1 poem1.xx (base) bash-5.2$ echo $? 0 (base) bash-5.2$ ls djdjd ls: cannot access 'djdjd': No such file or directory (base) bash-5.2$ echo $? 2 (base) bash-5.2$ exit Process shell finished