Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Guys!

I found this page some weeks ago and It's just cool how you help each other. I'm from Switzerland and I have a big question/request :)

I wanted to programm an ENIGMA, but only with its three rotors. I know how the rotors work but I don't have any idea how to programm that. I found this ENIGMA in C# on this page and tried to see how he programmed it, but it was way too difficult. Isn't there an easier way to programm the algorithm? In the following minutes or hours I'll put the code I programmed until now.

My goal is to make an Encryptor in C# with my own algorithms. Isn't there a sample which shows you, how you have to start?

Thanks for your attention!
Posted
Comments
Perić Željko 27-Nov-11 10:16am    
As in life, and in programming there is not shortcut,
especially when it comes to the area of ​​encryption.
It is necessary to study thoroughly the theory of cryptography,
then select the type of encryption that works best for you,
create an algorithm, usually in the literature which explains the cryptography exists a pseudo code that can be used for algorithm development, and then make the program in some of the programming languages.
The programs used for cryptography are complicated and most likely You will not find them on the web in the form of open source(they are too expensive), what would then be the purpose of such programs if everyone could see how it works.If you know fully how the program works then you are able to break the code
So you'll have to try and learn computer programming in C#,
or to hire one of Yours friends who already know to program a computer and together realize your goal. Since I had some free time I wrote this small console application in Sharp Develop C# , it should be enough for start.
In the CodeProject under
Learning Zones ,
Solutions Center ,
General Programming,
Cryptograpfy & Security
you have a whole chapter devoted to cryptography. (http://www.codeproject.com/KB/security/)

 
Share this answer
 
v2
Comments
Smithers-Jones 24-Nov-11 5:37am    
Added clickable link.
JoeilG 24-Nov-11 7:01am    
Hello :) Yes, I downloaded the code and wanted to see how the Rotorclass was programmed. But I just don't get it. Isn't there an easier way to programm a rotor, which rotates one letter further, each time you type something in a txtbox? I thought it might be possible with arraylists and some easy functions. Am I wrong? As you can see, I'm not a pro in programming ;)
Hello ,
this is my solution for JoeilG ,
first browse in the CodeProject under
Learning Zones ,
Solutions Center ,
General Programming,
Cryptograpfy & Security
you have a whole chapter devoted to cryptography.

http://www.codeproject.com/KB/security/[^]

Here is sample of code for Encryption of small text messages :

Program.cs

C#
/*
 * Created by Perić Željko
 * periczeljkosmederevo@yahoo.com
 * IDE Sharp Develop C#
 * Date: 28.11.2011
 * Time: 11:20
 * 
 * This is a simple console application for encryption of short
 * text messages (up to 255 caracters).It is based on
 * increasing of generic ASCII code of letters in text messages
 * by value of Rotation_key enterd trough keyboard.
 * 
 * example : Rotation_key = 1
 * 			 Message = ABC (ASCII : 65 , 66 , 67)
 * 			 Encrypted = BCD (ASCII : 66 ,67 , 68)
 * 
 * Since the value of the ASCII code is limited ,
 * so the value of the Rotation_key should be limited
 * it is up to you to find min and max values.
 * When you do that , given key name will be justified.
 * 
 * !!! The program is not final because it has no part to check
 *  	what exactly user had entered on the keyboard
 * 		there should be try...parse...catch part.
 * 		it is up to you.
 * 		It allso can be modifed to load .txt document,
 * 		encrypt text from it and then send it trough mail,
 * 		for example.
 * 		There is only part of program for encryption,
 * 		the other part for decryption you shuld write 
 * 		yourself.Look at this code it should be easy.
 *               You should change only one key charcter in program
 *               for Encryption to become program for Decryption :))
 * !!!
 * 
 * Good luck and happy learning of C#
 * 
 */
 
using System;

