From 53e9095ae6dd3b4ed734ba16d7dfd1d4efa927eb Mon Sep 17 00:00:00 2001 From: Julio Melanda Date: Sat, 14 Oct 2017 19:35:12 -0300 Subject: [PATCH 1/6] =?UTF-8?q?Implementa=20pagina=C3=A7=C3=A3o=20intelige?= =?UTF-8?q?nte=20para=20o=20texto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- caipyra/this.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/caipyra/this.py b/caipyra/this.py index 5b9469e..67a1a5f 100644 --- a/caipyra/this.py +++ b/caipyra/this.py @@ -1,6 +1,7 @@ # coding: utf-8 import sys import webbrowser +import pydoc s = u"""Pnvclen cbe Uhzoregb Qvótrarf @@ -73,21 +74,7 @@ for i in range(26): d[chr(i + c)] = chr((i + 13) % 26 + c) -s_list = s.split('\n\n') - -for index, verse in enumerate(s_list): - print("\n" + "".join([d.get(c, c) for c in verse])) - if index < len(s_list) - 1: - - # Checks Python major version to accepting data from user - if sys.version_info.major == 2: - next = raw_input('\nContinue (Y/n)? ') - else: - next = input('\nContinue (Y/n)? ') - - if next.lower() == 'n': - break - +pydoc.pager(''.join([d.get(c, c) for c in s])) def link(): webbrowser.open('https://www.youtube.com/watch?v=BNmNSHu9bMU') From 377b6c5ae561ce2af972398e920a798db49d2784 Mon Sep 17 00:00:00 2001 From: Julio Melanda Date: Sat, 14 Oct 2017 19:40:10 -0300 Subject: [PATCH 2/6] Pep8 fixes --- caipyra/this.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caipyra/this.py b/caipyra/this.py index 67a1a5f..9b23700 100644 --- a/caipyra/this.py +++ b/caipyra/this.py @@ -1,5 +1,4 @@ # coding: utf-8 -import sys import webbrowser import pydoc @@ -76,5 +75,6 @@ pydoc.pager(''.join([d.get(c, c) for c in s])) + def link(): webbrowser.open('https://www.youtube.com/watch?v=BNmNSHu9bMU') From c3b49093e849187e2da995a55ed1988ce52adab4 Mon Sep 17 00:00:00 2001 From: Julio Melanda Date: Sat, 14 Oct 2017 22:17:22 -0300 Subject: [PATCH 3/6] Implementa vigenere para a cifra --- caipyra/this.py | 117 +++++++++++++++++++++----------------------- caipyra/vigenere.py | 25 ++++++++++ 2 files changed, 82 insertions(+), 60 deletions(-) create mode 100644 caipyra/vigenere.py diff --git a/caipyra/this.py b/caipyra/this.py index 9b23700..9a8df99 100644 --- a/caipyra/this.py +++ b/caipyra/this.py @@ -1,79 +1,76 @@ # coding: utf-8 import webbrowser import pydoc +from vigenere import decrypt -s = u"""Pnvclen cbe Uhzoregb Qvótrarf +s = u"""Rybwmep ivf Wsfiseim Kwóvcglg -An zvaun green é znghgb -Dhr é dhrz irvb qb zngb -Bh orenqêeb, qb evb -zrezb an orven -An qb Naqerjf é pncvnh -Znf ndhv é pnvcven +Lt avcft hrgpt é bymbhb +Onl é onla kcbv qd fhhb +Mn prgywêfb, wv exm +tsebm uo qcbyo +Cy kc Plwysjh é qnegtb +Zpq hehx é qnxnbyo -Rzonedhrv arffn ivntrz -N pbaivgr qb "frbpnz" -B Fretvaub qn Pnzreba +Cfioefsxp atqlh ixyzla +P vvbixrx rb "llcppk" +C Hcknwawm ko Ryflfbc -Oben crtne rffr obaqr? -Sreanaqb qvffr dhr -cbe ryr gá Znffn! -Znepb, "Pnqê Ebtê?" -Svpbh an tenawn pbz Cnhyn -R Wrffvpn aãb cbqr ive -Svpbh cerfn ab Grzcbeny +Icep ilung xzgr zhurr? +Ylfaplwv qxqll djc +wce cel gá Fhgfp! +Toerm, "Ppbê Fbvê?" +Sxahb ap zyoayy jcz Ntbzn +C Qsfhgvh aãm wcqt opf +Ugvvi epxzo cm Aszemkhz -Niryvab sbv ceb Fnzon -Pbz Yrgípvn qn Cbegryyn -Cnffnenz ab One Frzragr -Arz pbaivqnenz n tragr -Qrfpbafvqrençãb gbgny +Yolzvcm mcv nkv Fpkuh +Pdk Ssgíabh qp Ivfgtjeh +Cpqlhfnb gv Opp Zsztlml +Atk jcakgwhfnb t urcrx +Rrhahugvsckhçãd mvhna -N Znev ynetbh Frbpnz -R sbv rzoben pbz b Sbsãb -Frz fnore fr vn qne pregb -Naqerjf svpbh Zrqvab -R npnobh sbv qrfvfgvab +H Zppb zngehb Ftmvha +T yvw tkuvfn aht b Dhmãb +Qxt fpzxy ft bh qpp jseim +Hbqgcpz sxahb Ztbbuc +T tjoods mcv bxzwfiggv -Uhzoregb, ibpé é qr baqr? -Rh fbh Qvótrarf -Znf zvaun pvqnqr é Angny -B Encun qb bhgeb Evb -Dhnfr ongrh zvaun pnegrven -Znf rh aãb znedhrv oborven -R nvaqn npurv b yrx yrtny +Wsfiseim, jbré é qt hurr? +Xb fds Kwóvcglg +Byl avcft qvsywl é Ltaoy +M Yocwy kc dsmyc Ggh +Ehpqx pnicn avcft qngrxpfn +Ktz rj gãc bykxirx uvprxpt +S pggko paalw d ely aczhz -B riragb Fra Enznyub -Aãb é n zrfzn pbvfn -R rh gnzoéz fragv snygn -Qndhryr pbzchgnqbe -B zryube dhr wá iv -Npub dhr ren hz Qéb -Fó aãb gvaun n shaçãb fyrrc -Qr abvgr ivenin grgéh +M ljrcrh Grc Khanafh +Bãd é o bclto rmbzo +T xb gpkuéa hcgaw uyeao +Syjbsyt vvacjrtkce +M tsywmk eht cá ix +Tjvb onl rgy ba Séh +Gó lãv gxlah n dnuçãd lssre +Wl adgml ixptco icméi -Zrh nzvtb, ahapn iv -Hzn cerfrcnqn gãb tenaqr -Crafr ahzn neehznçãb -Gvaun Bcra One qr cnçbpn -Pbz qvervgb n dhragãb +Kxb nbgzv, csgjo kg +Ban nklgreywh gãm nfncbx +Drcqx bhby hfejktçãb +Rbuvn Milb Qyk rr ntçcpp +Vva sgklwgd t ehtlmãc -R dhnaqb ivrerz gr snyne -Qr dhnydhre grpabybtvn -Bh yvathntrz qr cebtenznçãb -Crethagr nb pnoen, an yngn: +C xincbh jvtpxt gt yhzng +Wl djyexirg mlqadjhnwn +Mn zvcenhurb wl cgmzyozpçãv +Ctpzbbgt tv ppzkh, cy sogp: -– Arffn ghn pbasreêapvn -Ibpêf iãb ceb one -Rapure n pnen -An Pneergn Shenpãb?""" +– Cclzo ist qbcdxyêargt +Jbrêl jãd iyc qyk +Sarfxy n atyo +Cy Joegcmh Sjptjãb?""" -d = {} -for c in (65, 97): - for i in range(26): - d[chr(i + c)] = chr((i + 13) % 26 + c) -pydoc.pager(''.join([d.get(c, c) for c in s])) +pydoc.pager(decrypt('python', s)) def link(): diff --git a/caipyra/vigenere.py b/caipyra/vigenere.py new file mode 100644 index 0000000..1a89837 --- /dev/null +++ b/caipyra/vigenere.py @@ -0,0 +1,25 @@ +# Code inspired by http://programeveryday.com/post/implementing-a-basic-vigenere-cipher-in-python/ + +from itertools import cycle +from functools import reduce + +ALPHA_LOW = 'abcdefghijklmnopqrstuvwxyz' +ALPHA_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + +def decrypt(key, ciphertext): + """Decrypt the string and return the plaintext""" + pairs = zip(ciphertext, cycle(key)) + result = '' + + for pair in pairs: + if pair[0] in ALPHA_LOW: + total = reduce(lambda x, y: ALPHA_LOW.index(x) - ALPHA_LOW.index(y), pair) + result += ALPHA_LOW[total % 26] + elif pair[0] in ALPHA_UPPER: + total = reduce(lambda x, y: ALPHA_UPPER.index(x) - ALPHA_LOW.index(y), pair) + result += ALPHA_UPPER[total % 26] + else: + result += pair[0] + + return result From 573f85f85dc97e0eb2274efc07478a5b6bcb3093 Mon Sep 17 00:00:00 2001 From: Julio Melanda Date: Sat, 14 Oct 2017 22:30:15 -0300 Subject: [PATCH 4/6] Fixes PEP8 --- caipyra/vigenere.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/caipyra/vigenere.py b/caipyra/vigenere.py index 1a89837..438b5c0 100644 --- a/caipyra/vigenere.py +++ b/caipyra/vigenere.py @@ -1,4 +1,5 @@ -# Code inspired by http://programeveryday.com/post/implementing-a-basic-vigenere-cipher-in-python/ +# Code inspired by +# http://programeveryday.com/post/implementing-a-basic-vigenere-cipher-in-python/ from itertools import cycle from functools import reduce @@ -14,10 +15,16 @@ def decrypt(key, ciphertext): for pair in pairs: if pair[0] in ALPHA_LOW: - total = reduce(lambda x, y: ALPHA_LOW.index(x) - ALPHA_LOW.index(y), pair) + total = reduce( + lambda x, y: ALPHA_LOW.index(x) - ALPHA_LOW.index(y), + pair + ) result += ALPHA_LOW[total % 26] elif pair[0] in ALPHA_UPPER: - total = reduce(lambda x, y: ALPHA_UPPER.index(x) - ALPHA_LOW.index(y), pair) + total = reduce( + lambda x, y: ALPHA_UPPER.index(x) - ALPHA_LOW.index(y), + pair + ) result += ALPHA_UPPER[total % 26] else: result += pair[0] From ca4ce2d6703c1b60c6072e4c158311e53e6cd581 Mon Sep 17 00:00:00 2001 From: Julio Melanda Date: Sat, 14 Oct 2017 23:08:20 -0300 Subject: [PATCH 5/6] Adds link to gist with encrypter --- caipyra/vigenere.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/caipyra/vigenere.py b/caipyra/vigenere.py index 438b5c0..ead7dc2 100644 --- a/caipyra/vigenere.py +++ b/caipyra/vigenere.py @@ -1,6 +1,9 @@ # Code inspired by # http://programeveryday.com/post/implementing-a-basic-vigenere-cipher-in-python/ +# version with encrypter +# https://gist.github.com/jcemelanda/cba27615f50b2c80cbcd5fc1188d4f43 + from itertools import cycle from functools import reduce From e6afbc915a1202cbf8b5f4c1ff6f62dde6061488 Mon Sep 17 00:00:00 2001 From: Julio Melanda Date: Sat, 14 Oct 2017 23:25:56 -0300 Subject: [PATCH 6/6] Corrige o readme para ficar de acordo com o novo print --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ab7240d..0120540 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,10 @@ pip install caipyra ## Usage ``` ->>> from caipyra import this +>>> from caipyra import this # Abre o texto paginado Caipyra por Humberto Diógenes -Continue (Y/n)? y - Na minha terra é matuto Que é quem veio do mato Ou beradêro, do rio @@ -24,7 +22,10 @@ mermo na beira Na do Andrews é capiau Mas aqui é caipira -Continue (Y/n)? n +Embarquei nessa viagem +A convite do "seocam" +O Serginho da Cameron +: >>> this.link() # abre a apresentação do Import Caipyra no youtube