惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
H
Hacker News: Front Page
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
P
Palo Alto Networks Blog
Webroot Blog
Webroot Blog
Hacker News: Ask HN
Hacker News: Ask HN
IT之家
IT之家
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
P
Privacy & Cybersecurity Law Blog
C
Cisco Blogs
罗磊的独立博客
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Y
Y Combinator Blog
AWS News Blog
AWS News Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
Kaspersky official blog
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
Jina AI
Jina AI
MyScale Blog
MyScale Blog
TaoSecurity Blog
TaoSecurity Blog
大猫的无限游戏
大猫的无限游戏
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
美团技术团队
T
Tor Project blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 【当耐特】
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
I
Intezer
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - Goodspeed

几种常见的函数 遗传算法之背包问题 Transport scheme NOT recognized: [stomp] error running git Canvas 旋转的图片 canvas时钟 火箭起飞 让图标转起来 Tomcat启动脚本 Task中的异常处理 Parallel的陷阱 用Task代替TheadPool 使用ThreadPool代替Thread 正确停止线程 线程同步中使用信号量AutoResetEvent 异步和多线程的区别 C#和.NET Framework的关系 为什么泛型不支持协变性? 可空值类型与值类型这间的转换
Caesar cipher
Goodspeed · 2020-01-07 · via 博客园 - Goodspeed

Description: https://en.wikipedia.org/wiki/Caesar_cipher

#!/usr/bin/python
# -*- coding: UTF-8 -*-

# 恺撒挪移式密码法
## 密码字母移动三位
def caesar_crypt(plain):
    a, z = ord('a'), ord('z')
    cipher = []
    for char in plain:
        c = char
        if c != ' ':
            asc = ord(c) - 3
            if asc < a:
                asc = z - (a - asc) + 1
            c = chr(asc)
        cipher.append(c)
    return "".join(cipher)

def caesar_decrypt(cipher):
    a, z = ord('a'), ord('z')
    plain = []
    for char in cipher:
        c = char
        if c != ' ':
            asc = ord(c) + 3
            if asc > z:
                asc = a + (asc - z) - 1
            c = chr(asc)
        plain.append(c)
    return "".join(plain)


def main():
    plain = "the quick brown fox jumps over the lazy dog"
    print(plain)
    cipher = caesar_crypt(plain)
    print(cipher)
    plain = caesar_decrypt(cipher)
    print(plain)


if __name__ == '__main__':
    main()