Skip to content

String Cipher

Anthony Graca edited this page Oct 28, 2016 · 13 revisions

Overview

In this lesson we will be performing string manipulation. This will allow us to change each character of a string into some other character, allowing us to encrypt/decrypt our string.

New Concepts

Procedures

Sometimes we want to reuse code over multiple places. Although we could copy and paste code blocks, it is not the ideal way to reuse code because it makes our code look more complicated than it really is. Procedures allow us to only use code blocks once and reuse them wherever we want with one block.

Procedure

String Manipulation

We will need to use several blocks to be able to perform certain operations with our text strings.

  • Join - allows us to put two text strings and combine them into one. e.g "Te"+"xt" = "Text" Concatenate
  • Starts at - allows us to find where a certain character starts in a text string. For example, if we had the text string "Text", 'T' would be at position 1, 'e' would be at position 2, 'x' would be at position 3, 't' would be at position 4. If we wanted to know the position of "T', we would get the number 1.'

Index_Of

  • Length - This gives us the length of the string. So, if we had the string "Text", the length would be 4 because it has 4 characters.

Length

  • Segment - This allows us to cut the string from some position of a certain length. In this block example, we would take the "Text" string and cut the string starting at 1, which means our segment will start at 'T' since 'T' is in position 1. The second part of this segment block is to cut a certain length and in our example, we want our cut string to be of length 1. So since 'T' is in position 1 and of length 1, our new cut string is 'T'.

Substring

Let's Get Started!

How does a Cipher Work?

A Cipher works by using a key so that it can transform one letter into another letter. This key also allows us to transfer the encrypted message back into its original message. It is important that everyone uses the same key so that everyone can encrypt and decrypt the same message.

Our Cipher Key will be simple to use but still gives us a complicated encrypted message. Our Key will work by turning each letter in the alphabet into the next letter. So, A -> B, B -> C, C -> D, ... , Z -> A.

Plain Text: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !?.-_

Cipher Text: BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza !?.-_

External References: