Zoom Icon

Sandbox

From UIC Archive

Feistel Networks

Contents


Sandbox
Author: Pn
Email: Pnmail.png
Website: @PnUic
Date: 02/09/2012 (dd/mm/yyyy)
Level: Working brain required
Language: English Flag English.gif
Comments:



Introduction

Scrivi quello che vuoi per introdurre l'argomento



Essay

import random

class Feistel: def __init__(self): self.shK = [] self.invShK = []

def keyScheduler(self,key): random.seed(key) for i in xrange(4): self.shK.append(random.randint(1, 9999))

self.invShK = list(self.shK) self.invShK.reverse() return

def cipher(self, block, shK): block = self.round(block[0], block[1], shK[0]) block = self.round(block[0], block[1], shK[1]) block = self.round(block[0], block[1], shK[2]) block = self.round(block[0], block[1], shK[3]) return block

def crypt(self, block): return self.cipher(block, self.shK)

def decrypt(self, block): block.reverse() block = self.cipher(block, self.invShK) block.reverse() return block

def round(self, lx, rx, key): lx2 = rx rx2 = lx ^ self.f(rx, key) return [lx2, rx2]

def f(self, rx, k): return ~((rx^k)&rx)

  1. Main

if __name__ == "__main__": block = [1234,5678]; key = 1234;

feistel = Feistel() feistel.keyScheduler(key)

block = feistel.crypt(block) print block

block = feistel.decrypt(block) print block



Final Notes

Final Notes