To write a C# program to perform encryption and decryption of the given data.
#1

Aim:
To write a C# program to perform encryption and decryption of the given data.

Algorithm
ALGORITHM FOR ENCRYPTION:
Step 1: Declare the class as encrypt_class.
Step 2: Start the main function.
Step 3: Declare the variable str in string data type.
Step 4: Create the object for inbuild encryption
algorithm TripleDESCryptoServiceProvider.
Step 5: Create the data file using Filestream
class.
Step 6: Create the object for class cryptoStream.
Cryptostream is a class to invoke the
Encryotor algorithm.
Get the input from the user using Console.Readline().
Step 7: Write the input data using WriteLine function.
Step 8: Create the key file using File.Create.
Step 9: convert the key file into binary form.
Step 10:Close the file.
Step 11Tonguerint Data encrypted using console.writeLine.
ALGORITHM FOR DECRYPTION :
Step 1: Declare a class as decrypt_class
Step 2: start the main function
Step 3:Create the object for the inbuild algorithm
TripleDESCrypotserviceProvider.
Step 4: Create the file in c drive using FileStream fs =File.openRead.
Step 5: Using Binary Reader convert file as in binary form.
Step 6:Read the number of bytes of key file.
Step 7: Open the data file using FileRead function.
Step 8: Cryptostream is a class to use invoke the Decrytptor.
Step 9: Create the object for CryptoStream class.
Step 10: Using StreamReader read the data file .
Step 11: Print the content of data file using Console.writeLine.
Step 12: Close the file.
Program:
Code:
Encryption
using System;
using System.IO;
using System.Security.Cryptography;

class encrypt_class
{
public static void Main()
{
String str;

TripleDESCryptoServiceProvider cp= new TripleDESCryptoServiceProvider();

FileStream fs = File.Create("C:\\file.dat");
CryptoStream cs = new
CryptoStream(fs,cp.CreateEncryptor(),CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs);

Console.WriteLine("Enter a string");
str=Console.ReadLine();

sw.WriteLine(str);
sw.Close();

fs= File.Create("C:\\file.key");
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(cp.Key);
bw.Write(cp.IV);
bw.Close();

Console.WriteLine("Data Encrypted........");
}
}


Decryption:

using System;
using System.IO;
using System.Security.Cryptography;

class decrypt_class
{

public static void Main()
{

TripleDESCryptoServiceProvider cp= new TripleDESCryptoServiceProvider();

FileStream fs = File.OpenRead("C:\\file.key");
BinaryReader br = new BinaryReader(fs);
cp.Key=br.ReadBytes(24);
cp.IV=br.ReadBytes(8);

fs= File.OpenRead("C:\\file.dat");
CryptoStream cs = new
CryptoStream(fs,cp.CreateDecryptor(),CryptoStreamMode.Read);

StreamReader sr = new StreamReader(cs);

Console.WriteLine("Content in the file (After Decryption)");
Console.WriteLine(sr.ReadLine());
sr.Close();
}
}

Execution:
csc encrypt_class.cs
encrypt_class file

Enter the string
Abcdefghijklmnopqrstuvwxyz
Data encrypted……

csc decrypt_class.cs
decrypt_class file

Content in the file is (After decryption)
Abcdefghijklmnopqrstuvwxyz.
ENCRYPTION AND DECRYPTION PROGRAM USING COM
Code:
Dim dstr As String
    Dim i As Integer
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        For i = 1 To Len(TextBox1.Text)
            dstr = dstr + Chr(Asc(Mid(TextBox1.Text, i, 1)) + i)
        Next
        TextBox1.Text = dstr
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        dstr = ""
        For i = Len(TextBox1.Text) To 1 Step -1
            dstr = Chr(Asc(Mid(TextBox1.Text, i, 1)) - i) + dstr
        Next
        TextBox1.Text = dstr
    End Sub
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: objectives of expert system to prescribe medicine for the given symptoms, write a program to assign seats on each flight, wikipedia data flow diagram for encryption and decryption, data encryption and decryption topic, write a program for des in c, program in c to find first and follow of a given grammar, spech for thanking given seminar,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  VHDL program for Booth’s Multiplier smart paper boy 2 5,653 20-04-2013, 11:59 AM
Last Post: T
  Program in “LEX” to count number of vowels and consonants seminar class 2 9,626 22-03-2013, 10:20 AM
Last Post: computer topic
  Program in “LEX” to count number of Identifiers and Keywords seminar class 1 4,843 28-01-2013, 03:21 PM
Last Post: Guest
  To predict Exons in the given nucleotide sequence using the HMM gene tool. smart paper boy 0 1,237 10-08-2011, 02:50 PM
Last Post: smart paper boy
  To predict Open Reading Frames (ORFs) in the given nucleotide sequence using the ORF smart paper boy 0 1,418 10-08-2011, 02:49 PM
Last Post: smart paper boy
  To predict the genes in the given nucleotide sequence using the GenScan tool. smart paper boy 0 1,189 10-08-2011, 02:46 PM
Last Post: smart paper boy
  To perform multiple sequence alignment between the given sequences using Clustalw2 to smart paper boy 0 1,393 10-08-2011, 02:44 PM
Last Post: smart paper boy
  To perform global alignment between the given sequences using EMBOSS tool. smart paper boy 0 1,351 10-08-2011, 02:43 PM
Last Post: smart paper boy
  To perform local alignment between the given sequences using EMBOSS tool. smart paper boy 0 1,285 10-08-2011, 02:41 PM
Last Post: smart paper boy
  PROGRAM TO RECOGNIZE A STRING WITH THREE COSECUTIVE 0’s smart paper boy 0 1,663 10-08-2011, 11:44 AM
Last Post: smart paper boy

Forum Jump: