Sunday, 24 April 2022

The man in black - chapter 1 (short story)

chapter 2 | chapter 3 | chapter 4

Cassie laughed.

“Yeah, that’s the most likely answer!”

“Sure, laugh!” said Anna, “I’m not sure it was technically in the syllabus!”

Cassie was in a small café in the mall near their university. The semester was over, and many of them would be heading home for the next month. That is why they had gone there for a movie, some gift shopping, and to have some fun with friends before that.

“Can we talk about something that’s, you know, not subject related?” asked Jake, “for example, which film are we watching?”

“There are a few good options,” said Dany, Jake’s girlfriend and newest addition to their group, “Okay, two as far as I am concerned. What about the rest of you?”

Phil had the website of the theatre up on his phone. “Boring romance, comedy, with huge inverted commas around 'comedy', not in English, not in English, superhero, action movie, and super serious awards bait. Dany’s right, there are only two options.”

“You can go watch the awards bait,” said Lex, “it might help you catch up on some sleep.”

“Very funny,” said Phil, “seriously, which one shall we watch?”

Cassie noticed a huge stack of boxes at the counter of the coffee shop. Probably some sort of order, she thought. There were two employees in the shop, and they were stacking it there. Cassie expected someone would come pick it up.

By now, the shop was almost empty except for them. That was no wonder, as they were a little past teatime. Most people would start having dinner. Cassie wondered who would be ordering stuff from a café at this time. Maybe it was for a party. That sort of made sense, especially if they’d be having dinner at late at night.

Anna sipped her coffee. “Let’s pick one when we get there. What do we do about food? Smuggle it in, or buy popcorn?”

“Eat once it’s over?” asked Dany, “it’s less illegal, somehow. They don’t want you smuggling food it because it stinks.”

“She’s got a point,” said Phil, “but I’m not buying popcorn. Seriously, why isn’t this a watch party at one of our rooms again?”

“Never occurred to anyone?” asked Cassie.

A pair of men came into the café. Cassie noticed they were dressed somewhat formally, but fancily. It was a party, probably some sort of minor cooperate event, thought Cassie. They started talking with the cashier. The waiter went out to get a trolley. Cassie could see why that would be needed. The car park was not that far away, but it was a lot of boxes.

“Let’s have a bit of a snack before the movie starts,” said Phil, “we have at least an hour to kill as it stands because someone’s idea of shopping was, well, strangely efficient.”

“I don’t like shopping, that’s why I made a list,” said Dany.

“Not judging you. Just an observation.”

“So, order some sandwiches?” asked Jake.

They all looked at each other, and a few of them nodded. Jake went up to the counter and placed the order. Just then, the waiter returned with a trolley. Cassie admired his self-control. She would have used it as a skateboard.

Both employees and the two men who came with them were kept busy filling up the trolley. The seven of them sipped their drinks slowly, trying to decide on a film, which then drifted into debate/ discussion about a previous film. Cassie hadn’t watched it, so she let Phil, Lex, and Bella debate it. The trolley was filled up, the men paid in cash, and they wheeled the trolley out. The waiter followed them, presumably to help them load it into a vehicle.

The waiter returned a few minutes later. He collapsed on a chair behind the counter. The cashier went into the kitchen. Cassie assumed it was to make the sandwiches they had ordered.

Outside, the mall was fairly crowded. The shop was a little glass island in the middle of the mall. There was a speciality food shop a little way away. It was way out of their price range. There was a couple of branded clothes shops. There was also a bookshop. Cassie wanted to go in there, in a way, but buying physical books didn’t make a lot of sense given her current living situation.

Cassie had her work cut out for her over the break. She had decided to go home for two weeks. The air ticket was expensive, but she wouldn’t have a chance to go home over the next summer because of her internship, which meant it was now or never. Going home would probably mean a trip, lots of food, and buying lots of stuff to bring back. On the other hand, she would not get any work done during that time, and she really wanted to practice what she had learned that semester, at least to stay in touch with things.

She had her sandwich mostly in silence as the discussion turned into a full-blown debate between Bella and Lex. She spent her time studying those around her. The couple sitting at the next table sat up. They finished and then paid the bill. They were dressed well. Possibly a date, Cassie decided. There was another man sitting alone at a table, staring at his phone and inhaling coffee. He wouldn’t be there long either, thought Cassie. He desperately needed to be awake for something, probably work of some sort given how he was scrolling through something on his phone.

