Jump to content

  • Log In with Google      Sign In   
  • Create Account


ThinkingsHard

Member Since 11 Sep 2012
Offline Last Active Jun 16 2014 04:22 AM
-----

Topics I've Started

Beale Cipher

10 May 2014 - 08:15 PM

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.


JMenu, Listeners, and drawing

09 May 2014 - 08:17 PM


/**
	This frame will display a picture that the user
	selects using radio buttons.

	@author: B.Brenner
	@version:  1/26/10
*/

import java.awt.* ;                 // for FlowLayout and Dimension classes

import javax.swing.*;              // for Swing components

import java.awt.event.* ;        // for ActionListener interface
import javax.swing.BorderFactory;
import javax.swing.border.Border;


@SuppressWarnings("serial")
public class ImageViewerFrame extends JFrame{

	// Instance variables
	String [] descriptions = new String[6];   // 1 description per image
	String [] pictures = new String[6];
	Border loweredbevel = BorderFactory.createLoweredBevelBorder();  // Set up the border
	JPanel headingPanel;
	JPanel controlPanel;
	JLabel pictureLabel;
	JLabel headingLabel;
	JLabel instructionsLabel;
	JTextArea outputTextArea;  // I could have used a label containing HTML to create a multiple row label
	JMenuBar menuBar = new JMenuBar();
	JMenu fileMenu = new JMenu("File");
	JMenu exitMenu = new JMenu("Exit");
	JMenu aboutMenu = new JMenu("About");
	JMenu imageMenu = new JMenu("Images");
	JMenuItem image1 = new JMenuItem("Gregory Lake");
	JMenuItem image2 = new JMenuItem("Devils Post Pile");
	JMenuItem image3 = new JMenuItem("JMT Sign");
	JMenuItem image4 = new JMenuItem("Lonely Tree");
	JMenuItem image5 = new JMenuItem("View From Whitney");
	JMenuItem image6 = new JMenuItem("Lone Pine Lake");
	JMenuItem exit = new JMenuItem("Close");
	String mName ="";

	// constructor
	public ImageViewerFrame(){

		// Helper methods
		loadPictureInformation();
		createHeadingPanel();
		createOutputArea();

		// Create the area where the pictures will be displayed
		pictureLabel = new JLabel();
		pictureLabel.setIcon(new ImageIcon("images/" + pictures[0]));
		pictureLabel.setBorder(loweredbevel);

		// Add the components to the frame
		setLayout(new BorderLayout());
		add(controlPanel, BorderLayout.WEST);
		add(headingPanel, BorderLayout.NORTH);
		add(outputTextArea, BorderLayout.SOUTH);
		add(pictureLabel, BorderLayout.CENTER);
		
		setJMenuBar(menuBar);
		menuBar.add(fileMenu);
		menuBar.add(imageMenu);
		menuBar.add(aboutMenu);
		menuBar.add(exitMenu);
		
		imageMenu.add(image1);
		imageMenu.add(image2);
		imageMenu.add(image3);
		imageMenu.add(image4);
		imageMenu.add(image5);
		imageMenu.add(image6);
		exitMenu.add(exit);
		
	}

	/**
		Loads the arrays with the file name and description for
		each picture.
	*/
	public void loadPictureInformation() {
		// Load the file names for the pictures
		pictures[0] = "Gregory Lake.JPG";
		pictures[1] = "Devils Post Pile.JPG";
		pictures[2] = "JMT Sign.JPG";
		pictures[3] = "Lonely Tree.JPG";
		pictures[4] = "View From Whitney.JPG";
		pictures[5] = "Lone Pine Lake.JPG";

		// Load the descriptions for each picture
		descriptions[0] = "Gregory Lake is located between Yosemite Valley and Reds Meadow pack station on the John Muir Trail in California";
		descriptions[1] = "Devils Post Pile was caused by the glaciers.  It is part of Yosemite National Park, even though is located south of Yosemite.";
		descriptions[2] = "Not all signs on the trail were this nice.  This was a nice reminder about the man that the trail was named for.";
		descriptions[3] = "The tree seems lonely.  It is located approximately 2 days, by foot, before Mt. Whitney.";
		descriptions[4] = "Watching the sun rise from the summit of Mt. Whitney, the highest point in the continental US at 14,500 ft.";
		descriptions[5] = "The view from our last campsite on the John Muir Trail before reaching the end of the 220 mile backpack.";
	}


