Generated OTP using python3
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:
The above is the detailed content of Generated OTP using python3. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