The man stood up, as Bella launched into a tirade about a scene in the film they were talking about and how it illustrated her point. He paid the bill, and left. Their group was the only one left in the café. It wasn’t an issue, as there was a couple of hours to the displayed closing time.

Then someone walked in. Cassie sat up immediately. This person was wearing a long coat – a weird choice given the climate – as well as a black hat and a black mask, with dark sunglasses. They were also carrying a plain black drawstring bag and wearing gloves. Cassie couldn’t tell anything more about them other than their height – roughly in the 170 cm range – and the fact that they were wearing regular shoes most men would wear to work. Also, their hair was black and a little longer than shoulder length, but that was likely a wig.

Cassie stiffened. She nudged Dany, who was seated next to her. Phil, too appeared to have noticed what was happening.

Then, this person unfolded a piece of paper from their coat pocket and displayed it to the cashier. Cassie noticed her eyes widen.

Cassie realized it immediately – the shop was being robbed, and they were in the way if anything were to happen.



END OF CHAPTER ONE

Next chapter: chapter 2 | chapter 3 | chapter 4

You can also follow me on Facebook here.

Until next time!

Sunday, 17 April 2022

A simple cipher with randomness to deter breaking it - The cipher used in The Cipher (short story)

This is the code used in The Cipher (short story) which was published in this blog. It is a very simple cipher. You can read the story in question here: chapter 1  | chapter 2 |  chapter 3 | chapter 4

Hopefully, this is a fun coding exercise for you.

To cipher:

  1. You can use only letters and space. Any other characters will have to be changed into these (or the code changed to accommodate them, which is trivial).
  2. Take the plaintext one letter at a time. Convert it to a number (A-Z corresponding to 0-25, space = 26).
  3. Generate a random single byte hexadecimal number
  4. Generate a second number so that the modulus 27 of the sum of the two numbers gives the number that corresponds to the character you want to cipher. Mathematically: (random_number_1 + random_number_2) mod 27 = the numerical equivalent of the character to want to encipher. We'll see the detail of the maths in the code below.
  5. That is your ciphertext. Repeat for every letter in the cipher.

A graphical representation of the enciphering method mentioned above.

To decipher:

  1. Take two hexadecimal numbers out of the cipher (four characters, break it into blocks of two characters each)
  2. convert them to the usual denary numbers
  3. Add the numbers, take the modulus 27 of the sum
  4. Match to corresponding letter / space
  5. This is your plaintext. Repeat through the entire ciphertext.

A graphical representation of the deciphering algorithm above.


The code:

The code is given in Java this time. Converting it to C++ is easy, as all the methods used are static, so you can put everything into one file without issue. Alternatively, you can call the method from another class as well. Either way should work.

Class Cipher:

This class handles the basic cipher operations. It accepts a line of ciphered text and deciphers it, or vice versa. I have left all the functions public, but it is not necessary. You can leave just the cipherLine and decipherLine methods public and make the rest private, it should work just fine.

I've also made all the functions static. You can go ahead and make the class static as well, because you really don't need to instantiate it. Alternatively, you could remove the static keyword from all the methods and use an instance of the class Cipher in main, but it's pointless as there is no need to instantiate it.


import java.util.Random;