	/**
		Create the area for the selecting which picture to display
	*/
	public void createMenuPanel()
	{


		// The code needed to react to a radio button being selected
		class MenuListener implements ActionListener 
		{
			
			public void actionPerformed( ActionEvent evt )
			{
				//String menuName = "";
				//menuName = (String) evt.getSource();
				System.out.println("DEBUGGING" + (String) evt.getSource());
			//	mName = menuName;
				
			}
		}
		
		class ExitItemListener implements ActionListener
		{
			public void actionPerformed(ActionEvent event)
			{
				System.exit(0);
			}
		}
		/*
		ImageIcon imageIcon1 = new ImageIcon(pictures[0]);
		Image actualImage1 = imageIcon1.getImage();
		
		ImageIcon imageIcon2 = new ImageIcon(pictures[1]);
		Image actualImage2 = imageIcon2.getImage();
		
		ImageIcon imageIcon3 = new ImageIcon(pictures[2]);
		Image actualImage3 = imageIcon3.getImage();
		
		ImageIcon imageIcon4 = new ImageIcon(pictures[3]);
		Image actualImage4 = imageIcon4.getImage();
		
		ImageIcon imageIcon5 = new ImageIcon(pictures[4]);
		Image actualImage5 = imageIcon5.getImage();
		
		ImageIcon imageIcon6 = new ImageIcon(pictures[5]);
		Image actualImage6 = imageIcon6.getImage();
		*/

		// Register the listener
		ActionListener listener = new MenuListener();
			
			image1.addActionListener(listener);
			image2.addActionListener(listener);
			image3.addActionListener(listener);
			image4.addActionListener(listener);
			image5.addActionListener(listener);
			image6.addActionListener(listener);
		
		
		ActionListener exitListener = new ExitItemListener();
		exit.addActionListener(exitListener);

		// Create the other components
		JPanel myMenuPanel = new JPanel();
		myMenuPanel.setLayout(new GridLayout(0, 1));

		controlPanel = new JPanel();
		controlPanel.setLayout( new GridLayout(0, 1) );
		controlPanel.setBorder(loweredbevel);
	}
	


	/**
		Create the heading area at the top of the window
	*/
	public void createHeadingPanel() {
		headingLabel = new JLabel("<html>Pictures from <br>the John Muir Trail</html>", SwingConstants.CENTER );
		headingLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 24));
		instructionsLabel = new JLabel("Select a picture from the left to view", SwingConstants.CENTER);
		instructionsLabel.setFont(new Font("Comic Sans MS", Font.ITALIC, 18));
		headingPanel = new JPanel();
		headingPanel.setLayout(new GridLayout(0, 1));
		headingPanel.add(headingLabel);
		headingPanel.add(instructionsLabel);
		headingPanel.setBackground(Color.LIGHT_GRAY);
	}

	/**
		Create the output area to display the descriptions of the pictures
	*/
	public void createOutputArea() {
		outputTextArea   = new JTextArea(descriptions[0], 3, 20);   // 3 rows, 50 columns, initially empty
		outputTextArea.setEditable(false);   // make it be read only
		outputTextArea.setLineWrap(true);   // allow it to wrap
		outputTextArea.setWrapStyleWord(true);  // break lines between words
		outputTextArea.setBackground(Color.LIGHT_GRAY);
		outputTextArea.setForeground(Color.BLACK);
		outputTextArea.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
		outputTextArea.setBorder(loweredbevel);
	}
}

/**
	Creates a frame to display pictures in

	@author:  B.Brenner
	@verison:  1/26/2010
*/

