Cipher v4

The analysis function.

Skills: InputOutputVariablesIf StatementsLoopsArrays
1%

Brief

Add a button that analyses a string of pipe-separated numbers and outputs how many times each number appears in the string.

The user should be able to input any series of pipe-separated number, click a button, and be given the frequency of each number, e.g.

118|114|35|112|100|113|124|35|118|104|102|117|104|119|35|112|104|118|118|100|106|104|118|36|35|122|107|114|35|110|113|104|122|35|104|113|102|117|124|115|119|108|114|113|35|122|114|120|111|103|35|101|104|35|118|114|35|104|123|102|108|119|108|113|106|36|

outputs...

100 appears 2 times.
101 appears 1 times.
102 appears 3 times.
103 appears 1 times.
104 appears 8 times.
106 appears 2 times.
107 appears 1 times.
108 appears 3 times.
110 appears 1 times.
111 appears 1 times.
112 appears 2 times.
113 appears 5 times.
114 appears 5 times.
115 appears 1 times.
117 appears 2 times.
118 appears 6 times.
119 appears 3 times.
120 appears 1 times.
122 appears 3 times.
123 appears 1 times.
124 appears 2 times.
35 appears 10 times.
36 appears 2 times.

Here's some references to help you write this function:

Extension

Here's some features that you could implement to make this app even better.

  • Add an input where the user can specify the shift. This will help them test different shifts when using the analysis to crack an encryption.

  • Output the analysis in sorted order so that the most frequent numbers appear at the top. This will help the user make better guesses of what an unknown shift might be.
  • Add to the analysis an output that suggests possible shifts. If a code is the most frequent, calculate what shifts would translate it to e, a, i, and o. The user can then try those recommended shifts to see if they correctly decrypt the ciphertext.

You can use the Svelte example below if you need help to get started. It contains all of the code for this program. If you can, try to complete the program without looking at it.


Sandbox

Feel free to play around with the example below to see how the web page reacts to your code changes in a consequence-free environment. You won't break or overwrite anything so go for gold.