Guest User

Untitled

a guest
May 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public void vigin ( int dir ){ //viginaere
  2. String key = JOptionPane.showInputDialog(
  3. null,
  4. "Waehle vigin Verschiebung",
  5. "ANGELUS");
  6.  
  7. String text = textarea.getText();
  8. char[] cipher = new char [ text.length() ];
  9.  
  10. for( int i = 0; i < text.length(); i++){
  11. char c = text.charAt( i );
  12. int shift = key.charAt( i % key.length() ) - 'A';
  13. shift *= dir;
  14.  
  15. if( c >= 'A' && c <= 'Z' ){
  16. c += shift;
  17.  
  18. if( c > 'Z'){
  19. c -= 26;
  20.  
  21.  
  22. } else if( c < 'A' ){
  23. c += 26;
  24. }
  25. }
  26. cipher[ i ] = c; //not a character
  27. }//end for
  28. textarea.setText( new String( cipher ) );
  29. }
Add Comment
Please, Sign In to add comment