public class Cipher {
private static Random rd = new Random();

//To store alphabet of cipher
private static char[] letters1 = {'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',' '};
//To store alphabet, lower case. The cipher can translate from upper case or
//lower case as programmed, but the deciphered result will be upper case.
private static char[] letters2 = {'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',' '};

/*
Ciphers a line of plaintext.
Returns the ciphered line.
*/
public static String cipherLine(String line){
String ciphered = "";
for (int i = 0; i<line.length(); i++){
ciphered = ciphered+encipher(line.charAt(i));
}
System.out.println(ciphered.length());
return ciphered;
}

/*
Ciphers a single character
Returns the ciphered equivalent of the character
*/
public static String encipher(char letter){
String ciphered = "";
int num = 0;
int rem1 = 0;

//get equivalent numerical value
num = mapNum(letter);

//If number isn't mapped, that character is skipped over.
if ((num>26)||(num<0)){
ciphered = "";
System.out.println("invalid input");
return ciphered;
}

//Generates the two numbers whose sum produces the modulus 27 value we want.
//If you want an alphabet with over 27 characters, you can replace the value here.
int num1, num2 = 0;
num1 = rd.nextInt(256);
rem1 = num1%27;
if (num>rem1){
num2 = ((rd.nextInt(8)*27+(num-rem1)));
}
else if (num==rem1){
num2 = ((rd.nextInt(8)*27));
}
else{
num2 = ((rd.nextInt(7)*27+(27-rem1)+num));
}

String temp1, temp2;
temp1 = Integer.toHexString(num1); //Convert to hex
if (temp1.length()==1) temp1 = "0"+temp1; //Pad if it is not two characters
temp2 = Integer.toHexString(num2);
if (temp2.length()==1) temp2 = "0"+temp2;

ciphered = temp1+temp2;

return ciphered;
}

/*
Maps a letter to a corresponding number (index of array).
Works with both upper and lower case characters.
Returns corresponding number.
*/
public static int mapNum (char letter){
int num = 0;
for (int i =0; i<27; i++){
if ((letter==letters1[i])||(letter==letters2[i])){
num = i;
break;
}
else{
num = 28;
}
}

return num;
}

/*
Deciphers a line of enciphered text.
Returns the plaintext of that line.
*/
public static String decipherLine(String line){
String deciphered = "";
char letter ='0';
for (int i = 0; i<(line.length()/4); i++){
letter = decipher(line.substring(4*i, 4*(i+1)));
deciphered = deciphered+letter;
}
return deciphered;
}

/*
Deciphers a pair of hexadecimal numbers (or four characters).
Returns one plaintext characters.
*/
public static char decipher (String letters){
int num,num1,num2 = 0;
char letter;
if (letters.length()!=4){
System.out.println("wrong length for character" + letters);
return '0';
}
String temp1 = letters.substring(0,2);
String temp2 = letters.substring(2,4);

num1 = Integer.parseInt(temp1,16);
num2 = Integer.parseInt(temp2,16);


num = (num1+num2)%27;

letter = mapChar(num);

return letter;
}

/*
Maps a number to a character. Simply look up value in array if within range.
Returns character corresponding to number.
*/
public static char mapChar(int num){
char letter = '0';
if ((num<0)||(num>26)){
System.out.println("Invalid number");
return letter;
}
letter = letters1[num];
return letter;
}
}

The breakdown:

Importing Random: because we're using random numbers to add a level of randomness when we're enciphering it.

Then within the class, random is initialised. 

The two arrays letters1 and letters2 are used to store the letters / characters used in the cipher.

Function cipherLine takes in one line of text, extracts a character from it at a time, and enciphers it.

The function encipher takes in a character sent to it by cipherLine, and ciphers it. This is where bulk of the processing happens. First, the number corresponding to the letter is obtained from mapNum. Then the return value is checked, and if it is not in range, the character is simply not ciphered. If it is in range (0-26 for mod 27, for 27 characters in the alphabet (letters + space)) Then it proceeds to generated the ciphered values.

This is done by generating a random number under 256 (as we want it to fit to 8 bits or two hexadecimal characters). This is the first number, num1 . The next part is generating the second number (num2) so that you get the required result by (num1 + num2) mod 27. This also includes a random component. Random numbers from 0-7 are used because 0 to 7*27 is 0 to 189, which will keep you just below the ceiling of 255 even if you add 27 to it.

The calculation basically is,

  1. First, calculate first number (num1in the code) modulus 27. rem = num1 mod 27. This value is used in the next part of the calculation.
  2. Then compare it with the remainder you need, i.e., the value that mapNum gave you. This is called num in the code.
  3. If rem is greater, simply calculate the difference (rem - num). Tack that on top of an integer multiple of 27 (the integer 0-7 generated randomly, multiplied by 27) and assign it to num2, you're good to go. In equation form: num2 = (random integer * 27) + (rem - num).
  4. If the two are equal, simply assign an integer multiple of 27 to num2. That is, num2 = (random integer * 27).
  5. If num is greater, calculate (27 - rem) + num, add that to an integer multiple of 27. However, note that you can't use a multiple of 7 here, as you may go over 255 in that case. That is why 0 to 6 is used. In equation form: num2 = (random integer *27) + (27 - rem) + num.

Once this is done, you have two numbers under 255, whose sum mod 27 gives you the index of your plaintext. These numbers are still integers, so the function Integer.toHexString() is used to convert it to a hexadecimal number. Note that the output is a string and not a number, which is actually convenient for us.

Next you have to check whether it's a single character, and if that's the case, you need to pad it with a zero, otherwise it'll affect the length of our string. This is the set of four characters is returned.

The next function mapNum is also fairly straightforward. You check whether the character you want is in the alphabet. If it is, return its index, if not, return 28 which the function encipher reads as an error.