import javax.swing.JFrame;

public class ImageViewer {

	/**
		Create a frame for the GUI.  The remainder of the
		program is processed by the GUI.
	*/
	public static void main ( String[] args ){

		// Create the frame and set its properties
		ImageViewerFrame viewerFrame  = new ImageViewerFrame() ;
		viewerFrame.setSize( 580, 510 );
		viewerFrame.setVisible( true );
		viewerFrame.setTitle( "My Image Viewer" );
		viewerFrame.setLocationRelativeTo(null);   // center the frame on the screen
		viewerFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		viewerFrame.setResizable(false);   // don't allow the frame to be resized
	}
}

So, I'm having trouble getting the actionlistener to draw the image when I click the appropriate image, also I've started getting a null pointer exception. I can't figure out what I'd want to put inside my action listener to respond to the JMenuItem to draw the appropriate image.

 


How to cap speed of a moving object

11 April 2014 - 08:46 PM

//package bouncingBoxes;

import java.awt.Point;
import java.awt.Rectangle;

public class MyBox 
{
	private Rectangle box;
	private int dx;
	private int dy;
	private int speed = 1;
	
	
	
	
	private static final int BOX_WIDTH = 20;
	private static final int BOX_HEIGHT = 30;
	// constructor
	public MyBox(Rectangle box, int dx, int dy)
	{
		this.box = box;
		this.dx = dx;
		this.dy = dy;
	}
	// sets the vector
	public void setVector(int dx, int dy)
	{
		this.dx = dx;
		this.dy = dy;
	}
	// move the box
	public void move()
	{
		box.translate(dx, dy);
	}
	// moves the box just by the x coordinate
	public void moveX(int x)
	{
		dx = x;
		box.translate(dx, dy);
	}
	
	public void moveY(int y)
	{
		dy = y;
		box.translate(dx, dy);
	}
	
	public Rectangle getBox()
	{
		return box;
	}
	
	// gets the Y coordinate
	public int getDY()
	{
		return dy;
	}
	
	// gets the X coordinate
	public int getDX()
	{
		return dx;
	}

	public Point getNextLocation() 
	{
		//next x position
		int x = (int)box.getX() + dx;
		int y = (int)box.getY() + dy;

		//return the next location
	
		return  new Point(x,y);
	}

	public void bounceY() 
	{
		//swap direction in the y direction
		
		
		dy *= -speed;
		speed++;
		
	
	}

	public void bounceX() 
	{
		// swap direction in the x direction
		dx *= -speed;
		speed++;
	
	}
	
//package bouncingBoxes;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.JComponent;

/**
   This component displays a rectangle that can be moved. 
 */
public class RectangleComponent extends JComponent
{  
	private static final int BOX_WIDTH = 20;
	private static final int BOX_HEIGHT = 30;


	private ArrayList<MyBox> boxes;


	public RectangleComponent()
	{  
		boxes = new ArrayList<MyBox>();
	}

	public void paintComponent(Graphics g)
	{  
		Graphics2D g2 = (Graphics2D) g;

		for(MyBox box: boxes)
		{
			g2.draw( box.getBox() );
		}
	}

	public void addRectangle(int x, int y, int dx, int dy)
	{
		Rectangle rect = new Rectangle(x, y, BOX_WIDTH, BOX_HEIGHT); 

		MyBox box = new MyBox(rect, dx, dy);
		boxes.add(box);

		repaint();
	}


	public void addRectangle(int x, int y)
	{
		Rectangle rect = new Rectangle(x, y, BOX_WIDTH, BOX_HEIGHT); 

		MyBox box = new MyBox(rect, 4, 4);
		boxes.add(box);

		repaint();
	}

