Forums - Open Redstone Engineers
cryptography - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: Programming (https://forum.openredstone.org/forum-8.html)
+--- Thread: cryptography (/thread-1405.html)



cryptography - David - 11-19-2013

I've designed my own cryptography and made a java app to translate it from english to some weird stuff, and from weird stuff to english. Or any language really.

here is the code:
Code:
package cryptography;
import java.util.Scanner;
public class Cryptography {
    private static int shift = 0;
    private static final char[] alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                                            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
    private static final Scanner scan = new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println("1. from Enlish to cryptography");
        System.out.println("2. from cryptography to English");
        String choicestr = scan.nextLine();
        int choiceint = Integer.parseInt(choicestr);
        if(choiceint == 1){
            String rawui = scan.nextLine();
            char[] ui = rawui.toCharArray();
            for(int i = 0; i < ui.length; i++){
                int number = getNumber(ui[i]) + shift;
                System.out.print(getLetter(number));
                shift++;
            }
        } else {
            String rawui = scan.nextLine();
            char[] ui = rawui.toCharArray();
            for(int i = 0; i < ui.length; i++){
                int number = getNumber(ui[i]);
                number = number - i;
                System.out.print(getLetter(number));
                shift++;
            }
            System.out.println();
        }
    }
    private static int getNumber(char letter) {
        for(int i = 0; i < 26; i++) {
            if(alphabet[i] == letter) {
                return i;
            }
        }
        return 0;
    }
    private static String getLetter(int number) {
        return "" + alphabet[number];
    }
}

It only handles lower-case letters noting more nothing less. There is also a limit to how long your word can be, that limit depends on your word. It also doesn't handle sentences, only words.

Here is how it works:
The first letter you translate is always the same letter (a = a, b = b, c = c etc.)
The second letter you translate is shifted one (a = b, b = c, c = d etc.)
The third letter you tanslate is shifted twice (a = c, b = d, c = e etc.)
etc.

Let's say we want to translate "ore".
The first letter always is the same, so we've got this so far: "o.."
The second letter is shifted one to the right, the r becomes s: "os."
The third letter is shifted twice, the e becomes g: "osg"
There you go ore would be osg.

-David


RE: cryptography - Thor23 - 11-20-2013

Since it seems like you don't know, the encryption you've got here is actually this: Vigenère_cipher


RE: cryptography - David - 11-20-2013

(11-20-2013, 08:41 AM)Thor23 Wrote: Since it seems like you don't know, the encryption you've got here is actually this: Vigenère_cipher

No it isn't. The encryption process is not the same like, at all.


RE: cryptography - Xeomorpher - 11-20-2013

It is, except your's has a constant key, and is thus, less secure.


RE: cryptography - Xeomorpher - 11-20-2013

though they're both pretty weak formats


RE: cryptography - David - 11-20-2013

It was not intended for the military to send secret messages to somebody Smile. And my goal is accomplished, just having fun while writing a java app.


RE: cryptography - Chibill - 11-20-2013

I may copy with in my cousel for my version of SSH