๐Ÿ“œ โฌ†๏ธ โฌ‡๏ธ

Emoji Encryption

On the next pair of โ€œInformation Securityโ€ the teacher gave us the task to come up with our own encryption method. I immediately got the idea of โ€‹โ€‹a rather unusual (or maybe not) method. What came of it, read under the cut.



The cipher of "Caesar" was taken as the basis, the essence of which was to replace the letters by shifting the alphabet by a certain number. The number is also a key; the user enters it when encrypting.

What do we need? An array of emoji letters and symbols was compiled. For this, a script was written to parse all emoji from Vkontakte and the Delphi program to create an association by randomly mixing emoticons, as well as to add links to images. The output was something like this:
')
Array of associations
  and "โœจ", "http://vk.com/images/emoji/2728.png" 

  b "โ„", "http://vk.com/images/emoji/2744.png" 

  in "๐Ÿ€„", "http://vk.com/images/emoji/D83CDC04.png" 

  g "๐Ÿƒ", "http://vk.com/images/emoji/D83CDCCF.png" 

  d "๐Ÿ†˜", "http://vk.com/images/emoji/D83CDD98.png" 

  e "๐ŸŒ‚", "http://vk.com/images/emoji/D83CDF02.png" 

   "๐ŸŒ", "http://vk.com/images/emoji/D83CDF0D.png" 

  f "๐ŸŒ›", "http://vk.com/images/emoji/D83CDF1B.png" 

  s "๐ŸŒ", "http://vk.com/images/emoji/D83CDF1D.png" 

  and "๐ŸŒž", "1450830870441041053935" 

  th "๐ŸŒŸ", "http://vk.com/images/emoji/D83CDF1F.png" 

  to "๐ŸŒฐ", "http://vk.com/images/emoji/D83CDF30.png" 

  l "", "http://vk.com/images/emoji/D83CDF31.png" 

  m "๐ŸŒฒ", "http://vk.com/images/emoji/D83CDF32.png" 

  n "๐ŸŒณ", "http://vk.com/images/emoji/D83CDF33.png" 

  about "๐ŸŒด", "http://vk.com/images/emoji/D83CDF34.png" 

  p "๐ŸŒต", "http://vk.com/images/emoji/D83CDF35.png" 

  p "๐ŸŒท", "http://vk.com/images/emoji/D83CDF37.png" 

  with "๐ŸŒธ", "http://vk.com/images/emoji/D83CDF38.png" 

  t "", "http://vk.com/images/emoji/D83CDF39.png" 

  for "๐ŸŒบ", "http://vk.com/images/emoji/D83CDF3A.png" 

  "๐ŸŒป", "http://vk.com/images/emoji/D83CDF3B.png" 

  x "๐ŸŒผ", "http://vk.com/images/emoji/D83CDF3C.png" 

  "" ๐ŸŒฝ "," http://vk.com/images/emoji/D83CDF3D.png " 

  h "๐ŸŒพ", "http://vk.com/images/emoji/D83CDF3E.png" 

  w "๐ŸŒฟ", "http://vk.com/images/emoji/D83CDF3F.png" 

  u "๐Ÿ€", "http://vk.com/images/emoji/D83CDF40.png" 

   "๐Ÿ", "http://vk.com/images/emoji/D83CDF41.png" 

  s "๐Ÿ‚", "http://vk.com/images/emoji/D83CDF42.png" 

   "๐Ÿƒ", "http://vk.com/images/emoji/D83CDF43.png" 

  e "๐Ÿ„", "http://vk.com/images/emoji/D83CDF44.png" 

  "๐Ÿ…", "http://vk.com/images/emoji/D83CDF45.png" 

  I "๐Ÿ†", "http://vk.com/images/emoji/D83CDF46.png" 

  a "", "http://vk.com/images/emoji/D83CDF47.png" 

  b "๐Ÿˆ", "http://vk.com/images/emoji/D83CDF48.png" 

  c "๐Ÿ‰", "http://vk.com/images/emoji/D83CDF49.png" 

  d "๐ŸŠ", "https://habrastorage.org/getpro/habr/post_images/e83/65f/0bb/e8365f0bbf916dcd2feee82f85039a80.png" 

  e "", "https://habrastorage.org/getpro/habr/post_images/0d3/a7a/ff2/0d3a7aff2e3dc5d58c511f3c8d76f5d0.png" 

  f "๐ŸŒ", "http://vk.com/images/emoji/D83CDF4C.png" 

  g "", "http://vk.com/images/emoji/D83CDF4D.png" 

  h "๐ŸŽ", "https://habrastorage.org/getpro/habr/post_images/9f6/514/145/9f6514145586341507fdeb3419aadf96.png" 

  i "๐Ÿ", "http://vk.com/images/emoji/D83CDF4F.png" 

  j "๐Ÿ", "http://vk.com/images/emoji/D83CDF50.png" 

  k "", "http://vk.com/images/emoji/D83CDF51.png" 

  l "", "https://habrastorage.org/getpro/habr/post_images/6cf/2cd/60e/6cf2cd60e1966b7b22c0ede9c2569778.png" 

  m "๐Ÿ“", "http://vk.com/images/emoji/D83CDF53.png" 

  n "๐Ÿ”", "http://vk.com/images/emoji/D83CDF54.png" 

  o "๐Ÿ•", "https://habrastorage.org/getpro/habr/post_images/c8a/e3e/caa/c8ae3ecaa831341c53c06e637673b8c2.png" 

  p "๐Ÿ–", "http://vk.com/images/emoji/D83CDF56.png" 

  q "๐Ÿ—", "http://vk.com/images/emoji/D83CDF57.png" 

  r "๐Ÿš", "https://habrastorage.org/getpro/habr/post_images/a08/8af/125/a088af1256132a32f51c851801f54503.png" 

  s "", "http://vk.com/images/emoji/D83CDF5B.png" 

  t "", "http://vk.com/images/emoji/D83CDF5C.png" 

  u "๐Ÿ", "http://vk.com/images/emoji/D83CDF5D.png" 

  v "", "http://vk.com/images/emoji/D83CDF5E.png" 

  w "๐ŸŸ", "https://habrastorage.org/getpro/habr/post_images/71f/1b4/a98/71f1b4a989fbe225f56befde91b993c7.png" 

  x "", "http://vk.com/images/emoji/D83CDF60.png" 

  y "๐Ÿก", "http://vk.com/images/emoji/D83CDF61.png" 

  z "๐Ÿข", "http://vk.com/images/emoji/D83CDF62.png" 

  ~ "", "Http://vk.com/images/emoji/D83CDF63.png" 

  `" ๐Ÿค "," http://vk.com/images/emoji/D83CDF64.png " 

  !  "๐Ÿฅ", "http://vk.com/images/emoji/D83CDF65.png" 

  @ "๐Ÿฆ", "http://vk.com/images/emoji/D83CDF66.png" 

  # "๐Ÿง", "http://vk.com/images/emoji/D83CDF67.png" 

  $ "", "Http://vk.com/images/emoji/D83CDF68.png" 

  % "", "Http://vk.com/images/emoji/D83CDF69.png" 

  ^ "", "Http://vk.com/images/emoji/D83CDF6A.png" 

  & "", "Http://vk.com/images/emoji/D83CDF6B.png" 

  * "", "Http://vk.com/images/emoji/D83CDF6C.png" 

  ("๐Ÿญ", "http://vk.com/images/emoji/D83CDF6D.png" 

  ) "", "Http://vk.com/images/emoji/D83CDF6E.png" 

  _ "", "Http://vk.com/images/emoji/D83CDF6F.png" 

  + "", "Http://vk.com/images/emoji/D83CDF70.png" 

  "" ๐Ÿฑ "," http://vk.com/images/emoji/D83CDF71.png " 

  No. "๐Ÿฒ", "http://vk.com/images/emoji/D83CDF72.png" 

  ;  "๐Ÿณ", "http://vk.com/images/emoji/D83CDF73.png" 

  : "๐Ÿด", "http://vk.com/images/emoji/D83CDF74.png" 

  ?  "๐Ÿต", "http://vk.com/images/emoji/D83CDF75.png" 

  - "๐Ÿถ", "http://vk.com/images/emoji/D83CDF76.png" 

  = "", "Http://vk.com/images/emoji/D83CDF77.png" 

  / "", "Http://vk.com/images/emoji/D83CDF78.png" 

  \ "", "Http://vk.com/images/emoji/D83CDF79.png" 

  0 "", "http://vk.com/images/emoji/D83CDF7A.png" 

  1 "", "http://vk.com/images/emoji/D83CDF7B.png" 

  2 "", "http://vk.com/images/emoji/D83CDF7C.png" 

  3 "", "http://vk.com/images/emoji/D83CDF80.png" 

  4 "", "http://vk.com/images/emoji/D83CDF81.png" 

  5 "", "http://vk.com/images/emoji/D83CDF82.png" 

  6 "", "http://vk.com/images/emoji/D83CDF83.png" 

  7 "", "http://vk.com/images/emoji/D83CDF84.png" 

  8 "", "http://vk.com/images/emoji/D83CDF85.png" 

  9 "", "http://vk.com/images/emoji/D83CDF88.png" 

  "space", "๐ŸŽ‰", "https://habrastorage.org/getpro/habr/post_images/06d/0e6/e96/06d0e6e961f1030a5916279e2c57755a.png" 


In addition, another โ€œshiftโ€ array was created. Inside it contained numbers from 0 to 9, which were also assigned unique characters. In fact, you could add more numbers, this is a matter of taste. This array looks like this:

Shift array
  0 "", "https://habrastorage.org/getpro/habr/post_images/e61/d22/668/e61d226683006faa0b5a75f5f24716ef.png" 

  1 "", "http://vk.com/images/emoji/D83CDF8B.png" 

  2 "", "http://vk.com/images/emoji/D83CDF8C.png" 

  3 "", "http://vk.com/images/emoji/D83CDF8D.png" 

  4 "", "http://vk.com/images/emoji/D83CDF8E.png" 

  5 "", "http://vk.com/images/emoji/D83CDF8F.png" 

  6 "", "http://vk.com/images/emoji/D83CDF90.png" 

  7 "", "http://vk.com/images/emoji/D83CDF92.png" 

  8 "", "http://vk.com/images/emoji/D83CDF93.png" 

  9 "", "http://vk.com/images/emoji/D83CDFA3.png" 


Important note! You may have noticed that in the first and second arrays there are numbers 0-9. In order to distinguish between them, it is necessary to assign each unique character that is not previously encountered. This is an important condition for the operation of the entire cipher.


So now we have everything to encrypt the original message. First we find two numbers: the number of "shift" (borders 0-9) and the number of "position" (borders 0- "length of the original string"). Both are generated randomly. The first digit will determine the same letter shift as in Caesar's cipher, and the second number will be the position inside the string, in the place of which we will insert a smiley from the โ€œshiftโ€ array, which corresponds to the number of โ€œshiftโ€ (sorry for tautology).

We do the standard shift to the right side, but we replace them not with the shifted letter, but with its emoji symbol. During encryption, when typing the resulting string, we follow the moment when you need to insert the emoji character of the number of "shift". At the output we get a string of emoticons alone. Here we are waiting for the main problem, which is most likely associated with the correct display of emoticons. Since many browsers can display rectangles instead of the symbols we need (although this doesnโ€™t interfere with the recognition inside the code), we wrap them in with the appropriate links to the images. Thus, quite beautiful appearance of the cipher turns out.

Encryption example:

"Hello world" => imageimageimageimageimageimageimageimageimageimageimageimage
(there is no way to copy the cipher from here)

The encryption function itself looks like this:

var str = document.getElementById("text").value; var res=''; var key = getRandomInt(0,9); var key_insert = getRandomInt(0,str.length-1) ; for (var i=0;i<str.length;i++){ if (i==key_insert) {res = res+'<img alt="'+numbers[key][1]+'" src="'+numbers[key][2]+'">';} for (var j=0;j<cipher.length;j++){ if (str[i].toUpperCase()==cipher[j][0].toUpperCase()) { if ((j+key)>cipher.length-1) { res = res+'<img alt="'+cipher[(j+key)-cipher.length][1]+'" src="'+cipher[(j+key)-cipher.length][2]+'">'; } else { res = res+'<img alt="'+cipher[(j+key)][1]+'" src="'+cipher[(j+key)][2]+'">'; } } } } 

The decryption process is not much more complicated. To begin with, in the encrypted string, we look for the โ€œshiftโ€ symbol, comparing the string with the โ€œshiftโ€ array. When we found it, we translate it into a numerical value and make a reverse shift to the left, only now we replace the characters with letters.

Decryption Example:

imageimageimageimageimageimageimageimageimageimageimageimage => "Hello world"
(there is no way to copy the cipher from here)

Decryption function:

 function decodeEntities(encodedString) { var textArea = document.createElement('textarea'); textArea.innerHTML = encodedString; return textArea.value; } var str = String(document.getElementById("text").value.toString()); var res=''; for (var i=0;i<str.length;i+=2){ for (var j=0;j<numbers.length;j++){ if ( str[i]+str[i+1]==decodeEntities(numbers[j][1])) {var key = j} } } for (var i=0;i<str.length;i+=2){ for (var j=0;j<cipher.length;j++){ if ( str[i]+str[i+1]==decodeEntities(cipher[j][1])) { if ((j-key)<0) {res = res+cipher[cipher.length-(-1*(j-key))][0]} else {res = res+cipher[j-key][0]} } } } 

The decodeEntities () function is needed to convert emoji type code "" to a character. Also, when comparing letters, we fold adjacent elements. I think the reason here lies in the size of emoji, because only in this way we will get a symbol for comparison (if we try to deduce only one element by index, and not their sum, we will see emptiness).

The advantages of such a cipher include the fact that it cannot be decrypted using the โ€œrelative frequenciesโ€ method, as well as the fact that the key is not set by the user, therefore, the security of the cipher is increased.

Among the shortcomings - not all sites โ€œbeautifullyโ€ display the cipher, if at all they display it. Mobile applications generally output an empty string the place of the cipher (more precisely, the recipient sees the message this way, the sender will have a string from the set obj).

The simplest improvement would be to increase the โ€œshiftโ€ array or add another unique emoji to each digit inside this array.

What we have at the moment: sites of almost all social networks adequately display the cipher. Mobile applications are not very friendly with him. On Android, emoji also has a beautiful wrapper. Sometimes during the encryption process, emoticons like โ€œ: 3โ€ may disappear, which is not yet clear.

You can try the method here: emojicrypt.xyz
Based on the cipher "Caesar": Wikipedia
Website design is made using Material design lite: getmdl.io

Thank you for reading the article! I would be happy with suggestions and comments both on the method and on the article. And and (good for you).

Source: https://habr.com/ru/post/269259/


All Articles