Important alert: (current site time 7/15/2013 3:41:52 PM EDT)
 

VB icon

CODER AND DE-CODER

Email
Submitted on: 5/11/2006 8:43:10 AM
By: Suyash Bhatt  
Level: Intermediate
User Rating: By 2 Users
Compatibility: Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 5340
(About the author)
 
     This code is written for the main purpose of security. It can code a sentence to an other string for some specific number and can be de coded back only if the coded form along with the secret number are entered.
 
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: CODER AND DE-CODER
// Description:This code is written for the main purpose of security. It can code a sentence to an other string for some specific number and can be de coded back only if the coded form along with the secret number are entered.
// By: Suyash Bhatt
//
// Inputs:1-) name of the string to be coded or decoded, according to the user.
2-) Secret number for coding
3-) user friendly therefor continue or not....
//
// Returns:coded or decoded form of the given string.
//
// Assumes:Its totally a user friendly progrm so user don't need to know anything except running the program.
//
// Side Effects:enter a lesser secret value....
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=5277&lngWId=2//for details.//**************************************

import java.io.* ;
import java.lang.* ;
class testy
{
public String coding (String s2, int num2)
{
String cod="" ;
String s1=s2 ;
int num1=num2 ;
int len=s1.length () ;
int arr[] = new int [len] ;
int check=2 ;
for (int c=0; c<len; c++ ) 
{
char ch=s1.charAt(c) ;
arr[c]=(int)ch;
}
for(int c1=0 ; c1<len; c1++ )
{
if (arr[c1]<=(127-num1)) 
arr[c1]=arr[c1]+num1 ;
else
if (arr[c1]>(127-num1))
{
System.out.println (" THE CODING IS NOT POSSIBLE FOR THIS NUMBER...... ") ;
System.out.println (" PLEASE ENTER A LOWER NUMBER . ") ;
System.out.println (".............................") ;
System.out.println (".............................") ;
System.out.println () ;
System.out.println () ;
check=5 ;
break ;
}
}
if (check==2)
{
System.out.println () ;
for (int c2=0; c2<len; c2++) 
{
cod=cod+(char)arr[c2] ;
}
}
return cod ;
}
public String decoding (String s2, int num2)
{
String decod="" ;
String s1=s2 ;
int num1=num2 ;
int len=s1.length () ;
int arr[] = new int [len] ;
for (int c=0; c<len; c++ ) 
{
char ch=s1.charAt(c) ;
arr[c]=(int)ch;
}
for(int c1=0 ; c1<len; c1++ )
{
arr[c1]=arr[c1]-num1 ;
}
System.out.println () ;
for (int c2=0; c2<len; c2++) 
{decod=decod+(char)arr[c2] ;
}
return decod ;
}
public static void main (String args []) throws IOException
{
int chf=0 ;
do
{
InputStreamReader isr = new InputStreamReader (System.in) ;
BufferedReader d= new BufferedReader (isr) ;
System.out.println(" CODING OR DECODING ? for coding press 1 and for decoding press 2 ") ;
int choice = Integer.parseInt (d.readLine () ) ;
testy obj=new testy () ;
if (choice==1)
{
String cod="" ;
System.out.println ("ENTER THE STRING TO BE CODED ") ;
String codingstring=d.readLine () ;
String s1= codingstring ; 
System.out.println (" Enter the secret number between 0 and 10 for coding ") ;
int num1=Integer.parseInt (d.readLine ()) ;
String finaly=obj.coding (s1,num1) ;
if (finaly.length ()>0)
System.out.println ("the coded String is :- "+finaly);
System.out.println () ;
System.out.println () ;
System.out.println () ;
System.out.println (" DO YOU WANT TO CONTINUE (enter 1 for YES and 2 for NO) :- ") ;
chf=Integer.parseInt(d.readLine ()) ;
}
else 
if (choice==2)
{
System.out.println ("ENTER THE STRING TO BE DE-CODED ") ;
String codingstring=d.readLine () ;
String s1= codingstring ; 
System.out.println (" Enter the secret number between 0 and 10 for decoding ") ;
int num1=Integer.parseInt (d.readLine ()) ;
String finaly=obj.decoding (s1,num1) ;
if (finaly!=null)
System.out.println ("the decoded String is :- "+finaly);
System.out.println () ;
System.out.println () ;
System.out.println () ;
System.out.println (" DO YOU WANT TO CONTINUE (enter 1 for YES and 2 for NO) :- ") ;
chf=Integer.parseInt(d.readLine () ) ;
}
}while (chf==1) ;
}
}


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 Intermediate 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
6/22/2011 9:27:54 AMmahesh

i need some documentation for the above code please send to me
(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.