Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with slicing a list
#1
Hi, I have this program that ciphers text. The output for "This is a test!" would be:

Output:
2925596241966444785172913025754527297312947115361659656775S59817385191117554527297312947115361659656 775598173851911175H3479611511221598173851911175122738400274141N3062332593012311536165965677512273840 0274141E402651955633231FIFTFOGNT
To decipher the code the program first converts those letters (which in a longer text would be mixed with the numbers, but if the ciphered text is short they just stay in the back) to numbers. This numbers make the base_number which is needed to give a character (from a list of cipherable characters) a maximum value it could have. This is because a character can have a value between the maximum value the character could have + 1. The base_number in this case is 639744482 so the first letter in the cipherable characters list is "a" so it would have a value between 1 and the base_number in the case of "b" it would have a value between base_number + 1 and base_number * 2 .

Once the base_number is removed from the output so it's easier to decipher the output would be (you can't see this, this is a process made by the program):

Output:
2925596241966444785172913025754527297312947115361659656775S59817385191117554527297312947115361659656 77559817385191117534796115112215981738519111751227384002741413062332593012311536165965677512273840 0274141402651955633231O
So there is my problem. I can't find a solution on how to get each number so I can decipher it. What i mean is that i need to get a number, for example 2323232 (which is be between 1 and 639744482) so it's an "a". But I don't know how to slice the outpu so that I get each value for a character correctly.

As English is not my first language I don't think I'm being clear enough so here is an example:

With the output showed above, I want to make this:

Output:
ciphered_nums_list = [[29255962], [19664447851729], [130257545], [272973129471153616], [59656775S598173851911175] [5452729731294711536165965677], [5598173851911175347961151122], [159817385191117512273], [840027414130623325930], [12311536165965677512273840], [0274141402651955633231O], ]
So once from there I could get each number from the list and compare it to see if it is between one number and another number, and if it is, return that character.

The problem is the program doesn't tell me when one number ends, so i have to divide them in the program which is difficult because each number can have between 1 and 15 figures.


So, How would you do this?

I have tried to solve it but failed many times. I thinking in maybe changing the way the cipher works so that it is easier to decipher but I don't like that idea.

My two solutions are to add a special character at the end of each value to show that that is the end of the number. Or to make the ciphering program so that the value for a character is an only value instead of a value between two numbers.

Thanks for reading!

P.S: I have posted this on r/learnpython but haven't been able to solve the problem.
Reply
#2
Ever watch Mark Roper? He did a video about decoding baseball signals. The trick was that most of it was gibberish, then a marker that immediately preceded the actual signal. Something like a code at the beginning that told your program what the marker is (eg. a certain number of digits that make a total, or a certain total is hit and that marks where your letter code is hidden).
Gibberish        Marker  Letter   Gibberish.... etc 
|---------------|-------|--------|--------------
95729584759454y5 4143214 34156765 42365426534566
If you have a good code for the marker, python will know what it is looking for and can replace the marker and gibberish with a comma which will leave you with a list of letters.... I think.

It would be fun to code that the gibberish hid messages too so that a code breaker would spend their time decoding irrelevant msgs. lol
Reply
#3
Thats a great idea!

Now I was doing my program so that text like "Hello!" would be ciphered to
Output:
144042209809346⟚20030551517791⟚49461787026128⟚49461787026128⟚63810974923268⟚268587913534804⟚FHHTZZZFHHIGG
If the text was longer the letters (which is then transformed into the "seed" of the cipher) would be in between the numbers.

I'm using that special character, that I don't think anyone uses, as a marker for where each number starts and ends. This makes it easier to split the string each time there is a ⟚ and add it to a list of numbers that then decipher each number in a character.

What do you think about this approach?

If I use the method you said the marker would have to always be the same number for the program to recognize it or a number that has always the same number of figures. For example the marker would have to be a number of max 6 figures so it would be between 100000 and 999999. And I would still need to use a seed so that the value for each character always changes, even when you cipher the same text.
But it would be more safe than the method I'm using now so it's a good idea. I will see how I end up doing it. Thanks for your help.
Reply
#4
I wouldn't use any identifiable markers. I was thinking using a "code word" or "key phrase". So you sent your program and ciphered message to a person, and give them the "code word" by a totally separate means. Think sending the message by carrier pigeon, and the code word by radio. You need both to code or decode.

key_phrase = "The chickens will fry at midnight"

code_key = Convert_string_to_number(key_phrase) ##<---  however you like

marker_list = ()

Generate_key_list():

    for marker in range(100)  ##  <-- number of individual markers generated
        marker =  (code_key + (math and return the first or last 4 characters as marker)
        marker_list.append(marker) ## or str(marker) depending what you want.
        code_key += 1
    return marker_list
To encode have your program write the message as:
Final_message = (random_gibberish)+(marker1)+(number1)+(random_gibberish)+(marker2)+(number2)...
The person who receives the message will enter the key_phrase and generate the same marker_list on the other end. Then the program can find the first marker in the list and return the string of 14 numbers that follow(according to your example). Then the second, then third, etc.

Hope that expresses what I'm thinking.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  slicing and indexing a list example leodavinci1990 4 2,338 Oct-12-2020, 06:39 AM
Last Post: bowlofred
  List slicing issue Irhcsa 3 2,972 Apr-26-2019, 09:16 PM
Last Post: nilamo
  Slicing Python list of strings into individual characters Drone4four 5 3,494 Apr-17-2019, 07:22 AM
Last Post: perfringo
  String Slicing in List Comphrensions Patroclus72790 1 2,258 Mar-21-2019, 09:33 PM
Last Post: nilamo
  Slicing a complex dictionary and list Drone4four 2 6,760 Aug-16-2018, 02:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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