Next we get to the functions related to deciphering.

decipherLine takes a string, and feeds four characters into the decipher function at a time. I used substring to do this. 

decipher is the function where most of the calculation takes place here as well. First, it checks whether the incoming data is four characters long. if it isn't, it's not decoded. However, there is a problem here in that it doesn't check whether it's a valid hexadecimal number. You can try adding this part yourself.

From then on, it's simple, use substring to break it into two numbers of length 2 each, then convert both to numbers using Integer.parseInt(temp1, 16). The second argument, 16, tells the program that it's a hexadecimal number.

Then you add the two numbers together and get the modulus, which gives you the index of the character you want.

The next function mapChar, does exactly what its name says - gets the number, check if it's in range and get the corresponding letter from the alphabet.

Class Main:

This one is mostly housekeeping: selecting mode (cipher or decipher), telling the program where to get the ciphertext / plaintext, and feeding in a line of the input to the cipher or decipher function.


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// For user input
char inChar = '\0';
//Whether cipher or decipher mode
int mode = -1;

//For reading input
Scanner sc = new Scanner (System.in);

//Cipher or decipher mode: user input
System.out.println("Select C for enciphering, and D for deciphering");
inChar = sc.next().charAt(0);

if ((inChar=='c')||(inChar=='C')){
System.out.println("Ciphering mode");
mode = 0;
}
else if ((inChar=='d')||(inChar=='D')){
System.out.println("Deciphering mode");
mode = 1;
}

//Ciphering data:
if (mode==0){
String ciphered = "";
//For reading from file
try{
File myFile = new File("input1.txt");
Scanner myReader = new Scanner(myFile);
while (myReader.hasNextLine()){
String line = myReader.nextLine();
//Call the cipherLine method from Cipher to get ciphertext
ciphered = ciphered + Cipher.cipherLine(line) + "\n";
}
System.out.println(ciphered);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(0);
}
}
else if (mode ==1){
String deciphered = "";
//For reading from file
try{
File myFile = new File("input2.txt");
Scanner myReader = new Scanner(myFile);
while (myReader.hasNextLine()){
String line = myReader.nextLine();
//Call the decipherLine method from Cipher to get plaintext
deciphered = deciphered + Cipher.decipherLine(line) + "\n";
}
System.out.println(deciphered);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(0);
}
}

}
}

The breakdown:

Imports: Java.io.File and Java.io.FileNotFoundException are for reading from file. If you're going to hardcode the ciphertext / plaintext or if it's going to be user input, this is not necessary. Java.util.Scanner is used for both reading user input and reading files.

The first few variables are explained in the code itself.

Next, it asks the user whether to encipher or decipher. If the user input is c for encipher or d for decipher, it runs the respective program (using the mode variable to remember it), otherwise it simply ends. Maybe you can add a message there to let the user know this is happening.