namespace Encryption
{
	class Program
	{
		public static void Main(string[] args)
		{
			
			//
			// variables declaration
			//
			string Original_Message = "";
			string Encrypted_Message = "";
			string Original_Message_Letter_String = "";
			string Encrypted_Message_Letter_String = "";
			string Rotation_key_string = "";
			
			char Original_Message_Letter_Char = ' ';
			char Encrypted_Message_Letter_Char = ' ';
			
			int Letter_code = 0;
			int Rotation_key_number = 0;
			int Message_Lenght = 0;
			int Counter = 0;
			
			//
			// Hello to user
			//
			Console.Title = "Encryption program";
			Console.SetWindowSize(80,25);
			Console.Clear();
			Console.ForegroundColor = ConsoleColor.Green;
			Console.WriteLine("-------------------------------------------------");
			Console.WriteLine("    Program for encryption of text messages");
			Console.WriteLine("-------------------------------------------------");
			Console.WriteLine("");
			
			//
			// Get text message from console
			//
			Console.WriteLine("Type your message here :");
			Console.WriteLine("------------------------");
			Original_Message = Console.ReadLine();
			Console.WriteLine("");
			
			//
			// Get value of rotation key from console
			// and transfer it to number
			//
			Console.WriteLine("Value of rotation key :");
			Console.WriteLine("------------------------");
			Rotation_key_string = Console.ReadLine();
			Rotation_key_number = int.Parse(Rotation_key_string);
			Console.WriteLine("------------------------");
			Console.WriteLine("");
			
			//
			// Encrypt message
			//
			Message_Lenght = Original_Message.Length;
			Counter = 0;
			while(Counter < Message_Lenght)
			{
				Original_Message_Letter_String = Original_Message.Substring(Counter,1);
				Original_Message_Letter_Char = char.Parse(Original_Message_Letter_String);
				
				Letter_code = Original_Message_Letter_Char;
				Letter_code = Letter_code + Rotation_key_number;
				
				Encrypted_Message_Letter_Char = (char) Letter_code;
				Encrypted_Message_Letter_String =  Encrypted_Message_Letter_Char.ToString();
				
				Encrypted_Message = Encrypted_Message + Encrypted_Message_Letter_String;
				Counter = Counter + 1;
			}
			
			//
			// Write encrypted message on console
			//
			Console.WriteLine("Encrypted message");
			Console.WriteLine("-------------------------------------------------");
			Console.WriteLine(Encrypted_Message);
			Console.WriteLine("-------------------------------------------------");
			Console.WriteLine("");
			
			//
			// End of program
			//
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
}


Here is sample of code for Decryption of small text messages :

Program.cs

C#
/*
 * Created by Perić Željko
 * periczeljkosmederevo@yahoo.com
 * IDE Sharp Develop C#
 * Date: 28.11.2011
 * Time: 11:20

 * 
 * This is a simple console application for decryption of short
 * text messages (up to 255 caracters) encrypted by program Encryption.
 * Program Encryption is based on
 * increasing of generic ASCII code of letters in text messages
 * by value of Rotation_key enterd trough keyboard.
 * 
 * example : Rotation_key = 1
 *              Original message = ABC (ASCII : 65 , 66 , 67)
 *              Encrypted message = BCD (ASCII : 66 ,67 , 68)
 * 
 * so program decryption works in oposite direction
 * 
 * example : Rotation_key = 1
 *              Encrypted message = BCD (ASCII : 65 , 66 , 67)
 *              Decrypted or Original message= ABC (ASCII : 66 ,67 , 68)
 * 
 * Since the value of the ASCII code is limited ,
 * so the value of the Rotation_key should be limited
 * it is up to you to find min and max values.
 * When you do that , given key name will be justified.
 * 
 * !!! The program is not final because it has no part to check
 *      what exactly user had entered on the keyboard
 *         there should be try...parse...catch part.
 *         it is up to you.
 *         It allso can be modifed to load .txt document,
 *         decrypt text from it and then send it trough mail,
 *         for example.
 *
 * !!!
 * 
 * Good luck and happy learning of C#
 * 
 */

using System;

namespace Decryption
{
	class Program
	{
		public static void Main(string[] args)
		{
		//
            // variables declaration
            //
            string Encrypted_Message = "";
            string Decrypted_Message = "";
            string Encrypted_Message_Letter_String = "";
            string Decrypted_Message_Letter_String = "";
            string Rotation_key_string = "";
            
            char Encrypted_Message_Letter_Char = ' ';
            char Decrypted_Message_Letter_Char = ' ';
            
            int Letter_code = 0;
            int Rotation_key_number = 0;
            int Message_Lenght = 0;
            int Counter = 0;
            
            //
            // Hello to user
            //
            Console.Title = "Decryption program";
            Console.SetWindowSize(80,25);
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine("    Program for decryption of text messages");
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine("");
            
            //
            // Get text message from console
            //
            Console.WriteLine("Type your Encrypted message here :");
            Console.WriteLine("-----------------------------------");
            Encrypted_Message = Console.ReadLine();
            Console.WriteLine("");
            
            //
            // Get value of rotation key from console
            // and transfer it to number
            //
            Console.WriteLine("Value of rotation key :");
            Console.WriteLine("------------------------");
            Rotation_key_string = Console.ReadLine();
            Rotation_key_number = int.Parse(Rotation_key_string);
            Console.WriteLine("------------------------");
            Console.WriteLine("");
            
            //
            // Encrypt message
            //
            Message_Lenght = Encrypted_Message.Length;
            Counter = 0;
            while(Counter < Message_Lenght)
            {
                Encrypted_Message_Letter_String = Encrypted_Message.Substring(Counter,1);
                Encrypted_Message_Letter_Char = char.Parse(Encrypted_Message_Letter_String);
                
                Letter_code = Encrypted_Message_Letter_Char;
                Letter_code = Letter_code - Rotation_key_number;
                
                Decrypted_Message_Letter_Char = (char) Letter_code;
                Decrypted_Message_Letter_String =  Decrypted_Message_Letter_Char.ToString();
                
                Decrypted_Message = Decrypted_Message + Decrypted_Message_Letter_String;
                Counter = Counter + 1;
            }
            
            //
            // Write Decrypted message on console
            //
            Console.WriteLine("Decrypted message - Original text");
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine(Decrypted_Message);
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine("");
            
            //
            // End of program
            //
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}


If you are using IDE SharpDevelop you can find complete solutions for those programs on this adress :

Encryption[^]

All the best,
Perić Željko
 
Share this answer
 
v12
Comments
JoeilG 28-Nov-11 7:41am    
Thank you very much for your solution! Tonight I'll watch through the code to learn more about it. Have a nice day :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900