Python Forum
Cipher a plain text by using the logistic map
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cipher a plain text by using the logistic map
#1
The CIPHER program allows us to cipher a plain text by using the logistic map. For this, we need to insert the initial condition “Xo” (It should have at least 15 digits, e. g., Xo=0.123456789111213) and a plain text of length “m” which will be converted to the binary string “tp”, through the ISO norm 8859-1, the length of string “tp” will be 8m. With this information, we will generate the binary string “a” using 8m iterations of the logistic map “4x(1-x)” in “Xo” (We will assign “1” if the iteration is greater or equal than 0.5 or “0” in another case). Finally, we will add the binary strings “tp” and “a” to generate the ciphered binary string “bi”.

In this program, we require: select an initial condition and have a plain text. As a result, we will have a ciphered binary string.

NOTE: We use the ISO norm 8859-1 because It extends the ASCII code with characters used in the Spanish language, e.g., á, Á, ó, Ó, ñ, Ñ.

# Authors:
print('\nDavid H.G. y Hugo C.I.')
print('IPICYT')
# Date:
print('March 2019')
print('Python 3.6\n')

print('=================================================================')
print('This application cipher a plain text in a binary string.')
print('=================================================================')

#NOTE: We use the ISO norm 8859-1 (latin1) because this program was implemented for the Spanish language.
micodigo='latin1'

y = float(input("Insert the initial condition for ciphering:\n\n"))

## The initial condition should have at least 15 digits and be a decimal number. For example: 0.123456789101112
while True:
    continuar = int(input("Type 1 for ciphering, type 2 for change the initial condition or type 3 for quit:  "))
   
    # Option 3.
    if continuar == 3:
        break
    
    # Option 2.
    elif continuar == 2:
        y = float(input("Insert the new initial condition for ciphering:\n\n"))

    # Option 1.                   
    else:
        # "x" will be the initial condition.
        x = y
        
        # "tp" will be the plain text to cipher.
        tp = input("Insert the plain text to cipher:\n\n")   
        
        # "m" will be the length the plain text.
        m=len(tp)
        
        # We generate a binary string (a) using the logistic map "4x(1-x)".
        strs=''
        for i in range(m*8):
            x=4*x*(1-x)
            if x >= 0.5:
                b=1
                strs= strs[:] + "1"
            else:
                b=0
                strs= strs[:] + "0"
        a = strs
        n=len(a)
        
        # We generate a binary string (cb) using "tp".
        octetos = bytearray(tp, micodigo)
        binario= ''.join(f'{x:b}'.rjust(8, '0') for x in octetos)
        cb = binario
        
        # We generate the ciphered binary string (bi).
        bi=''
        for i in range(n):
            x=int(a[i])
            Y=int(cb[i])
            c=x^Y
            d=str(c)
            bi=bi+d
        print('\n____________________________________________')    
        print("Ciphered binary string:")
        print('____________________________________________ \n')
        print(bi)
        print('\n____________________________________________ \n')
        print(f"Initial condition: {y}")

Here,you will find the DECIPHER program which allows you to decipher a plain text ciphered with the CIPHER program, knowing the initial condition “Xo” used.

Here, you will find the DECIPHERER program which allows you, in some cases, decipher a plain text ciphered with the CIPHER program, but, without knowing the initial condition “Xo” used.

Aquí, encontrarás los programas antes mencionados, pero, en su versión en Español.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decipher a plain text ciphered by the CIPHER program DavidHG 0 1,453 Apr-27-2019, 10:29 PM
Last Post: DavidHG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020