Online since 2002. Over 3300 puzzles, 2600 worldwide members, and 270,000 messages.

TwistyPuzzles.com Forum

It is currently Tue Jul 22, 2014 7:40 am

All times are UTC - 5 hours



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 10:18 pm 
Offline
User avatar

Joined: Fri Feb 06, 2009 2:57 pm
Location: Pittsburgh
I know some of you may be curious in small programming challenges for beginning programmers, right?

I was bored at work waiting for a server to restart, so I made myself a ROT13 encode/decoder in java.

Fb, urer vg tbrf. Rapbqrf hccrepnfr, ybjrepnfr, naq vtaber punenpgref gung nera'g n-mN-M jvgubhg ertrk. Gung'q or rnfvre va n jnl, ohg guvf jbexrq bhg svar, gbb.

It also gave me an idea for another kind of ROT kind of cypher/cyptograph. I'll code the logic for it, if anyone is curious to try to crack it?

_________________
3x3x3 PB: 00:48.10
"Study gravitation, it's a field with a lot of potential."
Image


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 10:49 pm 
Offline
User avatar

Joined: Sat Apr 10, 2010 8:07 pm
Gung jnfag gb uneq V hfrq n fvzcyr nhgb ubg xrl fpevc. unir lbh rire gevrq nux, vgf irel rnfvr gb yrnea naq irel cbjreshy. Naljnl gvzr gb ghea bss gur fpevcg fb V pna tb onpx gb glcvat abeznyyl. Nyfb fbeel sbe nal glcbf V pnag ernyyl gryy vs V'ir znqr gurz :?.



Spoiler:So, here it goes. Encodes upprcase, lowercase, and ignore characters that aren't a-zA-Z without regex. That'd be easier in a way, but this worked out fine, too.


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 10:50 pm 
Offline
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
theVDude wrote:
I know some of you may be curious in small programming challenges for beginning programmers, right?

I was bored at work waiting for a server to restart, so I made myself a ROT13 encode/decoder in java.

Fb, urer vg tbrf. Rapbqrf hccrepnfr, ybjrepnfr, naq vtaber punenpgref gung nera'g n-mN-M jvgubhg ertrk. Gung'q or rnfvre va n jnl, ohg guvf jbexrq bhg svar, gbb.

It also gave me an idea for another kind of ROT kind of cypher/cyptograph. I'll code the logic for it, if anyone is curious to try to crack it?

I absolutely love breaking simple ciphers. I'll happily work on attacking any ciphertext that is is generated through a reasonably simple scheme.

For what it's worth, ROT-N is a mono-alphabetic substitution cipher where the permutation of the substitution alphabet is defined by addition/subtraction and wrapping. XOR is another such scheme, just with a different operator.

There are also well known poly-alphabetic substitution ciphers such as Vigenere and XOR with a multi-byte key.

_________________
Prior to using my real name I posted under the account named bmenrigh.


Last edited by Brandon Enright on Tue Aug 09, 2011 10:53 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 10:53 pm 
Offline
User avatar

Joined: Fri Feb 06, 2009 2:57 pm
Location: Pittsburgh
Beans wrote:
Gung jnfag gb uneq V hfrq n fvzcyr nhgb ubg xrl fpevc. unir lbh rire gevrq nux, vgf irel rnfvr gb yrnea naq irel cbjreshy. Naljnl gvzr gb ghea bss gur fpevcg fb V pna tb onpx gb glcvat abeznyyl. Nyfb fbeel sbe nal glcbf V pnag ernyyl gryy vs V'ir znqr gurz.[/color]

YBY, V unira'g hfrq NUX va n juvyr. Q: Naljnl, V'yy pyrna hc gur wnin pbqr sbe guvf naq cbfg vg hc va gur guernq va n zvahgr. :Q

Code:
package com.thevdude.rot13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class RotThirteen {

   public static void main(String[] args) {
      BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
      String in = "";
      System.out.println("ENTER TO ROT13 ENCODE/DECODE!");
      try{in = r.readLine();}
      catch(IOException e){System.out.println("ERROR!");}
      for(int a = 0 ; a < in.length() ; a++){
         int c = (int)in.charAt(a);
         if((c >= 97)&&(c <= 122)){
            c += 13;
            if(c <= 122){
               System.out.print((char)c);}
            else{
               c -= 26;
               System.out.print((char)c);}
         }else if((c >= 65)&&(c <= 90)){
            c += 13;
            if(c <= 90){
               System.out.print((char)c);}
            else{
               c -= 26;
               System.out.print((char)c);}
         }else{
            System.out.print((char)c);}
      }   
   }
}

_________________
3x3x3 PB: 00:48.10
"Study gravitation, it's a field with a lot of potential."
Image


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 11:08 pm 
Offline
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
If you use the transliteration operator you can do it in a single line of code.

For example here it is in perl:

Code:
brenrigh@lambda ~ $ echo 'test: 1, two, THREE' | perl -pe 'tr/[a-zA-Z]/[n-za-mN-ZA-M]/'
grfg: 1, gjb, GUERR

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 11:14 pm 
Offline
User avatar

Joined: Fri Feb 06, 2009 2:57 pm
Location: Pittsburgh
I'm not cool with regex. I understand, but never learned how to use it. D:

_________________
3x3x3 PB: 00:48.10
"Study gravitation, it's a field with a lot of potential."
Image


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Tue Aug 09, 2011 11:20 pm 
Offline
User avatar

Joined: Thu Dec 31, 2009 8:54 pm
Location: Bay Area, California
theVDude wrote:
I'm not cool with regex. I understand, but never learned how to use it. D:

Transliteration isn't a regular expression operation. Most languages support the canonical regular expression character class syntax of [a-z] in their transliteration operator but that is where the similarity ends.

Personally I think regular expressions are the best thing since sliced bread. Especially regex engines that support capturing and back-references, positive and negative look around, atomic grouping, lazy quantifiers, etc. I highly recommend learning a good regular language such as Perl's regex which is as close to the "standard" as you can get.

_________________
Prior to using my real name I posted under the account named bmenrigh.


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Sat Aug 13, 2011 3:43 pm 
Offline

Joined: Sun Mar 27, 2005 7:37 pm
Oh no, another thread where I haven't got a clue what anyone's talking about. Please stop making me feel stupid!

_________________
Image


Top
 Profile  
 
 Post subject: Re: Programming challenges/Cryptography?
PostPosted: Sat Aug 13, 2011 4:06 pm 
Offline
User avatar

Joined: Sat Apr 10, 2010 8:07 pm
UNUNUN. Vgf abg gung pbzcyvpngrq, heres a translator. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 5 guests


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 post attachments in this forum

Search for:
Jump to:  

Forum powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group