Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

TUGAS

“MEMBUAT PROGRAM KRIPTOGRAFI”


SISTEM KEAMANAN KOMPUTER
Dosen Pengampu : Wanhendra, M.SI

Dikerjakan Oleh :
Sersanda Bagas Oktavio (Nim. 3221023)
Wenny (Nim. 3221040)

PRODI SISTEM INFORMASI


SEKOLAH TINGGI TEKNOLOGI INDONESIA TANJUNGPINANG
TANJUNGPINANG
2023
1. Program Kriptografi (Teknik Subtitusi Cipher dengan 1 key) Menggunakan
bahasa Pemrograman Python.

Source Code :
# Nama :- Sersanda Bagas Oktavio (3221023) #
# - Wenny (3221040) #
# Mata Kuliah : Sistem Keamanan Komputer #
# Dosen Pengampu : Wanhendra,M.SI #
# ================================================================== #

def generate_alphabet_table(key):
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
table = key.upper() + alphabet

unique_chars = []
for char in table:
if char not in unique_chars:
unique_chars.append(char)

return ''.join(unique_chars)

def generate_cipher_table(key):
key = ''.join(sorted(set(key), key=key.index))
cipher_alphabet = key +
''.join(sorted(set("ABCDEFGHIJKLMNOPQRSTUVWXYZ") - set(key)))
return {plain: cipher for plain, cipher in
zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ", cipher_alphabet)}

def enkripsi(plaintext, key):


alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
table_key = generate_alphabet_table(key)
cipher_table = generate_cipher_table(key)
ciphertext = ''.join([cipher_table[letter] for letter in
plaintext.upper()])
return ciphertext

def deskripsi(ciphertext, key):


cipher_table = generate_cipher_table(key)
plaintext = ''.join([key for key, value in cipher_table.items() if
value == letter][0] for letter in ciphertext.upper())
return plaintext
def main():
print(' ')
print('===================================')
print('---3221023_Bagas & 3221040_Wenny---')
print('===================================')
print(' ')

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
choice = input("1. Enkripsi\n2. Dekripsi\nPilih Option :")
if choice == '1':
print(' ')
plaintext = input("Masukkan plaintext: ").upper()
key = input("Masukkan key: ").upper()

table_key = generate_alphabet_table(key)
print(f"\ntabel kolom alpabet key1:\n{alphabet}\n{table_key}")
print(' ')

ciphertext = enkripsi(plaintext, key)


print("Hasil chipertext:", ciphertext)
print(' ')

elif choice == '2':


print(' ')
ciphertext = input("Masukkan Cipher Text: ")
key = input("Masukkan key: ").upper()

deskripsied_text = deskripsi(ciphertext, key)


print(' ')
print("Teks terdekripsi (deskripsi Text):", deskripsied_text)
else:
print(' ')
print("Opsi tidak valid. Silakan pilih 1 atau 2.")

if __name__ == "__main__":
main()
2. Program Kriptografi (Teknik Subtitusi Cipher dengan 2 key) Menggunakan
bahasa Pemrograman Python.

Source Code :
# Nama :- Sersanda Bagas Oktavio (3221023) #
# - Wenny (3221040) #
# Mata Kuliah : Sistem Keamanan Komputer #
# Dosen Pengampu : Wanhendra,M.SI #
# ================================================================== #

def generate_alphabet_table(key):
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
table = key.upper() + alphabet

unique_chars = []
for char in table:
if char not in unique_chars:
unique_chars.append(char)

return ''.join(unique_chars)

def enkripsi(plaintext, key1, key2):


alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
table_key1 = generate_alphabet_table(key1)
table_key2 = generate_alphabet_table(key2)

ciphertext_key1 = ''
for char in plaintext:
if char in alphabet:
index = alphabet.index(char)
ciphertext_key1 += table_key1[index]

ciphertext_key2 = ''
for char in ciphertext_key1:
if char in alphabet:
index = alphabet.index(char)
ciphertext_key2 += table_key2[index]

return ciphertext_key2

def deskripsi(ciphertext, key1, key2):


alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
table_key1 = generate_alphabet_table(key1)
table_key2 = generate_alphabet_table(key2)

deskripsied_key2 = ''
for char in ciphertext:
if char in alphabet:
index = table_key2.index(char)
deskripsied_key2 += alphabet[index]

deskripsied_key1 = ''
for char in deskripsied_key2:
if char in alphabet:
index = table_key1.index(char)
deskripsied_key1 += alphabet[index]

return deskripsied_key1

def main():
print(' ')
print('===================================')
print('---3221023_Bagas & 3221040_Wenny---')
print('===================================')
print(' ')

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

choice = input("1. Enkripsi\n2. Dekripsi\nPilih Option :")


if choice == '1':
plaintext = input("Input PLAINTEXT: ").upper()
key1 = input("Input key1: ").upper()
key2 = input("Input key2: ").upper()

table_key1 = generate_alphabet_table(key1)
table_key2 = generate_alphabet_table(key2)

print(f"\ntabel kolom alpabet key1:\n{alphabet}\n{table_key1}")


print(f"\ntabel kolom alpabet key2:\n{alphabet}\n{table_key2}")

ciphertext = enkripsi(plaintext, key1, key2)

print(f"\nHasil chipertext: {ciphertext}")


print(' ')

elif choice == '2':


print(' ')
ciphertext = input("Masukkan Cipher Text: ")
key1 = input("Masukkan key1: ").upper()
key2 = input("Masukkan key2: ").upper()

deskripsied_text = deskripsi(ciphertext, key1, key2)


print(' ')
print("Teks terdekripsi (deskripsi Text):", deskripsied_text)
print(' ')
else:
print(' ')
print("Opsi tidak valid. Silakan pilih 1 atau 2.")

if __name__ == "__main__":
main()

3. Program Kriptografi (Teknik Shift Cipher) Menggunakan bahasa Pemrograman


Python

Source Code :
# Nama :- Sersanda Bagas Oktavio (3221023) #
# - Wenny (3221040) #
# Mata Kuliah : Sistem Keamanan Komputer #
# Dosen Pengampu : Wanhendra,M.SI #
# ================================================================== #

def enkripsi(text, key):


result = ""
for char in text:
if char.isalpha():
shift = ord('A') if char.isupper() else ord('a')
result += chr((ord(char) - shift + key) % 26 + shift)
else:
result += char
return result

def deskripsi(text, key):


return enkripsi(text, -key)

def main():
print(' ')
print('===================================')
print('---3221023_Bagas & 3221040_Wenny---')
print('===================================')
print(' ')

choice = input("1. Enkripsi\n2. Dekripsi\nPilih Option :")


if choice == '1':
print(' ')
text = input("Masukkan Pesan (PlainText): ")
key = int(input("Key: "))

enkripsied_text = enkripsi(text, key)


print(' ')
print("Teks terenkripsi (Cipher Text):", enkripsied_text)
elif choice == '2':
print(' ')
text = input("Masukkan Cipher Text: ")
key = int(input("Key: "))

deskripsied_text = deskripsi(text, key)


print(' ')
print("Teks terdekripsi (deskripsied Text):", deskripsied_text)
else:
print(' ')
print("Opsi tidak valid. Silakan pilih 1 atau 2.")

if __name__ == "__main__":
main()

You might also like