def decrypt(self,ciphertext): newciphertext = '' plaintext = [0 for c in ciphertext] bitstring = '' for m in ciphertext.upper(): if m in self.letters: newciphertext = newciphertext + m scrambled = self.scrambleKey(newciphertext) nchars = len(newciphertext) nchunks = int(math.ceil(nchars/20.0)) for ichunk in range(nchunks): istart = ichunk*20 chunk = newciphertext[istart:istart+20] for i in range(0,len(chunk)): if len(chunk) < len(self.key): kidx = i else: kidx = self.key[i] ch = chunk[i] numch = self.fdict[ch] pstart = ichunk*20 + kidx*5 pend = pstart + 5 piblock = scrambled[pstart:pend] pibits = cryptutils.list2bin(piblock) pinum = cryptutils.bin2dec(pibits) bitstring = bitstring + self.rdict[pinum] numct = numch ^ pinum plaintext[istart+kidx] = self.rdict[numct] plaintext = ''.join(plaintext) return (plaintext,bitstring)
def decrypt(self, ciphertext): newciphertext = '' plaintext = [0 for c in ciphertext] bitstring = '' for m in ciphertext.upper(): if m in self.letters: newciphertext = newciphertext + m scrambled = self.scrambleKey(newciphertext) nchars = len(newciphertext) nchunks = int(math.ceil(nchars / 20.0)) for ichunk in range(nchunks): istart = ichunk * 20 chunk = newciphertext[istart:istart + 20] for i in range(0, len(chunk)): if len(chunk) < len(self.key): kidx = i else: kidx = self.key[i] ch = chunk[i] numch = self.fdict[ch] pstart = ichunk * 20 + kidx * 5 pend = pstart + 5 piblock = scrambled[pstart:pend] pibits = cryptutils.list2bin(piblock) pinum = cryptutils.bin2dec(pibits) bitstring = bitstring + self.rdict[pinum] numct = numch ^ pinum plaintext[istart + kidx] = self.rdict[numct] plaintext = ''.join(plaintext) return (plaintext, bitstring)
def encrypt(self,message): newmessage = '' ciphertext = '' bitstring = '' for m in message.upper(): if m in self.letters: newmessage = newmessage + m scrambled = self.scrambleKey(newmessage) nchars = len(newmessage) nchunks = int(math.ceil(nchars/20.0)) for ichunk in range(nchunks): #print 'Chunk %i' % ichunk istart = ichunk*20 iend = istart + 20 if iend > len(newmessage)-1: chunk = newmessage[istart:] else: chunk = newmessage[istart:istart+20] for i in range(0,len(chunk)): if len(chunk) < len(self.key): kidx = i else: kidx = self.key[i] ch = chunk[kidx] numch = self.fdict[ch] pstart = ichunk*20 + kidx*5 pend = pstart + 5 piblock = scrambled[pstart:pend] pibits = cryptutils.list2bin(piblock) pinum = cryptutils.bin2dec(pibits) bitstring = bitstring + self.rdict[pinum] numct = numch ^ pinum ciphertext = ciphertext + self.rdict[numct] #print '%2i %2i %2s %2i %4i %4i %-20s %2i %2i %s' % (i,kidx,ch,numch,pstart,pend,str(piblock),pinum,numct,ciphertext[-1]) return (ciphertext,bitstring)
def encrypt(self, message): newmessage = '' ciphertext = '' bitstring = '' for m in message.upper(): if m in self.letters: newmessage = newmessage + m scrambled = self.scrambleKey(newmessage) nchars = len(newmessage) nchunks = int(math.ceil(nchars / 20.0)) for ichunk in range(nchunks): #print 'Chunk %i' % ichunk istart = ichunk * 20 iend = istart + 20 if iend > len(newmessage) - 1: chunk = newmessage[istart:] else: chunk = newmessage[istart:istart + 20] for i in range(0, len(chunk)): if len(chunk) < len(self.key): kidx = i else: kidx = self.key[i] ch = chunk[kidx] numch = self.fdict[ch] pstart = ichunk * 20 + kidx * 5 pend = pstart + 5 piblock = scrambled[pstart:pend] pibits = cryptutils.list2bin(piblock) pinum = cryptutils.bin2dec(pibits) bitstring = bitstring + self.rdict[pinum] numct = numch ^ pinum ciphertext = ciphertext + self.rdict[numct] #print '%2i %2i %2s %2i %4i %4i %-20s %2i %2i %s' % (i,kidx,ch,numch,pstart,pend,str(piblock),pinum,numct,ciphertext[-1]) return (ciphertext, bitstring)