LISTING PROGRAM
Kode Program Class Enkrip
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Numerics;
using System.IO;
namespace test1 {
class enkrip
{
public int[] cipher(int p, int ea, int[] arrayint) {
BigInteger e = 0;
//stringtochar arrchar = new stringtochar();
//char[] arraychar = arrchar.arrasci(text); //int[] arrayint = new int[arraychar.Length]; int key = ea;
int prime = p;
for (int i = 0; i <= arrayint.Length - 1; i++) {
// arrayint[i] = (int)arraychar[i];
e = BigInteger.ModPow(arrayint[i], key, prime); arrayint[i] = (int)e;
}
return arrayint; }
public void buatfiletextpengirim(string text, string filename) {
string direktoriawal = Directory.GetCurrentDirectory(); if (!Directory.Exists(direktoriawal + "/Pengirim")) {
Directory.CreateDirectory(direktoriawal + "/Pengirim"); }
System.IO.File.WriteAllText(direktoriawal + "/Pengirim/" + filename, text);
}
public void buatfiletextpenerima(string text, string filename) {
string direktoriawal = Directory.GetCurrentDirectory(); if (!Directory.Exists(direktoriawal + "/Penerima")) {
Directory.CreateDirectory(direktoriawal + "/Penerima"); }
System.IO.File.WriteAllText(direktoriawal + "/Penerima/" + filename, text);
Kode Program Class Dekrip
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Numerics;
namespace test1 {
class dekrip
{
public int[] plaintxt(int p, int[] enkripted, BigInteger da) {
BigInteger e = 0;
//enkrip ciphertext = new enkrip();
int[] arrayint = new int[enkripted.Length]; for (int i = 0; i <= enkripted.Length - 1; i++) {
arrayint[i] = (int)enkripted[i]; }
BigInteger key = da; int prime = p;
for (int i = 0; i <= arrayint.Length - 1; i++) {
e = BigInteger.ModPow(arrayint[i], key, prime); arrayint[i] = (int)e;
}
/*char[] hasildekrip = new char[arrayint.Length]; for (int j = 0; j <= arrayint.Length - 1; j++) {
hasildekrip[j] = (char)arrayint[j]; }
string result = string.Join("", hasildekrip);
System.IO.File.WriteAllText("C:/Users/Asus/Documents/Visual Studio 2012/Projects/test1/dekripted.txt", result);*/
return arrayint;
} } }
Kode Program Class Embed
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication2 {
class embed
{
convertbiner binertext = new convertbiner();
public string replacebit(string a, int posisi, string b) {
var aStringBuilder = new StringBuilder(a); aStringBuilder.Remove(posisi-1, 1);
aStringBuilder.Insert(posisi-1, b); return aStringBuilder.ToString(); }
public int tanambiner(string binaryawal, char rgb, string text) {
string[] binertexta = binertext.splittext(text); //int c = 0;
int i;
ulang:
for ( i = q; i < binertexta[r].Length; i++) {
string g;
string d = binertexta[r].Substring(i, 1); if (rgb == 'r')
{
g = replacebit(binaryawal, 8, d); q = q + 1;
}
else if (rgb == 'g') {
g = replacebit(binaryawal, 7, d); q = q + 1;
} else {
g = replacebit(binaryawal, 6, d); q = q + 1;
}
// a2 = a+1;
return Convert.ToInt32(g, 2); }
// if ((rgb == 'g') || (rgb == 'b')) // {
if (r == binertexta.Length-1) {
return Convert.ToInt32(binaryawal, 2); }
q = 0; r++;
goto ulang;
// } /* else {
return Convert.ToInt32(binaryawal, 2); } */
}
int t = s;
string[] binertexta = binertext.splittext(text); if (t <= binertexta.Length-1)
{
s = s + 1;
return ((binertexta[t].Length * 10) + 104); }
else {
s = s + 1; return 255; }
}
public int menambahintensitas(int x) {
if (x < 128) {
x = x + 128; }
return x; }
public int mengurangiintensitas(int colorawal, int x) {
if (colorawal < 128) {
x = x - 128; }
return x; }
public int buatgambar(Bitmap img, string text, string filehasil) {
string r, g, b;
int nr, ng, nb, R, G, B, A; int na = 0;
//Bitmap img = new Bitmap(@"C:\Users\Asus\Documents\Visual Studio 2012\Projects\ls test\a.bmp");
Bitmap gr = new Bitmap(img.Width, img.Height);
for (int y = 0; y < img.Height; y++) {
for (int x = 0; x < img.Width; x++) {
//a = 0;
Color pixel = img.GetPixel(x, y); R = img.GetPixel(x, y).R;
G = img.GetPixel(x, y).G; B = img.GetPixel(x, y).B; A = img.GetPixel(x, y).A;
r = binertext.inttobiner(menambahintensitas(R)); g = binertext.inttobiner(menambahintensitas(G)); b = binertext.inttobiner(menambahintensitas(B));
//int s = 100;
gr.SetPixel(x, y, Color.FromArgb(na, nr, ng, nb)); // using (Graphics gfx = Graphics.FromImage(bitmap)
//buat gambar
} }
//img.DrawToImage(img, new Rectangle(0, 0, img.Width, img.Height)); //gr.Save("c:/temp/hasil.bmp", ImageFormat.Bmp);
gr.Save(filehasil); return 0;
}
} }
Kode Program Class Ekstrak
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Drawing;
namespace ConsoleApplication2 {
class ekstrak
{
//Bitmap img = new Bitmap(@"C:\Users\Asus\Documents\Visual Studio 2012\Projects\ls test\hasil.bmp");
convertbiner binertext = new convertbiner(); embed intensitas = new embed();
public string ambilbiner(string binary, char rgb) {
string g; if (rgb == 'r') {
g = binary.Substring(7, 1); return g;
}
else if (rgb == 'g') {
g = binary.Substring(6, 1); return g;
} else {
g = binary.Substring(5, 1); return g;
public int ekstrakdata(Bitmap img, string filehasil) {
int R, G, B, A; int a = 0; int i = 0; int j = 0;
string r, g, b, fr, fg, fb; string q = "";
//int s = 0;
//string stringa = "";
int[] stringa = new int[img.Height * img.Width]; for (int y = 0; y < img.Height; y++)
{
for (int x = 0; x < img.Width; x++) {
Color pixel = img.GetPixel(x, y); R = img.GetPixel(x, y).R;
G = img.GetPixel(x, y).G; B = img.GetPixel(x, y).B; A = img.GetPixel(x, y).A;
r = binertext.inttobiner(intensitas.menambahintensitas(R)); g = binertext.inttobiner(intensitas.menambahintensitas(G)); b = binertext.inttobiner(intensitas.menambahintensitas(B));
if ( A == 255) {
stringa[i] = A; i++;
} else {
a = (A - 104) / 10; stringa[i] = a; i++;
j++; }
fr = ambilbiner(r, 'r'); fg = ambilbiner(g, 'g'); fb = ambilbiner(b, 'b');
//stringa[i] = a;
//stringa += string.Join("", a);
q += string.Join("", fr, fg, fb);
} }
// string[] stringb = stringa.Split(';');
int z; int v = 0;
int[] intrgb = new int[j];
for (int l = 0; l <= stringa.Length; l++) {
//z = Int32.Parse(stringb[i]); z = stringa[l];
{
break; }
intrgb[l] = Convert.ToInt32(q.Substring(v, z), 2); v += (z );
}
string result = string.Join(";", intrgb); // binary to int
// int to text file
System.IO.File.WriteAllText(filehasil, result);
return 0; }
} }
Kode Program Class Kripto
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Numerics;
namespace test1 {
public class kripto
{
public string gettext(string path) {
return System.IO.File.ReadAllText(path); }
public int random(int a) {
Random rand = new Random(); if (a < 256)
{
int p = rand.Next(256, 25000); return p;
} else {
int p = rand.Next(a, 25000); return p;
} }
public int rand(int b) {
Random rand = new Random(); int p = rand.Next(2, b); return p;
}
public bool test(int p, int b, double m) {
int a = rand(p); int j = 0;
ulang4:
if ((j > 0) && (z == 1)) {
return false; }
j = j + 1;
if ((j < b) && (z != p -1)) {
z = Math.Pow(z, 2) % p; goto ulang4;
}
if (z == p -1) {
if ((j == b) && (z != p - 1)) {
return false; }
return true; }
return true; }
return false; }
public int prima(int textlenght) {
ganjil: int cek = 0;
int p =random(textlenght); if (p % 2 == 0)
{
if (p == 25000) {
p--; }
else p++; }
if ((p % 3 == 0) || (p % 5 == 0) || (p % 7 == 0) || (p % 11 == 0) || (p % 13 == 0) || (p % 17 == 0) || (p % 19 == 0))
{
goto ganjil; }
int b = 0; double m = 0; do
{
b++;
m = (p - 1) / Math.Pow(2, b);
} while (m % 2 == 0);
do {
if (test(p, b, m) == true) {
cek++; }
else goto ganjil; } while (cek <= 2000);
//Console.WriteLine("m ="+m); return p;
}
public int kea(int p) {
int b = p - 1; int c = 0; int a = 0; int eA = 0; do
{
eA = rand(b); a = GCD(b,eA, c); } while (a != 1); return eA;
}
public BigInteger kda(int p, int eA) {
BigInteger p1 = p - 1, eA1 = eA; BigInteger a = p1, da = 0, b = 1; while (eA1 > 0)
{
BigInteger t = a / eA1, x = eA1; eA1 = a % x;
a = x; x = b;
b = da - t * x; da = x;
}
da %= p1;
if (da < 0) da = (da + p1) % p1; return da;
}
public int GCD(int b, int A, int c) {
c = b % A;
while (c != 0) {
b = A; A = c; c = b % A;
}
return A; }