Уведомления

Группа в Telegram: @pythonsu

#1 Май 11, 2014 09:52:52

vankai14
Зарегистрирован: 2014-05-11
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

Перевод из Python

Здравствуйте. помогите очень срочно!!! с питоном не работал, но очень надо подробно понять что делает предложенный ниже фрагмент алгоритма. если можно с подробным описанием 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

Офлайн

#2 Май 11, 2014 10:23:15

Shaman
Зарегистрирован: 2013-03-15
Сообщения: 1369
Репутация: +  88  -
Профиль   Отправить e-mail  

Перевод из Python

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

Офлайн

#3 Май 11, 2014 10:27:10

Shaman
Зарегистрирован: 2013-03-15
Сообщения: 1369
Репутация: +  88  -
Профиль   Отправить e-mail  

Офлайн

#4 Май 11, 2014 10:53:33

vankai14
Зарегистрирован: 2014-05-11
Сообщения: 2
Репутация: +  0  -
Профиль   Отправить e-mail  

Перевод из Python

Shaman
Цитировать

Я в этом описании не могу понять 2 и 3 пункты. 2ой это что? 4 бита возвращаются обратно после перестановки или как?

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version