Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>
  <head>
   <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
  </head>
    
    <body>
    <div id="manual">
     <h2 id="manual-heading">Users manual</h2>
      <!--<p class="manual">To use this tool you should first be familiar with what Vigenere cipher is and how it works.</p>  --> 

<p class="manual">This is a simple helping tool for hacking Vigenere's ciphertexts. The tool does not help you get the secret key's length - you should  figure it out (or better yet - guess) on your own (via
 some website or manually - there's plenty resources) but once you do get the supposed lenght of the key you can start playing with the software provided here.</p>
 
 
 <p class="manual">The first input field is where you put in the length of the key, for example "5".</p>
 
 <p class="manual">When you submit the number (Press "Sift text") the program will generate specified number of columns (five in this case) and fill each column with the coresponding 
 letters and also create specified number of buttons (also five in this case). Each of the buttons coresponds to one column (1. button coresponds to 1. column from the left, 2.button to 2.column, etc.).</p>
 
<p class="manual"> By pressing the sorting button (below the "Sift text" button) it will sort out all the letters making it easier for you to determine their regularity.</p>
 
 <p class="manual">Lastly there is the input field for the letters that you want to shift text in the coresponding columns by. Example : Lets say that you suspect that the key word is "APPLE". To check out your assumption you should put an "A" in the input field
  and press the first button, than put in "P" in the input field and press second and third buttons, put in "L" and press the fourth button and so on.</p>
 
 <p class="manual">And that is mosty it. There are a few important notices to add:</p>
 
 <ol>
 <li>The ciphertext is hardcoded into HTML. If you want to experiment on some other text, you should put your text into the appropriate spot in the HTML code (line 43).</li>
 <li>All text should be uppercase - otherwise it will not work.</li>
 <li>Program only works for the Slovenian alphabet as it is now - that means that there are no Q,X,Y or W in the program and if you happen to put one in in the ciphertext that will probably break the code and make your
 computer explode in purple fire. So adjust the code if you need to.</li>
 <li>When you use "Sort text" button I suggest that you copy paste the results in a text editor where you can count the letters much easier. If you want to retrieve the original occurance of the ciphertexts letters 
 you should restart the whole thing and go from the begining by pressing F5.</li>
 <li>When you "Sift text", you can only do it once. If you want to sift text by a different number you should refresh the page by pressing F5. Otherwise funky things will start happening.</li>
 </ol>
        
      <p>Spoiler alert: For those of you that will actually try and decipher the text - the original text is obviously in slovenian language and the key length is in fact 5. Another hint: middle row is not really ciphered - there is no shift there ;)</p>
      <p><a href="https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher">What is Vigenere's cipher?</a></p>   
      </div>
      <div id="tool">
        <h2>Your ciphered text</h2>
        <textarea rows="10" cols="30" id="ciphertext">
ZCKDTIJOFMČFMŠHSNASCNHOUMVLRNGSJEIVBVDEMLCPFMFRRNJNNEAČMNEKČIIIAMVCNČSTLMJBŽNAHCIOLDCSRIFČTLNNEIJOSMCCLNPZVNNFSRIOASUIČSZCKDBEJOFMČJOFMČROŽSTLTAEEEKDHALŽZENHVDRNJOFMČBAIVCŠOŽSJCLŠČJIAASCŠOŽSMNZČSARIPSCVNŽFFLJŠDUVŠČSARIPSZCMDPSKEAZNŠEČRINMDEIZIIVGVNŽSPKELRŽJIFISKNŠLZLSIVZCKDTIJOFMČFMŠHSNASDIAEEEIŠTFMFCRŠŽŽBRŠJŽVLZŽIJEČŽNNDFSFCSNVZRRNJNŠESČGVSNBŽROAMŠRIAČBVKZJCCLŠZŽBISSŠLDNAŠCPNPNMRNJCCZNUSMUGHIŠIŽČTCRFSTVVŠKIUABČCRČŠFNIEČMPKEČMMOVDZŽDLDNSKOASBHACSZMOLCIZOBSLFNDŽŽIIAČDCŽAVRKOUZNUEHAŽAELCŠCGDJŽKECČCNCŠCNHOUMVLRNGSJEIVBVDČSTLGNBŽNAHVVCTZEIBZČSTLMCČBVŠKŽŽNAAJSOTDFUCDDHBVVŠENHAAMVCNSENŠOCČUAERVCMRŠBUGEKMUŽIGMVLTČSHCVZCLSDNŽŽŠDDNBVVŠASHAOVDGAAVCMRŠTŽŠOFSCVMDŽIBAFIVLLACNGOBZEBJŠ</textarea>
        
        <br><br><br>
        <p>Put your key length here below</p>
        <form>
            
            <input type="text" name="index" id="index">
            <br><br>
            <input type="button" onclick="readByIndex()" value="Sift text, watch the magic happen">
            <br><br>       
            <input type="button" onclick="sortChars()" value="Sort text to to see which letters are the most common">
            <br><br>
            
        </form>
        
        <div id="cilj3"> 
            <input type="text" name="givenChar" id="givenChar" placeholder="Your letter here - upper case only">
            <br><br>
        </div>
        
        <div id="cilj2">            
        </div>
      </div>
    
    </body>
