4 Replies - 13795 Views - Last Post: 28 October 2013 - 01:07 PM

#1 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10196
  • View blog
  • Posts: 37,655
  • Joined: 27-December 08

[Challenge] Java Code Golf- Cryptography

Post icon  Posted 08 July 2012 - 09:15 PM

For this challenge, develop your own implementations of encryption, cipher, or hashing algorithms. Note that this means there should be no use of existing cryptography APIs like the javax.crpyto API. Encryption and cipher algorithms should support both encrypt and decrypt functionality. You may design your own class to support any operations. Only the actual encryption and decryption methods will be used in determining number of characters.

I have a sample RSA class. With the encrypt() and decrypt() methods, the character count comes out to 477 characters.
Spoiler

This post has been edited by macosxnerd101: 08 July 2012 - 09:52 PM
Reason for edit:: Don't trust Microsoft Word's character count feature


Is This A Good Question/Topic? 0
  • +

Replies To: [Challenge] Java Code Golf- Cryptography

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1618
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: [Challenge] Java Code Golf- Cryptography

Posted 08 July 2012 - 10:03 PM

well, I did this in C; I'll see what I can do in Java later. it's 51 chracters

Spoiler


also; what's stopping yours from being 8? you could create proxy functions like so

private void decrypt(){
   d();
}
private void encrypt(){
   e();
}



or am I taking the rules to literally?

This post has been edited by ishkabible: 08 July 2012 - 10:39 PM

Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10196
  • View blog
  • Posts: 37,655
  • Joined: 27-December 08

Re: [Challenge] Java Code Golf- Cryptography

Posted 08 July 2012 - 10:14 PM

I could create proxy functions. It seems to defeat the spirit of the challenge though. What algorithm are you implementing, out of curiosity? :)
Was This Post Helpful? 0
  • +
  • -

#4 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1618
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: [Challenge] Java Code Golf- Cryptography

Posted 08 July 2012 - 10:16 PM

just xor encryption...horribly obfuscated xor encryption. it uses the idea that (x^y)^y == x. you xor each bit of data with some key to encrypt it and when you need to decrypt it you apply the key again. it also happens that for most values of x and y, x^y isn't recognizable from x or y.

here's a full test program.
Spoiler


edit: also I miscounted, it's only 48!

edit2: here it is in Java
Spoiler

This post has been edited by ishkabible: 09 July 2012 - 09:53 AM

Was This Post Helpful? 1
  • +
  • -

#5 cppnewb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 13

Re: [Challenge] Java Code Golf- Cryptography

Posted 28 October 2013 - 01:07 PM

Cool challenge, gonna do some of the more basic ciphers (minus the transposition that can be done in like 3 lines and is pointless).

I'ma start with a Ceasar shift.
    public void CeasarEncrypt(){
      String toCrypt = getInput();
      char[] charList = toCrypt.toCharArray();
      int[] x = new int[toCrypt.length()];
      for(int i = 0; i < toCrypt.length(); i++){
          x[i] = (int) charList[i] + 3;
          charList[i] = (char) x[i];
      }
      for(int j = 0; j < toCrypt.length(); j++){
              System.out.print(charList[j]);
          }
    }
    
    public void CeasarDecrypt(){
     String deCrypt = getInput();
     char[] charList = deCrypt.toCharArray();
     int[] x = new int[deCrypt.length()];
     for(int i = 0; i < deCrypt.length(); i++){
          x[i] = (int) charList[i] - 3;
          charList[i] = (char) x[i];
      }
      for(int j = 0; j < deCrypt.length(); j++){
              System.out.print(charList[j]);
          }
    }



Note Ceasasr used a shift key of 3, it would however be easy to modify that code for any key you want
or to grab it from the user.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1