def reset(self, num_to_reset, on_index): i = on_index while i >= 0 and num_to_reset > 0: if self.targets[i].normal == True: self.targets[i] = Cipher(randint(1, 7), True, i) else: self.targets[i] = Cipher(randint(1, 7), False, i) i = i - 1 num_to_reset = num_to_reset - 1
def __init__(self, x): #hex limit is how many hex ciphers (non-normal ciphers) are allowed self.hex_limit = int(x * .3333) self.targets = [] self.hex_chance_upper = 5 x_2 = int(x / 5) #The first several will be normal ciphers for i in range(0, int(x_2)): self.targets.append(Cipher(randint(1, 7), True, i)) for i in range(x_2, x): #50% chance to make hex cipher if hex limit is not yet met if self.hex_limit > 0 and randint(0, self.hex_chance_upper) == 0: self.hex_limit -= 1 self.targets.append(Cipher(randint(1, 7), False, i)) else: self.targets.append(Cipher(randint(1, 7), True, i)) self.hex_chance_upper -= 1 if self.hex_chance_upper < 1: self.hex_chance_upper = 1
def __init__(self, file_open='', password=''): super(PyPherDecipher, self).__init__() self.setupUi(self) self.cipher = Cipher.Cipher() self.file = file_open self.passw = password self.go_back.clicked.connect(self.back) self.save.clicked.connect(self.check) self.password.clicked.connect(self.set_new) self.delete_file.clicked.connect(self.delete)
def __init__(self, encoded_str): self.letters = "abcdefghijklmnopqrstuvwxyz " self.c = Cipher(self.letters) self.best = self.c self.s = encoded_str print("About to build trigram map") self.t = TriGram() print("built trigram map") self.prior = 1 self.p = self.get_prob_log(self.c) self.best_p = self.p print("Initial perm prob log is " + str(self.p))
def cipher_data(self): self.cipher = Cipher.Cipher(self.textEdit.toPlainText(), self.passw) ciphered = self.cipher.cipher() if not os.stat(self.file)[0] & stat.S_IWRITE: # File is read-only, so make it writeable os.chmod(self.file, stat.S_IWRITE) f = open(self.file, 'w+') f.writelines('ciphered\n' + ciphered) f.close() else: f = open(self.file, 'w+') f.writelines('ciphered\n' + ciphered) f.close() # File is writeable, so make it read-only os.chmod(self.file, stat.S_IREAD)
def main(): C = cifra.Cipher() A = enemy.Adversary_Det() if (IND_CPA(C, A)): print("Cifra Identidade quebrada! O adversário venceu!")