</html>
            
          
!
            
              *{
  font-family:'Roboto';
}

body{
 background-color:skyblue;  
}

textarea {
  font-size: 22px;
}

#cilj2 {
  width: 45%;
  height: auto;
  border: 2px solid green;
  padding:18px;
  background-color: #00cccc;/*#00cc99;*/
  margin-left:25%;
  border-radius:10px;
}

#cilj2 textarea{
  font-family:serif;
  width:31px;
  text-align:center;
  margin-right:5px;
  padding-right:10px;
}

div {
  /*width: 30px;*/
  /*border: 1px solid gray;*/
  float: left;
  margin: 5px 5px;
}

#cilj3 {
  float: left;
  border: 2px solid  #ff8566;
  width: 50%;
  text-align:center;
  background-color:pink;
  border-radius:10px;
  margin-left:25%;
}

#manual-heading{
  text-align:center;
}

#manual{
  width:30%;
  padding:30px;
  float:left;
  border-radius:30px;
  border:3px solid #00b3b3;
  background-color:  #ffbf80;
}

#tool{
  padding:30px;
  width:55%;
  float:right;
  background-color:#87c5a6;
  border-radius:30px;
  border:4px solid #00b3b3;
  text-align:center;
}

#givenChar{
  margin-top:12px;
}

#cilj3 button {
  margin:5px;
  border-radius:10px;
}

#cilj3 button:hover{
  background-color: #cce6ff;
}

