Python Forum
Decipher a plain text ciphered by the CIPHER program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decipher a plain text ciphered by the CIPHER program
#1
The DECIPHER program allows us to decipher a plain text ciphered by the CIPHER program. For it, we need to insert the ciphered binary string “cbd” of length “m”, generated with the CIPHER program, and introduce an initial condition “Xo”, it is important that the initial condition coincides with the initial condition used to generate “cbd”. With "Xo" we generate the binary string “a” using m iterations of the logistic map “4x(1-x)” (We will assign “1” if iteration is greater or equal than 0.5 or “0” in another case). Finally, we will add the binary strings “cbd” and “a” to generate the deciphered binary string “bi”, which will be converted to the plain text “message” through ISO norm 8859-1.

In this program, we require: a ciphered binary string and the initial condition used for cipher this string. As a result, we will have the original plain text.

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 deciphers a binary string in a plain text.')
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 deciphering:\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 deciphering, 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 deciphering:\n\n"))

    # Option 1.   
    else:
        # "x" will be the initial condition.
        x = y
        cbd = input("Insert the binary string to decipher: \n\n")
        m=len(cbd)

        # We generate a binary string (a) using the logistic map "4x(1-x)".
        strs=''
        for i in range(m):
            x=4*x*(1-x)
            if x >= 0.5:
                b=1
                strs= strs[:] + "1"
            else:
                b=0
                strs= strs[:] + "0"
        a = strs

        # We generate the deciphered binary string (bi).
        bi=''
        for i in range(m):
            r=int(a[i])
            s=int(cbd[i])
            c=r^s
            d=str(c)
            bi=bi+d
 
        # We traduce the deciphered binary string to plain text (message).
        str1 = bi
        message = ""
        while str1 != "":
            i = chr(int(str1[:8], 2))
            message = message + i
            str1 = str1[8:]
        print('\n____________________________________________')  
        print("Deciphered binary string:")
        print('____________________________________________ \n')
        print(message)
        print('\n____________________________________________ \n')
        print(f"Initial condition: {y}")
HERE, you will find the CIPHER program which allows you to cipher a plain text by using the logistic map and the initial condition “Xo”.

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
  Automatic decipher a binary string ciphered by the CIPHER program DavidHG 0 1,968 Apr-27-2019, 10:40 PM
Last Post: DavidHG
  Cipher a plain text by using the logistic map DavidHG 0 1,748 Apr-27-2019, 10:09 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