Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main class="vigenere__wrapper" id="vigenere">
   
   <h1 class="vigenere__title">
      Vigenere Encryption
   </h1>
   
   <div class="vigenere__modes">
      <div class="vigenere__radio">
         <input type="radio" id="encrypt" value="true" v-model="is_encrypting">
         <label for="encrypt">Encrypt</label>
      </div>

      <div class="vigenere__radio">
         <input type="radio" id="decrypt" value="false" v-model="is_encrypting">
         <label for="decrypt">Decrypt</label>
      </div>
   </div>
   
   <textarea class="vigenere__input" rows="5" v-model="message"></textarea>
   
   <div class="vigenere__key">
      Secret key: <input type="text" v-model="key">
   </div>
   
   <div class="vigenere__message">
      <h3 class="vigenere__message-banner">
         Your 
         <span v-if=current_mode>Encrypted</span>
         <span v-else>Decrypted</span> Message
      </h3>
      
      <p>
         {{encrypted_message}}
      </p>
   </div>
</main>
              
            
!

CSS

              
                $box-shadow-light: 0 2px 4px 0 rgba(0,0,0,0.10);
$box-shadow: 0 4px 8px 0 rgba(0,0,0,0.12), 0 2px 4px 0 rgba(0,0,0,0.08);

* { box-sizing: border-box; }

input,
textarea {
   padding: 0.5rem;

   border: 1px solid #dddddd;
   border-radius: 3px;
   box-shadow: $box-shadow-light;
}

.vigenere__wrapper {
   padding: 1rem;
   min-height: 100vh;
   
   background-color: #f4fefd;
}

.vigenere__title { text-align: center; }

.vigenere__modes {
   display: flex;
   flex-wrap: wrap;
   align-items: center;
   justify-content: center;
}

.vigenere__radio {
   display: flex;
   padding: 0.5rem;
   
   input { margin-right: 0.33rem; }
}

.vigenere__input {
   display: block;
   width: 100%;
   margin: 0.5rem auto 1rem;
   max-width: 30rem;
}

.vigenere__key {
   display: flex;
   margin-bottom: 3rem;
   flex-wrap: wrap;
   align-items: center;
   justify-content: center;
   
   font-weight: 600;
   
   input { margin-left: 0.5rem; }
}

.vigenere__message {
   padding: 1.5rem;
   margin: 0 auto;
   max-width: 800px;
   
   box-shadow: $box-shadow;
   background-color: #fffefc;

   word-wrap: break-word;
   
   p {
      margin: 0;
      
      line-height: 1.25;
   }
}

.vigenere__message-banner {
   margin-top: 0;
   
   text-align: center;
}
              
            
!

JS

              
                new Vue({
   el: '#vigenere',
   data: {
      alphabet_array: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", ",", "?", "!", "\'", "_", "-", "&", "@", "#", "$", "%", "*", "(", ")", "/", ":", "<", ">", "|", "+", "=", " "],
      is_encrypting: 'true',
      message: 'This is a secret message to encrypt! In order to decode the below text, you will need the below key. Otherwise, you get a jumble of crap. Anyway, the wifi password is swordfish.',
      key: 'Good fortune'
   },
   methods: {
      convert_to_array: function(string) {
         return string.split('');
      },
      get_adjusted_key_array: function(item) {
         const item_index = this.alphabet_array.indexOf(item),
               before_index_array = this.alphabet_array.slice(0, item_index),
               after_index_array = this.alphabet_array.slice(item_index);
         
         return after_index_array.concat(before_index_array);
      }
   },
   computed: {
      current_mode: function() {
         return (this.is_encrypting === ("true" || true)) ? true : false;
      },
      message_array: function(){ return this.convert_to_array(this.message); },
      key_array: function(){ return this.convert_to_array(this.key); },
      key_adjusted_arrays: function() {
         let adjusted_arrays = [];
         
         this.key_array.forEach(item => adjusted_arrays.push(this.get_adjusted_key_array(item)));
         
         return adjusted_arrays;
      },
      encrypted_array: function() {
         const is_encrypting = this.current_mode,
               message_array = this.message_array,
               key_arrays = this.key_adjusted_arrays,
               alphabet_array = this.alphabet_array;
         
         let encrypted_array = message_array.map(function(item, index){
           const current_index = (index % key_arrays.length),
                 current_key_array = key_arrays[current_index];

            if (is_encrypting) {
               const alphabet_index = alphabet_array.indexOf(item),
                     encrypted_character = current_key_array[alphabet_index];
               
               return encrypted_character;
            } else {
               const encrypted_index = current_key_array.indexOf(item),
                     decrypted_character = alphabet_array[encrypted_index];
               
               return decrypted_character;
            }
         });
         
         return encrypted_array;
      },
      encrypted_message: function() {
         const is_encrypting = this.current_mode,
               encrypted_array = this.encrypted_array;
         
         let final_message = encrypted_array.reduce(function(acc, char, index) {
           acc += char;     
           return acc; // Can also return other values based on the array
         }, '');
         
         if (!is_encrypting) {
            final_message = final_message;
         }
         
         return final_message;
      }
   }
});

              
            
!
999px

Console