li{
  margin-top:15px;
  font-weight:bold;
}
            
          
!
            
              /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //1. Funkcija vzame dolžino predvidenega ključa in razdeli tekst na n delov oz stolpcev ki vsebujejo vsak korespondenčno vsebino
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            function readByIndex(){
                
                var ciphertext = document.getElementById('ciphertext').innerHTML;
                var index = parseInt(document.getElementById('index').value, 10);
                var secondaryIndex = 0; //namenjen je drugi for zanki, razlaga na vrstici 78
                var arrayArray = [];
                var textArray = [];

                //Razbije zašifriran string in napolni z dobljenimi črkami tabelo textArray
                textArray = ciphertext.split('');  
                
                //ta zanka razbije vso besedilo in napolni n-število tabel s stringi, ki so sestavljeni iz zaporedja znakov, ki se nahajajo na indexih 0,n,2n,4n,... / 1, 1+n, 1+2n, 1+4n ... / etc.... / 2, 2+n, 2+2n, 2+4n,... / n-1, 2n-1, 4n-1,... / n, n+n, 3n, 5n
                for(var i = 0; i<index; i++){
                    var temporaryArray = [];
                    var newString;
                    for(var j = secondaryIndex; j<textArray.length; j+=index){
                        temporaryArray.push(textArray[j]);                        
                    }
                    secondaryIndex++;
                    newString = temporaryArray.join("");
                    arrayArray[i]+=newString;
                }                
                secondaryIndex = 0;
                
                //poreže "undefined" substring ki se nekako pojavi na začetku vsakega stringa v tabeli arrayArray 
                for(var i = 0; i<arrayArray.length; i++){
                    var str = arrayArray[i].substring(9);
                    arrayArray[i] = str;                
                }
                
                //Ustvari n število stolpcev oziroma <textarea> elementov, ki je enako številu samostojnih stringov v arrayArray-u
                for(var i = 0; i<index; i++){
                    var newColumn = document.createElement('textarea');
                    var element = document.getElementById("cilj2");
                    element.appendChild(newColumn);
                }
                
                //Ustvarim tabelo oziroma objekt, ki ga napolnim z vsemi <textarea> elementi
                var arrayField = document.getElementsByTagName('textarea');
                var colNum = 0;
                
                //Določi primerne razrede vsakemu stolpcu, med vsemi <textarea> značilkami začne pri indeksu 1 ker mora preskočiti prvo text polje, vsak stolpec dobi svoj class in primerno vrednost, ki jo dodeljujem s pomočjo colNum
                for(var i = 1; i<arrayField.length; i++){
                    var classNum = "txtarea"+colNum;
                    
                    arrayField[i].setAttribute('id', classNum);
                    arrayField[i].setAttribute('cols', 1);
                    arrayField[i].setAttribute('rows', 30);
                    
                    //Napolnim vsak stolpec posebaj s primernim stringom iz arrayArray-a
                    arrayField[i].innerHTML = arrayArray[secondaryIndex];
                    
                    //ustvarim gumbe, ki bodo služili za proženje metode za shift-anje črk v določenem stolpcu
                    var newBtn = document.createElement('button');
                    newBtn.setAttribute('type', 'button')
                    newBtn.setAttribute('class', 'myBtn')
                    
                    //spodnja shiftChar funkcija sprejme 2 argumenta, v prvem je string, v drugem argumentu je unikatni razred s pomočjo katerega kasneje vračam spremenjeno besedilo v primeren stolpec
                    newBtn.setAttribute('onclick', 'shiftChar(\''+arrayArray[secondaryIndex]+'\',\''+classNum+'\')');
                    newBtn.innerHTML = 'Button for shifting letters in column number '+i;
                    var element = document.getElementById("cilj3");
                    element.appendChild(newBtn);                    
                    secondaryIndex++;
                    colNum++;                    
                }                
                secondaryIndex = 0;
            }
            
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //2. Funkcija razporedi znake po vrednosti. To rezultira v enakih črkah skupaj. Tako lažje ocenimo katere črke so  najbolj pogoste
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            function sortChars(){
                
                var arrayArray = document.getElementsByTagName('textarea');
                
                for(var i=1; i<arrayArray.length; i++ ){
                    var str = arrayArray[i].innerHTML;
                    var tempArray = str.split("");
                    var secondTempArray = tempArray.sort();
                    var secondStr = secondTempArray.join("");
                    arrayArray[i].innerHTML = secondStr; 
                }
            }
            
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //3. Funkcija zamenja izvorne znake za primerne protivrednosti v abecedi, doda željeni "shift" in izpiše nove znake v primernem stolpcu
            //   s pomočjo drugega argumenta address pa servira nov string v primeren stolpec
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            function shiftChar(str, address){
                
                var givenChar = document.getElementById("givenChar").value;
                var targetTextArea = document.getElementById(address);
                var stringToFillAlphabet = "ABCČDEFGHIJKLMNOPRSŠTUVZŽ";
                var indexValuesShifted = [];
                var indexValuesOrig = [];
                var shiftedStr = [];
                var alphabet = [];
                var givenStr = str;
                var numToSubtract;

                
                
                alphabet = stringToFillAlphabet.split("");

                //poiščem številsko protivrednosti črk glede na abecedo in jo shranim
                for(var i = 0; i<alphabet.length; i++){
                    if(givenChar == alphabet[i]){
                        numtoSubtract = i;                        
                    }  
                
                }
                
                //poiščem številske protivrednosti črk glede na abecedo in jih push-am v nov array indexValuesOrig
                for(var i = 0; i<givenStr.length; i++){
                    for(var j = 0; j<alphabet.length; j++){
                        if(givenStr[i] == alphabet[j]){
                            indexValuesOrig.push(j);
                        }
                    }                    
                }
                
                //številske vrednosti(indekse) črk sedaj prilagodim glede na od uporabnika podano črko oz. protištevilko in jih push-nem v nov array indexValuesShifted
                for(var q = 0; q<indexValuesOrig.length; q++){
                    var newValue = Number(indexValuesOrig[q]) - numtoSubtract;
                    if(newValue<0){
                        var num = 25 + newValue;
                        newValue = num;
                        //newValue*=(-1);
                    };
                    var newShiftedValue = newValue%25;   
                    indexValuesShifted.push(newShiftedValue);
                    console.log(newShiftedValue);
                }
                console.log(indexValuesShifted);
                
                //nove, shiftane vrednosti prenesem nazaj v ustrezne abecedne protivrednosti in jih push-nem v nov array shiftedStr
                for(var r = 0; r<indexValuesShifted.length; r++){
                    for(var p = 0; p<alphabet.length; p++){
                        if(indexValuesShifted[r] == p){
                            shiftedStr.push(alphabet[p]);
                        }
                    } 
                }
                console.log(shiftedStr);
                
                var finalStr = shiftedStr.join("");
                
                //nazadnje črke oziroma nov, spremenjen string sprojiciram še v primeren protistolpec ki ga pred tem za vsak slučaj spraznim 
                targetTextArea.innerHTML = "";
                targetTextArea.innerHTML = finalStr;
                console.log(shiftedStr);
                console.log(20%25);
                //Voíla!
            }
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console