If the mode is 0 (enciphering mode), it reads the input from the selected file line by line, and feeds into encipherLine from the Cipher class, and tacks it onto a string which is then printed once it is done processing the file. You can modify this to output to a file if you want to (which is probably more convenient if you're dealing with a lot of text).

If the mode is 1 (deciphering mode), the process is exactly the same except decipherLine is called.


In conclusion

This cipher is a bit bloated and it's not very efficient, but it's a fun exercise. The biggest advantage here is a result of the bloat, that is, the use of random numbers in the ciphering process makes it nearly immune to most conventional deciphering approaches. 

However, it is not a safe cipher, because once you know the method, you don't really need a key. Another problem is that the length of the message increases by a factor of four which will be problem if you want to cipher a really long message. It could be worse (it could be exponential), but this situation isn't exactly ideal.

Maybe you can also try modifying this to make a new, more secure cipher. Or you could come up with something completely different just for the fun of it. Anyway, I hope you have fun with it.

If you have anything to add, or if you want me to clarify anything, please comment below. I will reply as soon as I can.


You can also follow me on Facebook here.

Until next time!


Monday, 11 April 2022

The Cipher - Chapter 4 (short story)



After the snack break, they got back to work again. Cassie looked at the program Phil had created. It was at a higher level than she would have programmed, but she understood what it did. She looked at the snippets again.

There was no way the divisible by four thing was accidental. This cipher worked in pairs of hexadecimal numbers. It could be the Playfair cipher, but that would be hard to crack. No, that couldn’t be. Dany wouldn’t expect Jake to crack that. It was doable, but it would require a considerable amount of subject knowledge and a lot of maths. She couldn't expect Jake to convince someone else to do it for him either.

It had to be much simpler. Especially if, as she suspected, it had something to do with Jake’s upcoming birthday. That would be completely consistent with Dany’s character.

Unless it really was Playfair and the keyword was something significant to the two of them. If that was the case, they were doomed. There was no way Jake could recall something like that, and they'd all be caught in the crossfire.

Cassie pushed it to the back of her mind. The Playfair thing would be a last resort. No, she had to think simpler. What if two hexadecimal characters represented one letter? Sure, it was wasteful, but it would work.

How would she do that?

The most obvious would be adding the two characters followed by modulus 26. Cassie decided to try modifying the program on her own.

This took a bit of time. She had Phil’s code as a starting point, but she still had to look stuff up. After messing with it for about ten minutes, she ran the code. Immediate syntax error.

Cassie was used to this. She checked the code and realised she had missed a single quotation. She fixed that and ran the code. It spit out a result for the first message.

VLLIXIHXUETNONBRZMBNQWHGJWDGMNKSLRRFQOCJMMIEXPMAPPKZJOQXQHQZOXXMFQPWOTDWAUNAIUCVNKBNGNWFYWGUZANGWKTLELOXJECRZLLAA

That didn’t look better than anything else they had so far.

Cassie leaned back in her chair.

She thought for a moment. Then she remembered what they had attempted before the snack break. She could try other alphabets, such as including a space, including numbers, special characters, all of that. Now that the code was set up, it was child’s play. She ran it with just letters and space first, so that it would have 27 possible characters.

I CAN ARRANGE SOMETHING AT THE MALLTHE CAFE ON THE SECOND FLOOR DOES PARTIESYOUR JOB IS TO LURE HIM THERE SOMEHOW

So that was it. It was absurdly simple. You just added the adjacent hexadecimal numbers, found the remainder when it was divided by 27, and matched it to A-Z and zero. There were no keys, nothing. The really clever part was a sort of randomness built into the code that would fool most traditional code breaking approaches. 

She had to be friends with Dany.

Cassie forced herself down to earth again. She looked across at Jake. He was on his phone, smiling at something. He was still distracted. He hadn’t seen her reaction. Good.

She put the next message in, line by line this time.

STOP STRESSING ABOUT IT
EVEN IF HE SUSPECTS SOMETHING HE WONT REALLY KNOW UNTIL THE DAY
CAN YOU THINK OF A WAY TO INVITE HIS FRIENDS WITHOUT ALERTING HIM

Both looked like messages to Dany from someone. Cassie copied the next message into the code.

JUST TELL CASSIE OR ANNA
YOU WERE IN THE SAME CLASS IN THE FIRST YEAR WERENT YOU
ANYWAYS I DIDNT BOOK CAFE
STUDY AREA WILL DO AS YOU SAID

Yep, this was definitely Dany’s way of inviting them to the party. Cassie nudged Phil and showed him the results she had copied into a document. She also typed in “don’t tell Jake, it’s about his birthday party,” under it very quickly. He understood. She nudged Lex and showed him the document. He nodded. Anna was staring at her laptop, so there was no way to get the message to her without alerting Jake.

Phil took a look at her code quickly. Then he stopped the decoding program he was running and started creating a program to do the ciphering. It took him some time. He was in the middle of this when Jake looked up.

“Any results yet?”

Cassie quickly collapsed the run panel on her IDE so that Jake wouldn’t be able to see the decoded answer, even if he walked over and looked at her screen.

“Not yet, but we might be getting warmer,” said Lex, “this might take a bit of time.”

“So, what cipher is it?” asked Jake.

“Playfair, probably,” said Cassie, quickly, “that seems statistically likely.”

“So are we looking at a long solving time?” asked Jake.

“Yeah, there’s a lot of possibilities, in the tens of thousands if my maths is correct,” said Phil, “I need to concentrate.”

“Okay,” said Jake. He returned to his phone.

Meanwhile, Cassie looked up Jake’s birthday. It was the next day. Well done, Dany, she thought, well done.

Cassie watched as Phil typed in the code as fast as he could. Cassie had some idea about what Phil would do. He was trying to write a reply to Dany.

It took him a few tries to get it to compile without errors, and two more tries to generate a proper message that Cassie could decode. Finally, he generated a message and sent it to Cassie.

d2783b90471d752cd54cfe32cd7b5b4690a56d39bd48a12e56166e8bc44ead2aa39c992c32966fc5e6ae8638c54d0848c88f47b37c2adc431e01
1dcaf1909e5da00de12c5435950d179d298b1496dc0031a6c366692b441a5c9794af8919fb050ab6aecbf7a904368fcc

Cassie decoded it.

GOT THE MESSAGE WILL BE THERE
PHIL CASSIE ANNA AND LEX

Cassie nodded. So did Lex.

Phil sent the ciphered message to Dany.

Lex stretched like a cat.

“Look, this is going to take a while,” he said, “wouldn’t it be better if Phil ran this overnight?”
“Good point,” said Phil, quickly.

Anna looked up.

“You sure it’s Playfair?”

“Pretty sure,” said Cassie,

“Okay, let’s meet again tomorrow then,” said Anna, “Jake?”

“Yeah, let’s do that.”

They all went their separate ways after that. Phil messaged her afterwards with a ciphered message from Dany. She checked it. It was Dany simply confirming it. She was about to reply when Phil sent another message saying he decoded it already.

The next day, Cassie showed up at study area on time. Dany had informed them that she’d bring Jake along after all. Phil had managed to keep Jake at bay by telling him that they had to consider another alphabet for Playfair and that they were all working on it remotely.

That was how they managed to surprise Jake completely.

After they cut the cake and had a bit of a party, Dany finally came clean about the cipher.

“So wait, you were using it to plan a birthday party?”

“Affirmative,” said Dany, “and I used it to send a message to them as well.”

“You were in the know the whole time?” asked Jake.

“Nah, we cracked it, realised what was going on, and messaged her.”

“So, when did you really crack it?” asked Jake.

“Yesterday,” said Phil, “when Cassie said she was sure it was Playfair.”

“And you’ve all been lying to me since then? And I had no idea?”

“Basically,” said Lex, “Hey, it was for a good cause.”

“Show me the messages.”

Cassie showed him the translations. Jake read the messages over and over a few times.

“How did you know it wasn’t a kidnapping?” he asked.

Cassie rolled her eyes. “First, the sender, Dany, doesn’t have the social skills to organise a kidnapping, no offense, Dany. Secondly, that’s an incredibly insecure cipher for one, and thirdly, no kidnapper would basically send us an invitation to the same place, and fourth, I remembered your birthday was on the day we had our end-term party last year. Is that a satisfactory explanation?”

Jake pinched the bridge of his nose and shook his head. He was clearly trying to not laugh. 

“Yes, it is satisfactory, unless someone was planning to kidnap all of us.”

“From within the university where everyone is recorded at the entrance?” asked Dany.

“Good point,” said Jake, “So, have I introduced two groups of cipher nuts to each other?”

Cassie looked at Dany, and Dany looked at Cassie. Dany nodded.

“Yup,” said Cassie.


------------------------THE END ------------------------



Read previous chapters: chapter 1  | chapter 2 | chapter 3

Thank you for reading! I hope you found this interesting.

Next week will be the code for this cipher, for enciphering and deciphering. Stay tuned for that.

The week after that, Cassie and co will tackle a real crime. Stay tuned for that!


You can also follow me on Facebook here.

Until next time!

Monday, 4 April 2022

The Cipher - chapter 3 (short story)

chapter 1  | chapter 2chapter 4

Cassie decided to sleep on the problem. She knew that helped with some problems, particularly when she was stuck on assignments. Her dreams that night were filled with hexadecimal numbers and all sorts of ciphers, but she slept well regardless.

She spent the morning doing other stuff. After all, Phil wasn’t going to be up until midday anyway, and they didn’t have lectures that week. They had one coursework presentation, and then next week, they’d be free to leave the campus.

She had lunch and watched some stuff just because. She was halfway through it when her phone rang. It was Jake, who wanted to meet in the study area for a cipher cracking session. He promised snacks, and Phil had agreed to come. Cassie had no objections to that.

She joined the others there. Phil’s ridiculously powerful laptop was running, and currently, it sounded a bit like a hairdryer. He looked up when he saw Cassie.

“No results so far. How about you?”

“Same. Any new leads?”

“Nope.”

Cassie put her laptop bag on the table. “I’ve been thinking, like, should we change our approach?”

Phil gave her a quizzical look. Cassie took it as an invitation to continue.

“Well, how would you encipher something if you wanted to communicate with someone in secret?”

Phil thought for a second. “I’d use a proper cipher algorithm.”

“No, if you couldn’t do that?”

“Why would that be difficult? Vigenere with an easy to remember, ridiculously long key,” he replied, “Do you know it’s theoretically unbreakable if the key is as long as the message?”

True, and if that was the case, there was no way they were breaking it. Cassie turned to Jake.

“What about you?”

“I’d type it in windings.”

“Forget I asked. Anna?”

“Same? Or maybe A=1, B=2, and so on. That’ll be easy to break though.”

“It’s extremely easy,” said Cassie, “seriously, guys, can’t any of you think of an original approach?”

“Maybe if given time,” said Phil, “all that’s required for a cipher to work is that it takes some texts and spits out unintelligible text at the other end, which can be translated to the original text at the receiving end. Ideally, you wouldn’t lose any information in the process. Or introduce ambiguity because languages are a mess as is”

Cassie nodded. “But additional information would be okay.”

“Absolutely,” said Phil, “but it’ll be wasteful.”

“Wouldn’t be a problem if you’re not putting it on the internet, or dealing with large volumes,” said Cassie.

Phil nodded. “So you’re saying this cipher might be a bit wasteful.”

“I’m just considering possibilities.”

“Like skip codes?” asked Anna, “what if you ciphered a skip code the traditional way?”

“Yep, that could work,” said Phil, “I’ll try that on the text we translated the way Cassie suggested.”

“Assignments?”

Everyone turned. It was Lex, a fourth year.

Jake told him what was going on. He immediately volunteered to help. He, too, sat down with his computer, which he had with him for some reason.

“The skip code idea has some merit,” said Lex, “but it’s a bit basic, don’t you think?”

“Hey, not everyone remembers resistor codes, let alone using them for a random cipher,” retorted Cassie.

“Look, I detest econ with my entire being. I simply wanted some sense of normalcy, hence I defaulted to what I liked, what I was comfortable with, and did not include weird interest calculations…”

“So you’re saying we need to find what Dany likes?” asked Anne.

“Easy,” said Jake, “she reads / watches a lot of mystery-related stuff. She is also absolutely obsessed with fantasy as a genre. She loves programming and solving silly little problems that most people would do with pen and paper. She is very good at maths and enjoys it. She is organised in a chaotic way. She has also developed an obsession with fermented food recently for some reason and I think I’m catching it too. I think that’s it.”

“Fermented food?” asked Anna.

“Yeah, that’s the least relevant thing, let’s focus on that,” said Lex, “though seriously, liking maths and programming for the hell of it sounds more relevant to me. This suggests something simple but effective. Such as a Vigenere cipher.”

“Exactly, thank you!” said Phil, “we’re not going to crack this.”

Cassie rolled her eyes. She turned to Jake. “You said she’s weirdly happy about this situation. What sort of happy is she?”

Jake shot her a blank look.

“Is she the evil-I-have-fooled-you happy or is she just super giggly?”

“Well, she has been giggling a lot and I haven’t seen an evil witch look on her, so…”

“That means we can break this! Don’t you see? She wants us to break it,” said Cassie, “that means it’s a breakable cipher, or at least she thinks it is, which is not always the same thing, there was this once time….”

“Alright, so you’re saying it’s not Vigenere?” asked Phil.

“No, I’m saying it’s breakable even if it is Vigenere,” said Cassie.

“Alright, I’ll try that next,” said Phil, “once this is done trying what it’s trying right now. No results so far though.”

Cassie looked at the numbers again. It was a groups of four. Then another idea struck her.

“What if it’s Playfair, but converted to hex and she’s added a random multiple of 26 on top to fool us? That would definitely work.”

“Actually, that would,” said Phil, “but we’ll have research about breaking a Playfair cipher then.”

“Why 26?” asked Anna, “why are you assuming it’s just letters? She could have added numbers and spaces and special characters and all of that.”

“Normally you’d replace spaces with an Z before you cipher it,” said Lex, “and you’d avoid special characters and spell out any numbers.”

“But what if she didn’t?” asked Cassie, “how obsessed is she with ciphers, Jake?”

“Based on other people in my life, about average, I guess?”

“So she likely knows about that trick,” said Lex, “and she’d use it unless she plans to talk about pizza a lot….”

"She does like pizza," said Jake.

“You could replace it with an X,” Cassie pointed out.

“True,” said Anna, “but what if she chose not to? If she added just space, it’s going to be 27 characters. If it’s upper and lower case letters, it’s 52, plus space, it’s 53. If you add numbers, it’s 62 or 63. I think we should try all of that.”

“Easy enough,” said Phil, “so, did you guys do any programming?”

“A bit of micro c, python, java…” started Cassie.

“Perfect. Can I burrow your computer? I’ll just code that quickly.”

“Sure.”

“Dark mode IDE. I see you are a woman of culture, Cassie.”

Cassie bit back a retort. Sure, she didn’t have a good sleep schedule, but she didn't think Phil could look at a light mode anything for more than ten minutes at this point.

Phil produced the first output in a few minutes.

“This is A-Z plus space.”

KZA LSEX OUGWFZTJIMPUURQORDXMGP LBLUHMRRKZRXGAISMPTAEWTABGEAXDAMFWUSXPILI AENNPODYVLF MOSXPZBZTAAHCCKQASZGQNUVPZCBOMVLWQGIUVZTJRBCWTROASHTTXFWLGSBBHVKRBNLSXFPYUYCBI PIUPLUPEOLPBSZQYCFGHNXVCCOMFCSRTUTHNGOUVKFMAEEWBRYRUTYHDEP UC

“This doesn’t make a lot of sense,” said Lex.

Phil was typing away furiously.

“And this is with upper and lower case, no spaces.”

QffgNYjZgrzjWLZyJlOqYvRWSwJEvGRauFmampVsQAyyGbMUrsuCGxAGBllCfFdpLaxUyTnsKgdlooqtieAmiaQOWbqZgGVfIHIhtrhSAjYqvVudIiQrAqevGIaXAXRVcdxTXSAWPZTAFYoItHimdKsiuovZLRYxFIcIHunaTNxqGQqPcWbvDdmImNdXGhUMoItRZUALVjOxCMLMfEfzeyaRaZDiehVFxd

“That’s objectively worse,” said Lex.

“And this is with upper and lower case and space.”

NcddMVhYdqxiWIZwJkNqWvRTQuGArGQaqDmXkoTsN vyGbKTpruBFxxDBjiBbEcoIYwTyRlpJdciooqrgbymhaOOUZqZeCUdEHFfpreS iUpvVsbFfPpyoatGIXW VNTcdxTUQAULWTzFXnHtEfkZKsfrnuYIQYwBFcIDslXRMwqFPoPcUatAdjHkNaWEfRMkFtRWUxJRiOwzLIMdEfydvZRXWAiegSCwd

“And this is with numbers.”

u9J C2NO gdYWpZcJaDqCvR07anXDGGaCum4Qe su0RyGb1JVhu26xTkBPE2y5SepEmJy8RL  SEooqXM8emXa5OAFqZKZKJbHmLBrAS0YrfvVYHmBFVeUxZGI4M0Bk cdxT17AAi3TpFNd8tlBQwKsBNdkOpGYmYmcIaYR48Cmq6FUPcAQZhdF8QN7MvLyM7mtR3UT0oYOmVBpMJEfoTRPR43hieWzjmd

“None of them make sense,” said Lex.

“Well, something has to,” said Cassie, “Unless this is a convoluted ploy by Dany distract you, Jake.”

“Why?”

Was it a significant day to the two of them? Say, the day they met each other? Not according to what Cassie could remember, unless they were already dating before they joined the university. That was unlikely as their nationalities were different. What about Jake’s birthday? That was possible. She remembered going out for a term end / birthday party last year, so that was entirely possible. But then, Jake should have realised that.

“You can figure out if that’s the case,” said Cassie, “unless you have any other pertinent information that may help us…”

“Seriously, does anyone have any ideas?” asked Lex.

“Snack break talking about something else?” asked Anna, quickly, “like which movie we are watching on Friday?”

That made sense. The group decided to have a snack break. As promised, Jake bought snacks. Phil’s laptop still sounded like it was preparing for take-off. They spent a few minutes chatting about other stuff.


END OF CHAPTER THREE

Read previous chapters: chapter 1  | chapter 2 
Next chapter: chapter 4

Thank you for reading! Do let me know if you manage to crack the cipher. It doesn't need a key, and the stuff they've figured out so far might give you a few clues. (hint: it's straightforward, but not a common cipher algorithm).

You can read more about the Vigenere Cipher here if you're interested. The cipher in question here is not a Vigenere Cipher though.

The next chapter will be uploaded next Monday, 11th April.


You can also follow me on Facebook here.

Until next time!


How to write a character who is smarter than you

We all have that one character (or few) who is significantly smarter than the writer. So, as a writer, how do you write such a character con...