How do I... Make a code translator?

0 favourites
  • 6 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hello!

    I was going to write a simple little program for me and a friend to make secret coded messages and I have an idea in my head but I'm not sure how to execute it.

    To make it simple I have a number code: 1 0 5 1 9 8 6

    The idea is when you write the code you take the letters and push them forward acording to the numbers and when you reach the end of the number you loop around back to the start same thing with the alphabet if you use a letter to far forward in the alphabet and it goes past Z it should loop back to A, to me this sound like a for loop and an array thing where I make 7 cells in the array one for each number then when I type in a message into the tex box object and press enter I want the letters to be run through the array before finally printed out in the text below but changed.

    Example:

    "Hello" would translate into "Ieqmx"

    My thought process is this and I'm not sure if it's possible or if I'm overcomplicating it.

    While the selection box Normal to Code is sellected when the text box message is typed, you hit enter in this case we say "Hello" again, the text is then boiled down to variables for each letter A being 1, B being 2 etc, turning the word into "8,5,12,12,15" those variables is then put into the array adding the numbers from each cell onto the numbers making it into "9,5,17,13,24" then written out through variable into the text below as "Ieqmx" as those would be the corisponding letters to the variables.

    Then do the whole thing in reverse when I chose the "Code to Normal" option in the slection box where you subtract the number in the cells of the Array.

    Do you guys think it's possible and how should I proceed to make it actually work, it sounds easy in my head (And it probably is and I'm just a dumb xD) but when it comes to executing it I'm not sure.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah, you can use a bubble sort :

    https://en.wikipedia.org/wiki/Bubble_sort

    Sort of complicated. Is this for a commercial game?

    You can use the dictionary object for some more advanced sorts.The array is limited to 1 sort iirc.

  • Phealin

    It's very doable, and a sort isn't needed.

    You can use "repeat" or "for" to loop over the letters.

    Use the len() expression to set the length of the loop, then the mid() expression to get the individual letters.

    Next you need to convert the letters to a number. You could do it the long way by making an event for each, or you could use the find() expression [expained below].

    Wrapping the value around when adding a number can be do by using the % operator.

    Finally converting the number back to a letter can be done with mid() in a similar way to using find().

    As an example the following should encode your text.

    Global text input="hello"

    Global text output=""

    Start of layout

    set array size to (7,1,1)

    set array at 0 to 6

    ...

    set array at 6 to 2

    Global text letter=""

    Global number value=0

    Start of layout

    Repeat len(input) times

    set letter to mid(input, loopindex, 1)

    set value to find("abcdefghijklmnopqrstuvwxyz", letter)

    set value to (value+array.at(loopindex%array.width))%26

    add mid("abcdefghijklmnopqrstuvwxyz", value, 1) to output

    That works any input that consists of only lowercase letters.

  • jojoe Thanks, I will take a look at that and no it's mostly gonna be used by me and two other friends so we can quickly make coded messages for each other rather than have to sit for a few hours to make them coded then another few hours to uncode them but it could be a cool thing to have in a game at some point if I make some sort of spy game or something!

    R0J0hound

    You make it sound so simple... It probably is and I'm just intimidated by the thought of arrays as I've never fully managed to wrap my head around them except for the very basics, I will try this out though thanks

    Also love that picture XD

  • Phealin No problem . R0J0hound brings up a good point about not using a sort to scramble.

    The simple substitution cipher is quite easy to break. Even though the number of keys is around 288.4 (a really big number), there is a lot of redundancy and other statistical properties of English text that make it quite easy to determine a reasonably good key. The first step is to calculate the frequency distribution of the letters in the cipher text. This consists of counting how many times each letter appears. Natural English text has a very distinct distribution that can be used help crack codes.

    This means that the letter 'e' is the most common, and appears almost 13% of the time, whereas 'z' appears far less than 1 percent of time. Application of the simple substitution cipher does not change these letter frequencies, it merely jumbles them up a bit. it is possible to just replace the most common ciphertext character with 'e', the second most common ciphertext character with 't' etc. for each character . This will result in a very good approximation of the original plaintext, but only for pieces of text with statistical properties close to that for English, which is only guaranteed for long tracts of text.

    So in a nutshell, no matter how you switch things around, it can easily be decoded just by how we spell things.

  • If you really want something secure, you might want to try the Vernam cypher.

    Read About it!

    Edit: T'was fun to implement

    Use a cipher the same size of your message, store it safely, and send it to your friend so he can decode the ciphertext with it

    Here's the demo

    You'll need a tweaked plugin

    Here's the capx

    One thing to keep in note is that as long as the cipher is kept secure and is truly random (And if i implemented it right), This algorithm can't be cracked, so don't put your cipher on the public web.

    Also, Try this;

    ciphertext = /30/76/59/69/49/103/74/28/55/29/30/75/60/33/17/34/87/0/103/84/60/2/38/14/54/82/16

    cipher = WkVePG9iGxlkODrP2tG9YqUoQ71

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)