79315616

Date: 2024-12-29 12:56:23
Score: 0.5
Natty:
Report link

You must have come to a solution to this by now. Here is how I performed the permutation for the Present Cipher.

The permutation is stored as a list, where each input bit is mapped to the output bits.

permutation = [0,16,32,48,1,17,33,49,2,18,34,50,3,19,35,51,4,
           20,36,52,5,21,37,53,6,22,38,54,7,23,39,55,8,24,
           40,56,9,25,41,57,10,26,42,58,11,27,43,59,12,28,
           44,60,13,29,45,61,14,30,46,62,15,31,47,63]

def pLayer(data):
    """
    data is 64-bit hex
    """
    original_data = list(format(data, '#066b')[2:])
    permuted_data = list(format(data, '#066b')[2:])
    for i, j in enumerate(permutation):
        permuted_data[j] = original_data[I]
    return int("0b" + "".join(permuted_data), 2)

The code list(format(data, '#066b')[2:]) converts the hexadecimal number to a Python list of ones and zeros in string, making it easier for substitution and permutation.

Usage:

>>> a = 0xcccccccccccccccc
>>> permuted_a = pLayer(a)
>>> hex(permuted_a)
'0xffffffff00000000'

You can view my full implementation here.

I have also discussed the details of the Present cipher in my blog.

Hoping this helps :).

Reasons:
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Biplab