Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

need help with java

Name: lazy motherfucker 2008-10-20 12:40

why doesn't this shit read the second string i ask it to read when you hit no. 2?
also, messages in spanish as it is for a college project and i live in some crappy southamerican country and i'm too lazy to change it

import java.io.*;
public class principal {
    public static void main (String args[]) {
        boolean menu=true;
        String textocodificar = null;
        String clavecodificacion = null;
        char opcion = '0';
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    while (menu == true) {
            System.out.println ("menu:");
            System.out.println ("        blah blah");
            System.out.print ("Enter a number (the only one that works is no. 2)");
            try {
                opcion = (char) System.in.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (opcion == '2') {
                System.out.println ("Opción 2: Codificar mensaje");
                System.out.println ("Por favor, introduzca el texto a codificar: ");
                try {
                    textocodificar = bf.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                System.out.print ("Introduzca la clave: ");
                try {
                    clavecodificacion = bf.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                System.out.println ("La Codificación Vinegère del texto dado es: ");
                System.out.println ("El texto 'mide' " + textocodificar.length());
                System.out.println ("La clave 'mide' " + clavecodificacion.length());
                try {
                    System.in.read();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (opcion == '4') {
                menu=false;
            }
        }
    }
}

Name: Xarn !MhMRSATORI!xGIX62dlJesBTK+ 2008-10-21 21:13

>>15
I wish I didn't.

import static java.lang.Character.getNumericValue;

public class vigenere {
    public static String encrypt (String message, String key) {
        return translate(message, key, false);
    }
    public static String decrypt (String message, String key) {
        return translate(message, key, true);
    }
   
    private static String translate (String mess, String key, boolean decrypt) {
        char o[] = mess.toCharArray(),
             k[] = key.toCharArray(),
             chars[] = new char[]
            {'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'};
       
        for (int i = 0; i < k.length; i++)
            if (!Character.isLetter(k[i]))
                throw new IllegalArgumentException("Suck less.");
       
        for (int i = 0; i < o.length; i++)
            if (Character.isLetter(o[i]))
                o[i] =
                    chars[decrypt ? (getNumericValue(o[i]) -
                                     getNumericValue(k[i % k.length]) +
                                     chars.length) % chars.length
                                  : (getNumericValue(o[i]) +
                                     getNumericValue(k[i % k.length]) -
                                     20) % chars.length];
       
        return new String(o);
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List