Найти - Пользователи
Полная версия: Перевод из Python
Начало » Python для новичков » Перевод из Python
1
vankai14
Здравствуйте. помогите очень срочно!!! с питоном не работал, но очень надо подробно понять что делает предложенный ниже фрагмент алгоритма. если можно с подробным описанием generateRoundkeys80 и generateRoundkeys128. СПАСИБО!

def generateRoundkeys80(key,rounds):
“”“Generate the roundkeys for a 80-bit key

Input:
key: the key as a 80-bit integer
rounds: the number of rounds as an integer
Output: list of 64-bit roundkeys as integers”“”
roundkeys =
for i in xrange(1,rounds+1): # (K1 … K32)
# rawkey: used in comments to show what happens at bitlevel
# rawKey
roundkeys.append(key >>16)
#1. Shift
#rawKey+rawKey
key = ((key & (2**19-1)) << 61) + (key >> 19)
#2. SBox
#rawKey = S(rawKey)
key = (Sbox << 76)+(key & (2**76-1))
#3. Salt
#rawKey ^ i
key ^= i << 15
return roundkeys

def generateRoundkeys128(key,rounds):
“”“Generate the roundkeys for a 128-bit key

Input:
key: the key as a 128-bit integer
rounds: the number of rounds as an integer
Output: list of 64-bit roundkeys as integers”“”
roundkeys =
for i in xrange(1,rounds+1): # (K1 … K32)
# rawkey: used in comments to show what happens at bitlevel
roundkeys.append(key >>64)
#1. Shift
key = ((key & (2**67-1)) << 61) + (key >> 67)
#2. SBox
key = (Sbox << 124)+(Sbox << 120)+(key & (2**120-1))
#3. Salt
#rawKey ^ i
key ^= i << 62
return roundkeys

def addRoundKey(state,roundkey):
return state ^ roundkey
Shaman
def generateRoundkeys80(key,rounds):
        """Generate the roundkeys for a 80-bit key
        Input:
                key:    the key as a 80-bit integer
                rounds: the number of rounds as an integer
        Output: list of 64-bit roundkeys as integers"""
        roundkeys = []
        for i in xrange(1,rounds+1): # (K1 ... K32)
                # rawkey: used in comments to show what happens at bitlevel
                # rawKey[0:64]
                roundkeys.append(key >>16)
                #1. Shift
                #rawKey[19:len(rawKey)]+rawKey[0:19]
                key = ((key & (2**19-1)) << 61) + (key >> 19)
                #2. SBox
                #rawKey[76:80] = S(rawKey[76:80])
                key = (Sbox[key >> 76] << 76)+(key & (2**76-1))
                #3. Salt
                #rawKey[15:20] ^ i
                key ^= i << 15
        return roundkeys
def generateRoundkeys128(key,rounds):
        """Generate the roundkeys for a 128-bit key
        Input:
                key:    the key as a 128-bit integer
                rounds: the number of rounds as an integer
        Output: list of 64-bit roundkeys as integers"""
        roundkeys = []
        for i in xrange(1,rounds+1): # (K1 ... K32)
                # rawkey: used in comments to show what happens at bitlevel
                roundkeys.append(key >>64)
                #1. Shift
                key = ((key & (2**67-1)) << 61) + (key >> 67)
                #2. SBox
                key = (Sbox[key >> 124] << 124)+(Sbox[(key >> 120) & 0xF] << 120)+(key & (2**120-1))
                #3. Salt
                #rawKey[62:67] ^ i
                key ^= i << 62
        return roundkeys
http://www.lightweightcrypto.org/downloads/implementations/pypresent.py
vankai14
Shaman
Цитировать

Я в этом описании не могу понять 2 и 3 пункты. 2ой это что? 4 бита возвращаются обратно после перестановки или как?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB