• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ThinkingsHard

Beale Cipher

6 posts in this topic

I'm having trouble getting the Beale Cipher to work. For anyone unfamiliar, it's basically the ceasar cipher, only a bit cooler.

 

 

 

Take the decrypted message from the first cryptogram, and  have it be the key to solving the next cipher. How this cipher works

0123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (These values can be anything that you really want, I set a to zero instead of

abcde fgh i j    k   l    m  n   o  p    q   r   s    t   u    v   w  x   y  z    1 just for the hell of it)

Key:                “STRINGOFWORDSSTRINGOFWORDSSTRINGOFWORDS...”

Message         “THEPROBLEMISNOTTHEPROBLEMTHEPROBLEMISYOURATTITUDEABOUTTHEPROBLEM,DOYOUUNDERSTAND”

Encryption:  S = 18. S applies to the T of the first letter of the message. Shift T 18 letters

T becomes L

“LAVXFU…”

 

I have two problems. Right now, it's not properly encrypting. And the second problem, is, as you can see, the key isn't always going to be the same length of the message, but I'm failing to think of a loop that will take the key message, and continue to add it onto itsself until it reaches the length of the message you want to encrypt.

	public void encrypt2(String str, String key)
	{
		/*for(int z = 0;  z < str.length(); z++)
		{
			char kCh = key.charAt(z);
			key += kCh;
		}*/	

		for(int i= 0; i < str.length(); i++)
		{	
			// the Character in the string
			char baelleCh = str.charAt(i);

			for(int k=0; k < key.length(); k++)
			{
				// The character in the key
				char ch = key.charAt(i);
				// if the character in the key is a space
				if(ch == ' ')
				{
					// crypted  = the character
					char crypted = ch;
					cryptedString2 += crypted; // the character is added onto the string
				}
				
				else if(ch == 'a')
				{			
					shift = 0; // shift is nothing
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a'); // crypted is set to the character in the string minus value of a, plus the shift
					cryptedString2 += crypted;								   // mod 26 for the alphabet, plus the value of a
				}
				else if(ch == 'b')
				{			
					shift = 1;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'c')
				{			
					shift = 2;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'd')
				{			
					shift = 3;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'e')
				{			
					shift = 4;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'f')
				{			
					shift = 5;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'g')
				{			
					shift = 6;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'h')
				{			
					shift = 7;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'i')
				{			
					shift = 8;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'j')
				{			
					shift = 9;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'k')
				{			
					shift = 10;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'l')
				{			
					shift = 11;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'm')
				{			
					shift = 12;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'n')
				{			
					shift = 13;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'o')
				{			
					shift = 14;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'p')
				{			
					shift = 15;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'q')
				{			
					shift = 16;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'r')
				{			
					shift = 17;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 's')
				{			
					shift = 18;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 't')
				{			
					shift = 19;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'u')
				{			
					shift = 20;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'v')
				{			
					shift = 21;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'w')
				{			
					shift = 22;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'x')
				{			
					shift = 23;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'y')
				{			
					shift = 24;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else if(ch == 'z')
				{			
					shift = 25;
					char crypted = (char) (((baelleCh -'a') + shift)%26 +'a');
					cryptedString2 += crypted;
				}
				else
				{
					System.out.println("Bug; did not reach a letter");
				}
			}

		}
	}

I will be available to answer any questions in regards to this through this post or private message. I'm hoping to have this completed ASAP as it's what I'm working on for my final project this semester.

0

Share this post


Link to post
Share on other sites
You should never have repetitive chunks of code like that. This is how I would do it in C++ (although it should be easy to port to Java, since I am not using anything special about C++):
#include <iostream>
#include <string>

std::string key = "STRINGOFWORDS";
std::string message = "THEPROBLEMISNOTTHEPROBLEMTHEPROBLEMISYOURATTITUDEABOUTTHEPROBLEMDOYOUUNDERSTAND";

int main() {
  for (int i = 0, end = message.length(); i != end; ++i) {
    char encoding = 'A' + ((message[i] - 'A' + key[i % key.length()] - 'A') % 26);
    std::cout << encoding;
  }
  std::cout << '\n';
}
0

Share this post


Link to post
Share on other sites

Attempting to convert that over to Java.

 

It keeps getting annoyed saying key needs to be an int.

for (int i = 0; i <  str.length();  i++) 
   {
	char baelleCh = str.charAt(i);
	char ch = key.charAt(i);
			                            
        char encoding = (char)('A' + baelleCh - 'A' + key(i % key.length()) - 'A') % 26);
        cryptedString2 += encoding;
   }
