pythonatbash密码在python中实现。(代码片段)

author author     2022-12-26     502

关键词:

import argparse

ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'


def encrypt(message):
    message = message.replace(':', '')
    message = message.replace(';', '')
    message = message.replace(',', '')
    message = message.replace('.', '')
    message = message.replace('?', '')
    message = message.replace('!', '')

    message = message.upper()

    encrypted_message = ''

    for c in message:
        if c not in ALPHABET:
            encrypted_message += c
            continue

        index_in_alphabet = ALPHABET.find(c)
        shifted_index = len(ALPHABET) - 1 - index_in_alphabet
        encrypted_message += ALPHABET[shifted_index]

    return encrypted_message


def decrypt(message):
    message = message.replace(':', '')
    message = message.replace(';', '')
    message = message.replace(',', '')
    message = message.replace('.', '')
    message = message.replace('?', '')
    message = message.replace('!', '')

    message = message.upper()

    decrypted_message = ''

    for c in message:
        if c not in ALPHABET:
            decrypted_message += c
            continue

        index_in_alphabet = ALPHABET.find(c)
        shifted_index = len(ALPHABET) - 1 - index_in_alphabet
        decrypted_message += ALPHABET[shifted_index]

    return decrypted_message


def main():
    usage = "python atbash_cipher.py -e -m \"secret\"\nor\n \ " \
            "python atbash_cipher.py -d -m \"HVXIVG\""
    description = "Command line program for demonstrating the Atbash cipher."
    parser = argparse.ArgumentParser(usage=usage, description=description)

    parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0')

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("-e", "--encrypt", action="store_true", dest="encrypt", help="Encrypts the plain text message.")
    group.add_argument("-d", "--decrypt", action="store_true", dest="decrypt", help="Decrypts the encrypted message.")

    parser.add_argument("-m", "--message", action="store", required=True,
                        dest="message", help="You need to specify the message. Like this: -m \"secret\"")

    options = parser.parse_args()

    if options.encrypt:
        print("The encrypted message is: " + encrypt(options.message))
    elif options.decrypt:
        print("The decrypted message is: " + decrypt(options.message))


if __name__ == '__main__':
    main()

如何在 Spring mvc 中实现忘记密码

】如何在Springmvc中实现忘记密码【英文标题】:HowtoimpelementForgotPasswordinSpringmvc【发布时间】:2018-07-0719:37:33【问题描述】:我有一个项目,我需要在登录时实现忘记密码。所以,我想知道春天是否在这件事上提供了任何帮助。... 查看详情

关于在 asp.net mvc 中实现忘记密码功能的一些问题

】关于在asp.netmvc中实现忘记密码功能的一些问题【英文标题】:Somequestionsregardingimplementingforgotpasswordfunctionalityinasp.netmvc【发布时间】:2011-07-2819:26:38【问题描述】:我想在asp.netmvc中实现一个忘记密码功能,允许用户重置密码,... 查看详情

如何在 TextInputLayout Android 中实现这样的密码错误?

】如何在TextInputLayoutAndroid中实现这样的密码错误?【英文标题】:HowtoachievepassworderrorlikethisinTextInputLayoutAndroid?【发布时间】:2021-12-1408:31:32【问题描述】:这就是我想要实现的。请帮助我处理第三个错误的正则表达式。【问题... 查看详情

如何在 Lumen 6x 中实现默认 Laravel 重置密码

】如何在Lumen6x中实现默认Laravel重置密码【英文标题】:HowtoImplementDefaultLaravelResetPasswordinLumen6x【发布时间】:2020-03-1101:50:02【问题描述】:我是Laravel/Lumen框架的新手,我正在尝试将Laravelhttps://laravel.com/docs/5.7/passwords的默认重置... 查看详情

如何使用 jwt 在 typescript 中实现更改密码 API?

】如何使用jwt在typescript中实现更改密码API?【英文标题】:HowtoimplementthechangepasswordAPIintypescriptwithjwt?【发布时间】:2021-09-0202:19:20【问题描述】:我创建了登录api并在其中实现了jwt。现在我正在尝试使用带有cookie或本地存储的jw... 查看详情

在哪里可以找到在 ASP .NET MVC2 中实现密码恢复的 C# 示例代码

】在哪里可以找到在ASP.NETMVC2中实现密码恢复的C#示例代码【英文标题】:WheretofindC#samplecodetoimplementpasswordrecoveryinASP.NETMVC2【发布时间】:2011-12-0905:40:59【问题描述】:如何在MVC2应用中实现密码重置?使用ASP.NET成员资格提供程序... 查看详情

您将如何在 Tomcat 5.5 中实现加盐密码

】您将如何在Tomcat5.5中实现加盐密码【英文标题】:HowwouldyouimplementsaltedpasswordsinTomcat5.5【发布时间】:2010-09-1708:04:48【问题描述】:我的Web应用程序依赖于容器管理的安全性,我想知道是否可以使用加盐密码。据我所知,只需... 查看详情

在 Python 中实现装饰器模式

】在Python中实现装饰器模式【英文标题】:ImplementingthedecoratorpatterninPython【发布时间】:2011-03-0807:55:46【问题描述】:我想在Python中实现decoratorpattern,我想知道是否有一种方法可以编写一个只实现它想要修改的函数的装饰器,... 查看详情

python在python中实现图形边缘/(代码片段)

查看详情

在 Python 中实现 Typescript 接口

】在Python中实现Typescript接口【英文标题】:ImplementingTypescriptinterfacesinPython【发布时间】:2020-08-3009:08:36【问题描述】:我正在寻找一些关于在Python中实现一组仅数据值“接口”的最佳方法的建议,这些接口相当于它们的打字稿... 查看详情

我可以在没有 POST 的情况下在 python 中实现 Web 用户身份验证系统吗?

...这很疯狂),我希望能够拥有一个用户可以拥有用户名和密码并安全登录的系统。这甚至可能吗?如果不是,您将如何使用POST进行处 查看详情

如何在 Python 中实现向量自回归?

】如何在Python中实现向量自回归?【英文标题】:HowtoimplementVectorAuto-RegressioninPython?【发布时间】:2013-08-2307:28:00【问题描述】:我想在python中实现向量自回归。我的数据保存为3个列表的列表。我找到了这个-http://statsmodels.sourcef... 查看详情

在python中实现类接口的正确方法是啥

】在python中实现类接口的正确方法是啥【英文标题】:Whatistherightwaytoimplementaninterfacelikeclassinpython在python中实现类接口的正确方法是什么【发布时间】:2022-01-1712:16:01【问题描述】:什么是让继承自超类的每个类在python中具有相... 查看详情

在 Python 中实现 XOR

】在Python中实现XOR【英文标题】:ImplementingXORinPython【发布时间】:2016-01-0100:12:43【问题描述】:所以我正在尝试在Python中实现逻辑运算符XOR。我首先询问用户他们想要测试多少个输入(4-TT、TF、FT、FF)。我知道XOR计算T&T->... 查看详情

在 Python 中实现类似列表的索引访问

】在Python中实现类似列表的索引访问【英文标题】:Implementlist-likeindexaccessinPython【发布时间】:2011-09-2302:29:42【问题描述】:我希望能够使用类似数组的语法访问python对象的一些值,即:obj=MyClass()zeroth=obj[0]first=obj[1]这可能吗?... 查看详情

如何在 Python 中实现机会/概率? [复制]

】如何在Python中实现机会/概率?[复制]【英文标题】:HowcanIimplementchance/probabilityintoPython?[duplicate]【发布时间】:2021-04-0722:09:36【问题描述】:我想让Python在70%的情况下打印“是”,在30%的情况下打印“否”。我该怎么做呢?【... 查看详情

python在python中实现倒数第一个堆栈(代码片段)

查看详情

str() 如何在 python 中实现?

】str()如何在python中实现?【英文标题】:howstr()implementinpython?【发布时间】:2019-07-1100:48:30【问题描述】:节省和结果的定义savings=100result=100*1.10**7修复打印输出print("Istartedwith$"+savings+"andnowhave$"+result+"Awesome!")pi_string的定义pi_stri... 查看详情