Facebook
From Arash, 2 Years ago, written in Python.
This paste is a reply to modules from Arash - go back
Embed
Viewing differences between modules and Re: modules
import random
import math as floor


def genKys(length, choice):
genKys(length):
    key = [0] * length
    choice = floor.floor(random.random() * length * 8)
    for i in range(choice):
        key[floor.floor(random.random() * (length - 1))] = 1
    return key

def enc(plain, key):
    length = len(key)
    cipher = [None] * length
    for i in range(length):
        cipher[i] = 1 if key[i] == plain[i] else 0
    return cipher

def getBts(plain):
    length = len(plain)
    bits = [None] * length * 8
    for i in range(length):
        for j in range(8):
            bits[8 * i + 7 - j] = (int)(ord(plain[i]) / pow(2, j)) % 2
    return bits

def main():
    txt = input("Enter cipher text : ")
    length = len(txt)
    key = genKys(length * 8, floor.floor(random.random() * length * 8))
    plain = getBts(txt)
    print("plaintext : ")
    print(plain)
    cipher = enc(plain, key)
    print("ciphertext : ")
    print(cipher)
    deciphered = enc(cipher, key)
    print("deciphered : ")
    print(deciphered)

if __name__ == "__main__":
    main()
bits

Replies to Re: modules rss

Title Name Language When
Re: Re: modules Arash python 2 Years ago.