0

Share this post


Link to post
Share on other sites

Attempting to convert that over to Java.

 

It keeps getting annoyed saying key needs to be an int.

for (int i = 0; i <  str.length();  i++) 
   {
	char baelleCh = str.charAt(i);
	char ch = key.charAt(i);
			                            
        char encoding = (char)('A' + baelleCh - 'A' + key(i % key.length()) - 'A') % 26);
        cryptedString2 += encoding;
   }

 

"key(i % key.length())" doesn't make sense as far as the java compiler is concerned.

 

Try to take a look at that line in Alvaro's version and see what's going on.

 

First, you get the appropriate index into the key.  That's "key[i % key.length()].  The % is used to loop if the message is longer than the key.

 

Then, subtract 'A' (or 'a' depending on your case) from it.  That gets you the offset from 0.  Do this to the message character as well.

 

Then, sum them and mod 26 to get the appropriate encrypted character.

 

Finally, add your appropriate base ('A' or 'a') back in, and voila, you have your string.

 

In fact, whether you're using C++ or Java, that line should be exactly the same, parentheses and all, except for maybe a cast at the very end.

Edited by SeraphLance
1

Share this post


Link to post
Share on other sites
	public void encrypt2(String str, String key)
	{
		
		for (int i = 0; i <  str.length();  i++) 
			{
			
			char baelleCh = str.charAt(i);
			char ch = key.charAt(i % key.length());
			
			if(baelleCh == ' ')
			{
				cryptedString2 += baelleCh;	
			}
			
		    char encoding = (char) (((baelleCh - 'a') + (ch - 'a')) % 26 + 'a');
		    cryptedString2 += encoding;
			}

It works now, the only problem is, it adds characters like \ and _. Is there a way to make it not have these when it's encrypting the string? I can't really think of anything that would remove them without messing with the encryption. editting this to add that If I change it to

 

 char encoding = (char) (((baelleCh - 'a') + (Character.getNumericValue(ch)%26 + 'a')) % 26 + 'a');

 

I get a neater string with no odd symbols, however I then run into a problem of, I'm having it not align the words properly. There are spaces, and it's spaced out and looks nice, however there is a 3 letter encrypted string where a 2 letter string should be, same for a 4 and a few 6's. It's quite strange. I'm not sure why.

Edited by ThinkingsHard
0

Share this post


Link to post
Share on other sites

I'm not sure why you're getting those symbols in the cyphertext.  Is it coming from capital letters?  Your cypher assumes everything is lowercase (as Alvaro's assumes everything is uppercase).  If you want to handle both cases you need some extra logic.

 

As for your new problem, can you give an example?

0

Share this post


Link to post
Share on other sites

I fixed it by using this code

	public  void encrypt2(String str, String key)
	{

		for (int i = 0; i <  str.length();  i++) 
		{
			char baelleCh = str.charAt(i);
			char ch = key.charAt(i % key.length());
			// allows spaces
			if(baelleCh == ' ')
			{
				cryptedString2 += baelleCh;    
			}
			else
			{		
				// like the Ceasar Cipher, takes the char in the string, minus 'a' plus the numerical value of the character of the key, mod 26, plus 'a'
				char encoding = (char) (((baelleCh - 'a') + (ch-'a')) % 26 + 'a');
				cryptedString2 += encoding;
			}
		}
	}
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0