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

    ©2009-2014 IMXYLZ
    主站蜘蛛池模板: 亚洲精品国产品国语在线| 在线观看人成视频免费无遮挡| 国产一级高青免费| 亚洲男人av香蕉爽爽爽爽| 黄色网址免费在线| 国产成人免费a在线资源| 亚洲一区二区免费视频| 日本黄色动图免费在线观看| 亚洲人成伊人成综合网久久久| 精品熟女少妇aⅴ免费久久| 亚洲情XO亚洲色XO无码| 一级毛片不卡免费看老司机| 国产91精品一区二区麻豆亚洲 | a级精品九九九大片免费看| 亚洲一区二区三区乱码A| 免费一级全黄少妇性色生活片 | 亚洲精品成a人在线观看| 国产福利免费视频 | 亚洲熟妇无码AV不卡在线播放| 成人免费无码大片A毛片抽搐| 亚洲欧美日韩一区二区三区在线| 国产成人免费永久播放视频平台| 成年大片免费视频播放一级| 久久夜色精品国产亚洲| 国产精品色拉拉免费看| 亚洲欧洲专线一区| 国产精品亚洲视频| 久久国产乱子免费精品| 亚洲最新中文字幕| 女人18毛片水真多免费看| 日韩久久无码免费毛片软件| 国产AV无码专区亚洲AVJULIA | 免费H网站在线观看的| 国产AV无码专区亚洲AV琪琪 | 亚洲国产最大av| 亚洲国产主播精品极品网红 | 嫩草影院在线播放www免费观看| 亚洲伊人久久大香线蕉啊| 亚洲av午夜精品一区二区三区| 最近免费中文字幕MV在线视频3| 亚洲人妖女同在线播放|