• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Search | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

Java basic encryption question

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Cryptographic Theory and Cryptanalysis - Internal and Transmission Security

View previous topic :: View next topic  
Author Message
alphaenyx
Just Arrived
Just Arrived


Joined: 20 Oct 2009
Posts: 0


Offline

PostPosted: Tue Oct 20, 2009 10:35 pm    Post subject: Java basic encryption question Reply with quote

Just had a question, made my own encryption(really,really simple) that scrambles the characters in a string of text based upon a numerical key.
It isn't anything fancy, but I was just wondering how would this be reverse engineered without a key.
Code:

import java.util.Scanner;

public class encrypt
{
   public static void main(String[]args)
   {
      Scanner keyb = new Scanner(System.in);

      String input = keyb.nextLine();
      int key = keyb.nextInt();

      String inputencrypt = encrypt(input,key);
      System.out.println(inputencrypt);

      String inputdecrypt = decrypt(inputencrypt,key);
      System.out.println(inputdecrypt);
   }
   public static char[] stringtochararray(String a)
   {
      char[] chararray = new char[a.length()];

      for (int i = 0;i < a.length();i++)
      {
         char c = a.charAt(i);
         chararray[i] = c;
      }
      return chararray;
   }
   public static String encrypt(String a,int key)
   {
      char[] chray = stringtochararray(a);

      for(int k=1;k<=(a.length()-1);k++)
      {
         char buff = chray[k];
         chray[k] = chray[key%k];   
         chray[key%k] = buff;
      }
      String enc = new String(chray);
      return enc;
   }
   public static String decrypt(String a,int key)
   {
      char[] chray = stringtochararray(a);

      for(int k=(a.length()-1);k>=1;k--)
      {
         char buff = chray[key%k];
         chray[key%k] = chray[k];
         chray[k] = buff;
      }
      String dec = new String(chray);
      return dec;
   }
}

Just made this in an hour or so, so i apologize for the short hand variables.
Sorry if this thread should be somewhere else.
Back to top
View user's profile Send private message
Mantralord
Just Arrived
Just Arrived


Joined: 24 Mar 2008
Posts: 0


Offline

PostPosted: Wed Oct 28, 2009 9:33 am    Post subject: Reply with quote

You implemented a transposition cipher.

By modern standards those are very insecure; they're vulnerable to many attacks.
Back to top
View user's profile Send private message
alphaenyx
Just Arrived
Just Arrived


Joined: 20 Oct 2009
Posts: 0


Offline

PostPosted: Wed Oct 28, 2009 6:12 pm    Post subject: Reply with quote

Yes but without knowing the key would this not be impossible to reverse?
I was just looking at simulated annealing, but it seems kina confusing.
Back to top
View user's profile Send private message
Mantralord
Just Arrived
Just Arrived


Joined: 24 Mar 2008
Posts: 0


Offline

PostPosted: Thu Oct 29, 2009 4:43 am    Post subject: Reply with quote

Well, as long as you know where one letter should be in the plaintext and where it ended up after encryption, you can deduce the key. An easy example is maybe encrypting an url, you know that likely it will contain only one ':' character, 5 characters into the plaintext (ex. "http://"). You can figure out what modulus was used to get it transposed by analyzing the encrypted text, and subsequently decrypt the rest of the url.
Back to top
View user's profile Send private message
alphaenyx
Just Arrived
Just Arrived


Joined: 20 Oct 2009
Posts: 0


Offline

PostPosted: Thu Oct 29, 2009 7:41 am    Post subject: Reply with quote

That makes sense thanks, but if you knew nothing about the plaintext would it still be possible?
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Cryptographic Theory and Cryptanalysis - Internal and Transmission Security All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Community Area

Log in | Register