onepad cipher Algorithm

The OnePad cipher algorithm, also known as the One-Time Pad (OTP) cipher, is a type of symmetric key encryption technique that provides theoretically unbreakable security, given that certain conditions are met. It was invented by Gilbert Vernam and Joseph Mauborgne in the 1910s and has been used in various high-security communication systems, most notably during World War II. The algorithm works by combining a plaintext message with a random secret key (also known as a pad) of the same length, using the XOR (exclusive-or) operation. The result is a ciphertext that can only be decrypted by someone who possesses the same secret key. The security of the OnePad cipher relies on a few critical principles: the key must be truly random, as long as the plaintext message, used only once, and kept secret between the sender and recipient. If these conditions are met, the OnePad cipher is considered to have perfect secrecy, as there is no way for an attacker to gain any information about the plaintext message without knowing the secret key. However, practical implementation challenges, such as generating truly random keys and securely distributing them, have limited the widespread use of OnePad ciphers in modern cryptography. Nonetheless, the concept of the One-Time Pad continues to be a subject of interest and serves as a theoretical foundation for understanding the limits of secure communication.
import random


class Onepad:
    def encrypt(self, text):
        """Function to encrypt text using pseudo-random numbers"""
        plain = [ord(i) for i in text]
        key = []
        cipher = []
        for i in plain:
            k = random.randint(1, 300)
            c = (i + k) * k
            cipher.append(c)
            key.append(k)
        return cipher, key

    def decrypt(self, cipher, key):
        """Function to decrypt text using pseudo-random numbers."""
        plain = []
        for i in range(len(key)):
            p = int((cipher[i] - (key[i]) ** 2) / key[i])
            plain.append(chr(p))
        plain = "".join([i for i in plain])
        return plain


if __name__ == "__main__":
    c, k = Onepad().encrypt("Hello")
    print(c, k)
    print(Onepad().decrypt(c, k))

LANGUAGE:

DARK MODE: