LISTING PROGRAM
a. Fungsi Buka File
void Word_textstring filepath{ Microsoft.Office.Interop.Word.Application wordApp = new
Microsoft.Office.Interop.Word.ApplicationClass; object filenameO = filepath;
object objFalse = false; object objTrue = true;
object missing = System.Reflection.Missing.Value; object emptyData = string.Empty;
try{ Microsoft.Office.Interop.Word.Document aDoc =
wordApp.Documents.Openref filenameO, ref objFalse, ref objTrue, ref missing, ref missing, ref missing, ref missing,
ref missing,ref missing, ref missing, ref objTrue, ref missing, ref missing,ref missing, ref missing;
aDoc.ActiveWindow.Selection.WholeStory; aDoc.ActiveWindow.Selection.Copy;
IDataObject data = System.Windows.Forms.Clipboard.GetDataObject;
plaintext.Text = data.GetDataSystem.Windows.Forms.DataFormats.Text.
ToString; System.Windows.Forms.Clipboard.SetDataObjectstring.Empty;
} catchException err{
MessageBox.Showerr.Message; }
finally{ MessageBox.ShowFile berhasil dibaca;
}
b. Fungsi Tulis File
void Tulis_Wordstring filepath, string tulis{ Microsoft.Office.Interop.Word.Application wordApp
= new Microsoft.Office.Interop.Word.ApplicationClass;
Universitas Sumatera Utara
object filenameO = filepath; object objFalse = false;
object objTrue = true; object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty; try{
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Add;
Range rng = aDoc.Application. ActiveDocument.Range0,0;
rng.Text = tulis; aDoc.SaveAsref filenameO, ref objFalse, ref objFalse,ref
missing, ref missing, ref missing, ref missing, ref missing ,ref missing, ref missing, ref objTrue, ref missing, ref mi
ssing,ref missing, ref missing; aDoc.Application.ActiveDocument.CloseWdSaveOptions.wdS
aveChanges, ref missing, ref missing; }
catchException err{ MessageBox.Showerr.Message;
} finally{
MessageBox.ShowFile berhasil ditulis; }
c. Fungsi Massey-Omura
public Massey_OmuraBigInteger p{ if p == 0
this.p = generate_kunci_prima; else
this.p = p; do{
e = must_gcd_withBigInteger.Subtractthis.p,1; d = Inverse_Modulare, BigInteger.Subtractthis.p, 1;
}whileBigInteger.GreatestCommonDivisore,BigInteger.Subt ractthis.p, 1 = 1 || BigInteger.Remainder
BigInteger.Multiplyd, e, BigInteger.Subtractthis.p,1 = 1;}
Acak Prima
private BigInteger generate_kunci_prima{ BigInteger c_prima;
do{ rng.GetBytesrnd;
c_prima = BigInteger.Absnew BigIntegerrnd; }whileLehmannc_prima;
return c_prima; }
Acak Kunci Enkripsi private BigInteger must_gcd_withBigInteger p{
Universitas Sumatera Utara
BigInteger c_e; do{
rng.GetBytesrnd; c_e = BigInteger.Absnew BigIntegerrnd;
}whilec_e p || BigInteger.GreatestCommonDivisorc_e, p = 1;
return c_e; }
Pengecekan Prima private bool LehmannBigInteger p{
BigInteger test; int putaran = 0;
do{ rng.GetBytesrnd;
test = BigInteger.RemainderBigInteger.Absnew BigIntegerrnd, BigInteger.Subtractp, 1;
test = BigIntegerBigInteger.ModPowtest, BigInteger.DivideBigInteger.Subtractp, 1,2, p;
if test = 1 BigInteger.Subtracttest, p = -1 return false;
putaran++; }whileputaran 10;
return true; }
Acak Kunci Dekripsi private BigInteger Inverse_ModularBigInteger a, BigInteger
b{ BigInteger x1, y1, x2, y2, q, temp, modulo = b;
x1 = y2 = 1; x2 = y1 = 0;
while b = 0 {
q = BigInteger.Dividea, b; temp = b;
b = BigInteger.Subtracta, BigInteger.Multiplyq, b; a = temp;
temp = x2; x2 = BigInteger.Subtractx1, BigInteger.Multiplyq, x2;
x1 = temp; temp = y2;
y2 = BigInteger.Subtracty1, BigInteger.Multiplyq, y2; y1 = temp;
} x1 = x1 0 ? x1 : BigInteger.Addmodulo, x1;
return x1;
}
Universitas Sumatera Utara
Pehitungan Enkripsi
public BigInteger enkripsiBigInteger p_or_c{ return BigInteger.ModPowp_or_c, e, p;
}
Perhitungan Dekripsi public BigInteger dekripsiBigInteger c{
return BigInteger.ModPowc, d, p; }
}
d. Fungsi Elias Gamma