Since we were not allowed to have MFA together with the same application we are using, I got an idea from my leader to just have a generated OTPs.
import time import hmac import base64 import struct import hashlib def generate_otp(secret, interval=30, digits=6): # Decode the base32 encoded secret key = base64.b32decode(secret) # Calculate the number of time intervals since the Unix epoch counter = int(time.time()) // interval # Convert the counter to bytes msg= struct.pack(">Q", counter) # Create the HMAC hash using SHA-1 hmac_hash = hmac.new(key, msg, hashlib.sha1).digest() # Get the dynamic offset from the last nibble of the hash offset = hmac_hash[-1] & 0x0F # Extract a 4-byte dynamic binary code form the hash using the offset code = struct.unpack(">I", hmac_hash[offset:offset + 4]) [0] & 0x7FFFFFFF # Modulus operation to get the final OTP otp = code % (10 ** digits) return str(otp).zfill(digits) # Lists for secret keys and remarks secret_keys_with_titles = { "[name]": "[secret_key]", "VAR": "ABDCDEFGHIJKLMNO", "VER": "PQRSTUVWXYZ12345", "VIR": "6789101112131415" } # ANSI escape codes for different color colors = [ "\033[91m", # Red "\033[92m", # Green "\033[94m", # Blue "\033[93m", # Yellow "\033[96m", # Cyan ] print() # Generate the OTPs for all secret keys otps = {title: generate_otp(secret) for title, secret in secret_keys_with_titles.items()} # Output the OTPs in horizontal way output = [] for i, (title, otp) in enumerate(otps.items()): color = colors[i % len(colors)] # Rotate through colors output.append(f"{color}{title}: {otp}\033[0m") #\033[0m resets the color print(" | ".join(output)) print()
So, this is how it look on your terminal:
以上是使用 python3 生成 OTP的详细内容。更多信息请关注PHP中文网其他相关文章!

ArraySareBetterForlement-WiseOperationsDuetofasterAccessCessCessCessCessCessAndOptimizedImplementations.1)ArrayshaveContiguucuulmemoryfordirectAccesscess.2)列出sareflexible butslible dueTopotentEnallymideNamicizing.3)forlarargedAtaTasetsetsetsetsetsetsetsetsetsetsetlib

在NumPy中进行整个数组的数学运算可以通过向量化操作高效实现。 1)使用简单运算符如加法(arr 2)可对数组进行运算。 2)NumPy使用C语言底层库,提升了运算速度。 3)可以进行乘法、除法、指数等复杂运算。 4)需注意广播操作,确保数组形状兼容。 5)使用NumPy函数如np.sum()能显着提高性能。

在Python中,向列表插入元素有两种主要方法:1)使用insert(index,value)方法,可以在指定索引处插入元素,但在大列表开头插入效率低;2)使用append(value)方法,在列表末尾添加元素,效率高。对于大列表,建议使用append()或考虑使用deque或NumPy数组来优化性能。

tomakeapythonscriptexecutableonbothunixandwindows:1)Addashebangline(#!/usr/usr/bin/envpython3)Andusechmod Xtomakeitexecutableonix.2)onWindows,确保pytythonisinsinstalledandassociatedwithedandassociatedwith.pyuunwith.pyun.pyfiles,oruseabatchfile(runuseabatchfile(rugitter)。

当遇到“commandnotfound”错误时,应检查以下几点:1.确认脚本存在且路径正确;2.检查文件权限,必要时使用chmod添加执行权限;3.确保脚本解释器已安装并在PATH中;4.验证脚本开头的shebang行是否正确。这样做可以有效解决脚本运行问题,确保编码过程顺利进行。

ArraySareAryallyMoremory-Moremory-forigationDataDatueTotheIrfixed-SizenatureAntatureAntatureAndirectMemoryAccess.1)arraysStorelelementsInAcontiguxufulock,ReducingOveringOverheadHeadefromenterSormetormetAdata.2)列表,通常

ToconvertaPythonlisttoanarray,usethearraymodule:1)Importthearraymodule,2)Createalist,3)Usearray(typecode,list)toconvertit,specifyingthetypecodelike'i'forintegers.Thisconversionoptimizesmemoryusageforhomogeneousdata,enhancingperformanceinnumericalcomp

Python列表可以存储不同类型的数据。示例列表包含整数、字符串、浮点数、布尔值、嵌套列表和字典。列表的灵活性在数据处理和原型设计中很有价值,但需谨慎使用以确保代码的可读性和可维护性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能