Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
PHPmaster PHPmaster is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 332
Rep Power: 15
PHPmaster mempunyai hidup yang Normal
Default [SHARE] Enkripsi Teks: Caesar,Mono-Polyalphabetic, Vigenere, Permutasi/Trasposisi

Dear All,

Member baru, mau share dasar-dasar enkripsi berbasis teks, sebelum menguasai enkripsi berbasis byte (Stream cipher atau block cipher).





http://dtugasalgoritma.blogspot.com/...r-chipher.html

http://dtugasalgoritma.blogspot.com/...ic-cipher.html





http://dtugasalgoritma.blogspot.com/...-pemutasi.html

http://dtugasalgoritma.blogspot.com/...ic-cipher.html





http://dtugasalgoritma.blogspot.com/...-vigenere.html



Berikut ini kode program:

Caesar Cipher


Code:

Public Class Form1
Dim huruf(26) As Char
Dim i, p, k, c As Integer
Dim plainText, cipherText As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Mengisi array abjad A s/d Z, Kode ASCII A=65
For i = 0 To 25
huruf(i) = Chr(65 + i)
Next i
End Sub

Private Sub ButtonEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEncrypt.Click
cipherText = ""
k = CInt(TextBoxGeser.Text)
If (TextBoxPlain.Text.Length 0) Then
For i = 0 To TextBoxPlain.Text.Length - 1
p = Asc(TextBoxPlain.Text.Substring(i, 1)) - 65
c = (p + k) Mod 26
cipherText = String.Concat(cipherText, huruf(c))
Next i
TextBoxCipher.Text = cipherText
End If
End Sub

Private Sub ButtonDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDecrypt.Click
Dim geserKiri As Integer
plainText = ""
k = CInt(TextBoxGeser.Text)
geserKiri = 26 - (k Mod 26)
If (TextBoxCipher.Text.Length 0) Then
For i = 0 To TextBoxCipher.Text.Length - 1
c = Asc(TextBoxCipher.Text.Substring(i, 1)) - 65
p = (c + geserKiri) Mod 26
plainText = String.Concat(plainText, huruf(p))
Next i
TextBoxPlain2.Text = plainText
End If
End Sub

Poly Alphabetic Cipher


Code:

Public Class Form1
Dim huruf(26) As Char
Dim i, p, k, c As Integer
Dim plainText, cipherText As String
Dim kunci As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Mengisi array abjad A s/d Z, Kode ASCII A=65
For i = 0 To 25
huruf(i) = Chr(65 + i)
Next i
End Sub


Private Sub ButtonEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEncrypt.Click
cipherText = ""
If (TextBoxPlain.TextLength 0 And TextBoxKunci.TextLength 0) Then
aturKunci()
For i = 0 To TextBoxPlain.TextLength - 1
p = Asc(TextBoxPlain.Text.Substring(i, 1)) - 65
k = Asc(kunci.Substring(i, 1)) - 65
c = (p + k) Mod 26
cipherText = String.Concat(cipherText, huruf(c))
Next i
TextBoxCipher.Text = cipherText
End If
End Sub

Private Sub ButtonDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDecrypt.Click
plainText = ""
If (TextBoxCipher.TextLength 0 And TextBoxKunci.TextLength 0) Then
aturKunci()
For i = 0 To TextBoxCipher.TextLength - 1
c = Asc(TextBoxCipher.Text.Substring(i, 1)) - 65
k = Asc(kunci.Substring(i, 1)) - 65
p = (c + 26 - k) Mod 26
plainText = String.Concat(plainText, huruf(p))
Next i
TextBoxPlain2.Text = plainText
End If
End Sub

Private Sub TextBoxPlain_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxPlain.GotFocus
TextBoxPlain.SelectAll()
End Sub

Private Sub TextBoxPlain_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxPlain.KeyPress
e.Handled = Not (Char.IsLetter(e.KeyChar) Or Asc(e.KeyChar) < 32)
e.KeyChar = UCase(e.KeyChar)
End Sub

Private Sub TextBoxPlain_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxPlain.TextChanged
TextBoxCipher.Text = ""
End Sub

Private Sub TextBoxCipher_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBoxCipher.GotFocus
TextBoxCipher.SelectAll()
End Sub

Private Sub TextBoxCipher_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxCipher.KeyPress
e.Handled = Not (Char.IsLetter(e.KeyChar) Or Asc(e.KeyChar) < 32)
e.KeyChar = UCase(e.KeyChar)
End Sub

Private Sub TextBoxCipher_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBoxCipher.TextChanged
TextBoxPlain2.Text = ""
End Sub

Private Sub TextBoxKunci_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBoxKunci.KeyPress
e.Handled = Not (Char.IsLetter(e.KeyChar) Or Asc(e.KeyChar) < 32)
e.KeyChar = UCase(e.KeyChar)
End Sub

Private Sub aturKunci()
If TextBoxPlain.Text.Length 0 Then
kunci = String.Concat(kunci, TextBoxKunci.Text.Substring(0, i))
End If
End If
End Sub

End Class

Enkripsi Transposisi/Permutasi

<div style="margin:20px; margin-top:5px">
Code:

import java.util.Scanner;
public class Transposisi {
public static void main(String[] args) {
// Baca data dari keyboard
Scanner baca = new Scanner(System.in);
System.out.print("Masukkan kalimat (min 3 karakter)? ");
String kal = baca.nextLine().trim().toUpperCase();
if (isValid(kal)) {
// Baca lebar matrix transposisi
System.out.print("Masukkan lebar kolom transposisi (min 2 digit) ? ");
int kolom = baca.nextInt();
if (kolom < 2) {
System.out.print("Lebar kolom transposisi (min 2 digit) !");
System.exit(-1);
}
int baris = kal.length() / kolom;
if (kal.length() % kolom > 0)
baris++;

// Ciptakan matrix dan isi dengan data
char[][] ch = new char[baris][kolom];
int pos = 0;
for (int i=0; i
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Terkait
Thread Thread Starter Forum Replies Last Post
JUAL program enkripsi teks hackerkuntet Software Original & Open Source 0 26th May 2012 10:11 AM
[SHARE] Menampilkan pesan teks sebelum logon windows Braincode Shareware & Freeware 0 11th November 2011 05:32 PM
<<<<Candoia Lovers (Mono Pohon, Mono Tanah, dan Mono Halmahera) Kumpul di Sini>>>> Y451R Reptil lovers 17 21st February 2011 07:48 PM

 


All times are GMT +7. The time now is 07:11 PM.