Breaking the Vigenère Cipher

The Vigenère cipher is a very known cipher for centuries, you can read more about it from here. It uses a series of Caesar ciphers to encrypt the text. Sometime ago I came across a challenge in breaking the Vigenère cipher. But this was a variant of a Vigenère cipher which uses XOR gate instead of normal polyalphabetic substitution. Here is the encryption program. In a challenge you won’t get the encryption program but however you can code it.

#include <stdio.h>
#define KEY_LENGTH 7 
/*
* Title: Variant of a Vignere Cipher Encrypter
* Author: Osanda Malith Jayathissa
* Website: https://osandamalith.wordpress.com
*/
int main() {

  FILE *fpIn, *fpOut;
  unsigned char ch;
  unsigned char key[KEY_LENGTH] = {0xBA, 0x1F, 0x91, 0xB2, 0x53, 0xCD, 0x3E};

  fpIn = fopen("ptext.txt", "r");
  fpOut = fopen("ctext.txt", "w");

  for (size_t i = 0; fscanf(fpIn, "%c", &ch) != EOF; ++i) 
  if (ch!='\n') fprintf(fpOut, "%02X", ch ^ key[i % KEY_LENGTH]);   

  fclose(fpIn);
  fclose(fpOut);
  
  return 0;
} 

Continue reading

Advertisements