Выдает ошибку что выхожу за пределы массива, хотя проверяю это в цикле. Тем не менее через раз, выводит ошибку.
package supreme;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
menu();
}
public static void menu() {
Scanner in = new Scanner(System.in);
int choice;
System.out.print("1.Crypt\n2.Uncrypt\n3.Exit\nPlease make your choice: ");
switch(choice = in.nextInt()) {
case 1:
{
System.out.println("Please enter your string which will be crypted: ");
String line = in.next();
byte[] crypting = line.getBytes();
System.out.println("Please enter your password(it can be any number): ");
String temp = in.next();
char [] password = temp.toCharArray();
for ( int i = 0; i <crypting.length; i ++ ) {
System.out.println("Element " + i +" is: " + crypting[i]);
}
int counter = 0;
for (int i = 0; i < crypting.length; i++) {
if(counter == crypting.length) counter = 0;
if((password[counter] == '1') && (password[counter+1] == '0')) {
crypting[i] = (byte)(crypting[i] << 1);
}
if(password[counter] == '0' && password[counter+1] == '1') {
crypting[i] = (byte)(crypting[i] >> 1);
}
if(password[counter] == '1' && password[counter+1] == '1') {
crypting[i] = (byte)(~crypting[i]);
}
counter+=2;
System.out.println(counter);
}
System.out.println("After crypt!");
for( int i = 0; i <crypting.length; i ++ ) {
System.out.println("Element " + i +" is: " + crypting[i]);
}
String crypted = new String(crypting);
System.out.println(crypted);
byte [] sss = crypted.getBytes();
for(int i = 0; i < sss.length; i++) {
System.out.println(sss[i]);
}
break;
}
case 2:
{
break;
}
default:
System.out.println("Please, choose one of the possible variants:");
menu();
}
}
}
if (counter >= password.length - 2) counter = 0;
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Разрабатываю свою Java IDE, необходимо найти autocomplete фичуВозможно, есть какой-то опенсорс репозиторий или можно как-то вырвать этот механизм...
Подскажите пожалуйста, как лучше получать сигнал с аудио разъёма пк для последующей его обработки на java? Есть ли какие - нибудь специальные...
Такое вообще возможно? Именно что бы из кода Java программы это делалосьОС Windows