def freA(s, small): count = Counter(s) #would make a dictioary ac = sum(count[l] for l in string.ascii_letters + ' ') if ((ac * 100 / small) >= 80): pc = sum(count[l] for l in string.punctuation) if ((pc * 100 / small) <= 10): freq = { 'e': 12.49, 't': 9.28, 'a': 8.04, 'o': 7.64, 'i': 7.57, 'n': 7.23, 's': 6.51, 'r': 6.28, 'h': 5.05, 'l': 4.07, 'd': 3.28, 'c': 3.34, 'u': 2.73, 'm': 2.51, 'f': 2.40, 'p': 2.14, 'g': 1.87, 'w': 1.68, 'y': 1.66, 'b': 1.48, 'v': 1.05, 'k': 0.54, 'x': 0.23, 'j': 0.16, 'q': 0.12, 'z': 0.09 } fc = sum(count[l] for l in freq) return fc else: return 1
def encrypt(plaintext, key, mode, iv): if mode == AES.MODE_CBC: assert iv != None block = list(ord(b) for b in iv) cipher = AES.new(key, AES.MODE_ECB) plaintext = bytearray(plaintext) plaintext = [ plaintext[i:i + AES.block_size] for i in range(0, len(plaintext), AES.block_size) ] ciphertext = [iv] for i in range(len(plaintext)): block = [(x ^ y) for (x, y) in zip(plaintext[i], block)] block = "".join(chr(b) for b in block) block = cipher.encrypt(block) ciphertext.append(block) return ciphertext elif mode == AES.MODE_CTR: cipher = AES.new(key, AES.MODE_ECB) counter = Counter(iv) plaintext = bytearray(plaintext) plaintext = [ plaintext[i:i + AES.block_size] for i in range(0, len(plaintext), AES.block_size) ] ciphertext = [iv] for i in range(len(plaintext)): block = cipher.encrypt(str(counter)) counter.increment() block = list(ord(b) for b in block) block = [(x ^ y) for (x, y) in zip(plaintext[i], block)] ciphertext.append(block) return ciphertext
def convert_to_dict_representation(reviews): all_reviews = [] for review in reviews: all_reviews.append(Counter(review)) return all_reviews
def decrypt(self, enc): cipher_ctr = AES.new(self.skey, mode=AES.MODE_CTR, counter=Counter(nonce)) return cipher_ctr.decrypt(enc)
def generate(self): cipher_ctr = AES.new(self.skey, mode=AES.MODE_CTR, counter=Counter(nonce)) return cipher_ctr.encrypt(plaintext)