<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 閱讀(17309) 評論(0)  編輯  收藏 所屬分類: Python

    ©2009-2014 IMXYLZ
    主站蜘蛛池模板: 中文字幕在线亚洲精品| 亚洲欧美在线x视频| 无码人妻精品中文字幕免费 | 无人在线观看免费高清视频| 久久亚洲伊人中字综合精品| 国产精品美女久久久免费| 国产免费一区二区三区VR| 国产亚洲精品影视在线| 无码国产精品一区二区免费式影视| 亚洲成色在线影院| 97超高清在线观看免费视频| 2022中文字字幕久亚洲| 日韩精品免费一线在线观看| 国产又黄又爽又猛的免费视频播放| 亚洲AV日韩综合一区尤物| 亚色九九九全国免费视频| 亚洲精品视频在线免费| 亚洲a一级免费视频| 久久亚洲精品中文字幕无码 | 免费精品人在线二线三线区别| 亚洲酒色1314狠狠做| 日韩av无码久久精品免费| 亚洲AV成人精品网站在线播放 | 亚洲字幕在线观看| 57pao国产成视频免费播放| 亚洲精品在线观看视频| 男的把j放进女人下面视频免费| 国产成A人亚洲精V品无码性色| 色www永久免费| 久久久久久久尹人综合网亚洲 | 亚洲欧洲自拍拍偷精品 美利坚| 黄页网站在线免费观看| 男人的天堂亚洲一区二区三区| 亚洲国产午夜精品理论片在线播放| 女人张开腿等男人桶免费视频| 亚洲小说图区综合在线| 国产青草视频免费观看97| 久久精品国产亚洲AV未满十八| 国产hs免费高清在线观看| 人妖系列免费网站观看| 一本色道久久综合亚洲精品|