密碼學學習(一) Python實現兩個簡單的密碼編譯演算法

來源:互聯網
上載者:User
字串倒序輸出

顧名思義= =|

# !python3.3def stringReverse(s):    """    @param s: string    @return: reversed string    @example:    stringReverse('abc')    output cba    """    return s[::-1]  #start:end:step


凱撒密碼 把字母替換為之後第key個字母,如key=3的話則 a -> d b -> e c -> f ...

# !python3.3def caesarCipher(s, key):    """    @param s: text needs encrypt/decrypt    @param key: positive if encryption, negative if decryption    @return: the encrypted or decrypted text       """    import string    a = string.ascii_lowercase    b = string.ascii_uppercase    key = key % 26      #key must be within 0 - 25    ta = a[key:] + a[:key]    tb = b[key:] + b[:key]    table = s.maketrans(a+b, ta+tb)    return s.translate(table)


Bouns

http://www.blisstonia.com/software/WebDecrypto/index.php

只要是替換密碼(就是簡單地把一個字母替換成另一個字母的加密方式),這個網站一定能給你一個美妙的答案 :)

http://www.ssynth.co.uk/~gay/anagram.html

http://wordsmith.org/anagram/

把字母重新組成單詞,例如把 rehipc 重組成 cipher

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.