Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btn_encryptActionPerformed(java.awt.event.ActionEvent evt) {
- char a[] = {'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'};
- int key = Integer.parseInt(tf_key.getText());
- String text = tf_text.getText();
- int k = 25 - key;
- char[] result = new char[text.length()]; // {'t', 'f', 'd', 'v', 's', 'f'}
- char[] letters = text.toLowerCase().toCharArray(); // {'s', 'e', 'c', 'u', 'r', 'e'}
- for (int i = 0; i < text.length(); i++) {
- for (int j = 0; j < a.length; j++) {
- if (j <= k) {
- if (letters[i] == a[j]) {
- result[i] = a[j + key];
- }
- } else {
- if (letters[i] == a[j]) {
- result[i] = a[j - (k + 1)];
- }
- }
- }
- }
- String generatedCipher = String.valueOf(result); // tfdvsfa
- tf_cipher.setText(generatedCipher); // tfdvsfa
- }
- private void btn_decryptActionPerformed(java.awt.event.ActionEvent evt) {
- char a[] = {'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'};
- int key = Integer.parseInt(tf_key.getText());
- String text = tf_text.getText();
- int k = 25 - key;
- char[] result = new char[text.length()];
- char[] letters = text.toLowerCase().toCharArray();
- for (int i = 0; i < text.length(); i++) {
- for (int j = 0; j < a.length; j++) {
- if (j > (key - 1)) {
- if (letters[i] == a[j]) {
- result[i] = a[j - key];
- }
- } else {
- if (letters[i] == a[j]) {
- result[i] = a[j + (k + 1)];
- }
- }
- }
- }
- String generatedCipher = String.valueOf(result);
- tf_cipher.setText(generatedCipher);
- }
Add Comment
Please, Sign In to add comment