Facebook
From Arash, 2 Years ago, written in Python.
This paste is a reply to modules from Arash - view diff
Embed
Download Paste or View Raw
Hits: 168
  1. import random
  2. import math as floor
  3.  
  4.  
  5. def genKys(length):
  6.     key = [0] * length
  7.     choice = floor.floor(random.random() * length * 8)
  8.     for i in range(choice):
  9.         key[floor.floor(random.random() * (length - 1))] = 1
  10.     return key
  11.  
  12. def enc(plain, key):
  13.     length = len(key)
  14.     cipher = [None] * length
  15.     for i in range(length):
  16.         cipher[i] = 1 if key[i] == plain[i] else 0
  17.     return cipher
  18.  
  19. def getBts(plain):
  20.     length = len(plain)
  21.     bits = [None] * length * 8
  22.     for i in range(length):
  23.         for j in range(8):
  24.             bits[8 * i + 7 - j] = (int)(ord(plain[i]) / pow(2, j)) % 2
  25.     return bits

Replies to Re: modules rss

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