Important alert: (current site time 7/15/2013 3:40:57 PM EDT)
 

VB icon

AP Project Encryption

Email
Submitted on: 3/15/2005 4:16:17 PM
By: Carl S. Finch 
Level: Beginner
User Rating: By 1 Users
Compatibility: Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.4), Java (JDK 1.5)
Views: 10594
(About the author)
 
     Could some programmer please give me a few pointers on what I am doin wrong? I am currently working on a encryptor/decryptor that is also suppose to open/save files as they are encrypted/decrypted from my program. Could some one please lead me to the right direction?
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: AP Project Encryption
// Description:Could some programmer please give me a few pointers on what I am doin wrong? I am currently working on a encryptor/decryptor that is also suppose to open/save files as they are encrypted/decrypted from my program. Could some one please lead me to the right direction?
// By: Carl S. Finch
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4709&lngWId=2//for details.//**************************************

/********************************Encryption, and how it works****************************
/*Programmer: Carl Finch
/*Date: 03/14/05
/*Machine: Fedora Core 3, 2.0GHZ, 256MB DDR, 160GB HD.
/****************************************************************************************
/*******************************Note's that might be important***************************
/*Array's I have string arrays, textarea array of 2, and integer arrays. mostly to create
/*the program faster, and save space if that's possible.
/****************What it all means
/*String arrays Code[0] - Code[2].
/*Code[0] = the string we initally set, and one in which you can change.
/*Code[1] - Code[2] = Serves the purposes of findng what is in the string array of 0 element
/*and store that back in to Code[1], and add that to the second textarea. Tried with only two strings,
/*but couldn't get it to work for some reason.
/*Encrypt button only used to press find what's integer value is in the txtcode, and creates equation
/*set's that equation to the code[1] string, as all characters by using the charAt.
/*the Encryption arrays of Encryption[0] - Encryption[2] are just random variables I created for
/*the modulus at the end of the equation...
/*********************************************************************************************
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.lang.*;
public class encryptonite extends JFrame implements ActionListener
{
JFileChooser MyFile = new JFileChooser();
private String[] Code = new String[3];
private JScrollPane JS1 = new JScrollPane();
private JTextArea[] Write = new JTextArea[2];
private JLabel lblSearch = new JLabel("File Name: ");
private JTextField txtBrowse = new JTextField(10);
private JButton Browse = new JButton("Browse");
private JButton Encrypt = new JButton("Encrypt it");
private JButton Decrypt = new JButton("Decrypt it");
private JTextField txtCode = new JTextField(10);
private int[] Encryption = new int[4];
JPanel Top = new JPanel();
public encryptonite()
{ 
super("Encryptonite - created by: Carl Finch");
setSize(400,400);
Top.add(lblSearch);
Top.add(txtBrowse);
Top.add(Browse);
Top.setLayout(new GridLayout(2,1));
//--- Create scrolling text area using JScrollPane.
Write[1] = new JTextArea("", 15,30);
Code[0] = "This is the Caesar Cipher encryption";
Write[0] = new JTextArea(Code[0],15,30);
JScrollPane scrollingResult2 = new JScrollPane(Write[1]);
JScrollPane scrollingResult = new JScrollPane(Write[0]);
Encryption[1]=(int)(1+(Math.random()*(Math.pow((Math.random()*256),2))));
txtCode.setText("###");
Encrypt.addActionListener(this);
Decrypt.addActionListener(this);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(Top);
c.add(scrollingResult);
c.add(Decrypt);
c.add(Encrypt);
c.add(txtCode);
c.add(scrollingResult2);
c.setSize(400,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Encrypt)
{
Code[1]="";
Code[2]=Write[0].getText();
for(int i=0; i<Code[2].length(); i++)
{
Encryption[3]=(int)(Code[2].charAt(i))+1;
if(Encryption[3]>126)
{
Encryption[3]=Encryption[3]-95;
 }
 Code[1]=Code[1]+(char)Encryption[3];
 Code[1] = Code[1] + (char)((Code[2].charAt(i)+Integer.parseInt((txtCode.getText()))) % 256);
 Write[1].setText(Code[1]);
}
}
if(e.getSource() == Decrypt)
{
Code[1]="";
Code[2]=Write[1].getText();
for(int i=0; i<Code[2].length(); i++)
{
Encryption[3]=(int)(Code[2].charAt(i))-1;
if(Encryption[3]<32)
{
Encryption[3]=Encryption[3]+95;
}
Code[1]=Code[1]+(char)Encryption[3];
Code[1] = Code[1]+(char)((Code[2].charAt(i)+Integer.parseInt((txtCode.getText())))%256);
Write[0].setText(Code[1]);
}
}
}
//create random number generator.
public void random()
{
Encryption[0]=2;
Encryption[2]=(int)(Math.pow(Encryption[0],Encryption[1])*(1+(Math.random()*Encryption[2])));
}
//Add createframe, setsize, and color.
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(false);
encryptonite framelook = new encryptonite();
framelook.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
framelook.setVisible(true);
framelook.setBackground(Color.white);
framelook.setForeground(Color.red);
}
}


Other 8 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
5/14/2005 2:22:34 PM

First off, set the "Write[1].setText(Code[1])" outside of the for loop since it only needs to print once the way you have it. That will fix the out of memory error you were probably getting. The lines "Code[1]=Code[1]+(char)Encryption[3];" and "Code[1] = Code[1]+(char)((Code[2].charAt(i)+Integer.parseInt((txtCode.getText())))%256);" are the main culprits. The way the program logic goes, you are taking the modified character (the +1 and the -95 logic right above the lines i just mentioned) and assigning it to the output string instead of a temp variable. Then you modulus the character the user originally typed (instead of the one you just modified) and added that to the output string. Also, name your variables according to their purpose, ie stringLength is much easier to figure out than Encryption[7]. Hope this helps ya. Happy coding!
(If this comment was disrespectful, please report it.)

 
2/9/2007 10:07:19 AMRajkumar

excellant
(If this comment was disrespectful, please report it.)

 
2/18/2011 1:44:12 AMramanujam

i need RSA code in java
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.