	public void updateLocations()
	{
		for(MyBox box: boxes)
		{
			//get bottom after future move
			Point p = box.getNextLocation();
			Rectangle r = box.getBox();


			//if bottom of box will hit bottom of screen ...
			//    or hits off of top
			if( (p.getY() + r.height > this.getHeight() )  ||
					(p.getY() <=0) )
			{
				//switch direction
				box.bounceY();
				
			}
			if( (p.getX() + r.width > this.getWidth())   ||
					(p.getX() <=0) )
			{
				//switch direction
				box.bounceX();
			}

			box.move();
		}

		repaint();
	}

	
	/*
	 * Did not do what I had hoped
	 * keep it here in event that I need it later
	 * public void outOfBounds()
	{
		for(MyBox box: boxes)
		{

			if(box.getDX() > this.getWidth())
			{
				int x = box.getDX() - this.getWidth();
				box.moveX(x);
			}
			
			if(box.getDX() < 0)
			{
				int x = box.getDX();
				box.moveX(-x);
			}
			
			if(box.getDY() > this.getHeight())
			{
				int y = box.getDY() - this.getHeight();
				box.moveY(y);
			}
			
			if(box.getDY() < 0)
			{
				int y = box.getDY();
				box.moveY(-y);
			}
		}
		
	}
	*/
}



I'm trying to get this to work so that the rectangle will bounce off the walls, increasing speed as it bounces, however it will obviously increase so quickly that it will bounce out of the screen eventually. I want to find out when it goes out of bounds, then find the speed it was at when it went out of bounds, and then remove THAT speed by 1, without incrementing speed after it goes out of bounds, allowing it to stay fast, without causing the out of bounds speed again.  I'm kinda burned out from work and classes, and can't think. Anything anyone can do to help, even a bump in the right direction while I continue tot google search would be wonderful. Thank you.


What path to take in programming?

01 April 2014 - 04:15 PM

Hey guys,

 

     So, I'll get right into it. I just talked to my college adviser, and I can complete my degree next semester (Community College). We talked for a good while, and it would be a brutal semester but I could do it. Or I could take two more semesters, and take a few extra classes here or there, and get to know more of what I want to do. Let me bold this for anyone who skims  the biggest problem I'm having is that I do not know what niche in the programming world I want to fill. Do I want to be a game programmer? Maybe, it sounds like fun. Do I want to do mobile apps? Website? Back-end server? Data Analysis? Security? I don't know. And what I decide on, matters. If I decide of mobile apps, he suggested taking the extra semester, and taking a course with him in C# (The main language they teach in the college is Java, for 3 semesters, so that's the only language most of us know who come from there).

    So if anyone has suggestions, or brief layouts of the different niches in the programming world, that would help a lot. I know you might be hesitant to try to suggest anything, because you don't want to push someone into doing something. It's a decision they need to make on their own. I'm just looking for information here, the ups and downs of certain fields, so I can try to plan accordingly.

 

**Edit** It's early and I have to leave for work right now, but it seems I failed to mention that I DO plan on pursuing a Bachelors, and hopefully even a Masters degree in Computer Science. I'm just trying to decide if I should get my Associates a semester early, or take the extra semester, and an extra class or two, before going on to a four year school.**Edit**

 

     Thanks!


Trouble with strings and chars with arrays and loops

14 February 2014 - 08:08 PM

stringLength = x.length();
    String[] beautifulMind = new String[stringLength];
    String bMind = Arrays.toString(beautifulMind);
    bMind = bMind.toLowerCase();
    int[] charCount = new int[25];
    
    for (int i = 0; i < beautifulMind.length; i++)
    {
            if(bMind.charAt(i) = ("a"))
               {
                 charCount[0] = charCount[0]++;
                }
       

That's pretty much all the relevant code. I know bMind.charAt(i) isn't working because it needs a variable, at one point it was telling me invalid for a string and a char. I also had tried something similar to (bMind.charAt(i)).equals("a");  But that didn't work. I'm not sure exactly what would work here. If it isn't completely obvious. I want to take a string, and convert all of it to lower case, and then go through a loop to look at each letter in the sentence separately, and then add that to a count in an array, which I will later use to get statistics on all letters in the string.

 

Thanks.


PARTNERS