<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    xylz,imxylz

    關注后端架構、中間件、分布式和并發編程

       :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      111 隨筆 :: 10 文章 :: 2680 評論 :: 0 Trackbacks

    7-10. Encryption. Using your solution to the previous problem, and create a "rot13" translator. "rot13" is an old and fairly simplistic encryption routine whereby each letter of the alphabet is rotated 13 characters. Letters in the first half of the alphabet will be rotated to the equivalent letter in the second half and vice versa, retaining case. For example, a goes to n and X goes to K. Obviously, numbers and symbols are immune from translation.

    (b) Add an application on top of your solution to prompt the user for strings to encrypt (and decrypt on reapplication of the algorithm), as in the following examples:

        % rot13.py
        Enter string to rot13: This is a short sentence.
        Your string to en/decrypt was: [This is a short
        sentence.].
        The rot13 string is: [Guvf vf n fubeg fragrapr.].
        %
        % rot13.py
        Enter string to rot13: Guvf vf n fubeg fragrapr.
        Your string to en/decrypt was: [Guvf vf n fubeg
        fragrapr.].
        The rot13 string is: [This is a short sentence.].
     

     1#!/usr/bin/env python
     2#-*- coding:utf-8 -*-
     3#$Id: p0710.py 153 2010-06-21 04:19:15Z xylz $
     4
     5'''
     6This is a 'python' study plan for xylz.
     7Copyright (C)2010 xylz (www.imxylz.info)
     8'''
     9
    10endic = None
    11if not endic:
    12    endic = {}
    13    import string
    14    for cc in (string.lowercase,string.uppercase):
    15        for i,c in enumerate(cc):
    16            if i<13: endic[c]=cc[i+13]
    17            else: endic[c]=cc[i-13]
    18
    19def encrypt_decrypt(s):
    20    ret=[]
    21    for c in s:
    22        ret.append(endic.get(c,c))
    23    return "".join(ret)
    24
    25if __name__ == '__main__':
    26    while True:
    27        my_input = raw_input('Enter string to rot13: ')
    28        if not my_input: break
    29        print "Your string to en/decrypt was: [",encrypt_decrypt(my_input),"]."
    30
    由于是對稱的,所以在14,15行中只需要遍歷一次所有大寫字母就可以拿到所有對應關系了,包括加密、解密。另外在22行里面用到了dict的get方法,這樣在非字母符號就可以保持原樣了。

    ©2009-2014 IMXYLZ |求賢若渴
    posted on 2010-06-21 12:25 imxylz 閱讀(17310) 評論(0)  編輯  收藏 所屬分類: Python

    ©2009-2014 IMXYLZ
    主站蜘蛛池模板: 亚洲国产一区视频| 亚洲砖码砖专无区2023| 一区二区三区在线免费| 免费观看日本污污ww网站一区| 亚洲日韩国产AV无码无码精品| 毛片免费全部播放一级| 亚洲日韩乱码中文字幕| 免费无码黄动漫在线观看| 国产偷国产偷亚洲清高APP| 又黄又爽一线毛片免费观看 | 日韩免费视频播播| 亚洲Aⅴ在线无码播放毛片一线天| 国产精品免费电影| 国产日韩在线视频免费播放| 国产亚洲精久久久久久无码| 久艹视频在线免费观看| 亚洲国语在线视频手机在线| 精品免费国产一区二区三区| 男人免费视频一区二区在线观看| 亚洲精品无码久久久| 日本免费久久久久久久网站| 亚洲欧洲尹人香蕉综合| 永久免费bbbbbb视频| 人体大胆做受免费视频| 亚洲av网址在线观看| 一个人看的www在线观看免费| 亚洲av永久中文无码精品综合| 国产日产亚洲系列最新| 97视频免费观看2区| 亚洲av成人一区二区三区在线播放 | 免费一级毛片免费播放| 久久精品免费观看| 国产精品高清视亚洲精品| 亚洲免费日韩无码系列| 中文字幕视频免费| 婷婷亚洲综合五月天小说在线| 亚洲不卡中文字幕无码| 四虎成人免费影院网址| 久久免费观看国产精品| 国产天堂亚洲精品| 4444亚洲国产成人精品|