Kode Aktivitas Vigenere Cypher Pada Bahasa Pemrograman Java

Berikut ini saya coba sajikan satu rutin aplikasi ciphering dalam bahasa / kegiatan Java untuk melaksanakan enkripsi dan dekripsi  Vigenere cipher.
Vigenère cipher yakni metode enkripsi teks aksara dengan memakai serangkaian cipher Caesar berbeda menurut suatu kata kunci. Boleh dikatakan bahwa  Vigenère  merupakan bentuk sederhana substitusi polyalphabetic.


The Vigenère cipher, ditemukan oleh seorang Prancis, Blaise de Vigenère di kurun ke-16. Ini yakni cipher polyalphabetic sebab memakai dua atau lebih huruf cipher untuk mengenkripsi data. Dengan kata lain, huruf- huruf dalam cipher Vigenère diubah menurut lompatan  yang berbeda, biasanya dilakukan dengan memakai kata atau frase sebagai kunci enkripsi.
Berbeda dengan cipher monoalphabetic, cipher polyalphabetic tidak rentan terhadap analisis frekuensi, sebab lebih dari satu huruf dalam plaintext sanggup diwakili oleh satu huruf di enkripsi.

                package com.darto.vigenecipher;
                public class VigenereCipher
                {
                    public static String encrypt(String text, selesai String key)
                    {
                        String res = "";
                        text = text.toUpperCase();
                        for (int i = 0, j = 0; i < text.length(); i++)
                        {
                            char c = text.charAt(i);
                            if (c < 'A' || c > 'Z')
                                continue;
                            res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A');
                            j = ++j % key.length();
                        }
                        return res;
                    }
                 
                    public static String decrypt(String text, selesai String key)
                    {
                        String res = "";
                        text = text.toUpperCase();
                        for (int i = 0, j = 0; i < text.length(); i++)
                        {
                            char c = text.charAt(i);
                            if (c < 'A' || c > 'Z')
                                continue;
                            res += (char) ((c - key.charAt(j) + 26) % 26 + 'A');
                            j = ++j % key.length();
                        }
                        return res;
    }

                    public static void main(String[] args)
                    {
                        String key = "MYJAVALAMP";
                        String message = "Blog saya ada di blogspot !";
                        String encryptedMsg = encrypt(message, key);
                        System.out.println("String: " + message);
                        System.out.println("Encrypted message: " + encryptedMsg);
                        System.out.println("Decrypted message: " + decrypt(encryptedMsg, key));
                    }

Baca Juga

                }

Artikel Terkait

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel