# Thank you Julius Caesar!

--Originally published at #CParravirgen

Since the beginning of time, when human kind learn that to communicate between a lot of people, they had to speak the same language, more and more people started to learn the same language so they could understand what others were saying. This started to happen and at some point, we also felt the need to give messages to certain people without others finding out what we were saying to each other. So, how can we pass a message to someone else that is not physically close to us, but also in a secure way such that nobody else in between finds and knows what we were saying? Julius Caesar came out with a solution and an idea for this: The Cipher. What it would do is change the letters in a certain pattern, making it appear like the message has no sense when you read it, and you need the exchange pattern to decipher it.

Written in Java, a Caesar cipher could be programmed like this:

```package cipher;

public class CaesarsAlg {

String encrypt(int key, String text){
char abc[] = {'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'};
String result = "";
int size = text.length();
Character next;
for (int i = 0; i < size; i++) {
next = text.charAt(i);
int numVal = next.getNumericValue(next)-10;
result += abc[(numVal + key)%26];
}

return result;
}

public static void main(String[] args) {
CaesarsAlg myTest = new CaesarsAlg();
String text = "sbgsnofbcsghfobgtsfwfqcbcqwawsbhcgwbcqfsofzogdcgwpwzwrorsgdofogidfcdwodfcriqqwobcqcbghfiqqwob";
for(int i=0; i<26; i++){
System.out.println(myTest.encrypt(i, text));
}
}
}```

Another classic security model to cipher things and messages is the Vigenère Cipher, this one is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple form of polyalphabetic substitution.

Making a Vigenère Cipher is not so hard

program it, deciphering a message encrypted that way is quite a challenge instead.

An implementation in Java of the cipher could look like this:

```package cipher;

public class VigenerAlg {
String encrypt(int key, char text){
char abc[] = {'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'};
String result = "";
Character next;
next = text;
int numVal = next.getNumericValue(next)-10;
result += abc[(numVal + key)%26];
return result;
}

public static void main(String[] args) {
VigenerAlg myTest = new VigenerAlg();
String text = "defendtheeastwallofthecastle";
String encipher = "fortification";
int text_i = 0;
int encipher_i = 0;
int key = 0;
Character letter;
String res = "";
//myTest.encrypt(i, text);
while(text_i < text.length()){
if(encipher_i >= encipher.length()){
encipher_i = 0;
}
letter = encipher.charAt(encipher_i);
key = letter.getNumericValue(letter)-10;

encipher_i++;

res += myTest.encrypt(key, text.charAt(text_i));
text_i++;
}
System.out.println(res);

}

}```

So this is it for now, there are many more ways to cipher things, since is the major part of the classical information security models.

As always, good day, good luck, be safe, eat well, move your ass at the gym or somewhere else, take your vitamins, talk to interesting people, don’t text and drive, have enough sex (even if it has to be with yourself), learn things, share things and try to make the world a better place, move on on achieving your definition of “success” and drink more coffee!