please help me with the java codes for this problem i tried to do this program a week ago but even now i dont have an idea of how to go about with it. please help me it is urgent
Cryptography
Encryption (encoding) Given a message to send, we use the following table of letter to integer conversion to perform the encoding:
a, A=0 b, B=1 c, C=2 d, D=3 e, E=4 f, F=5 g, G=6 h, H=7 i, I=8 j, J=9 k, K=10 l, L=11 m, M=12
n, N=13 o, O=14 p, P=15 q, Q=16 r, R=17 s, S=18 t, T=19 u, U=20 v, V=21 w, W=22 x, X=23 y, Y=24 z, Z=25
And a key k(0<=k<=25).
Example suppose the key for shift cipher is k=11, and the message is we will meet at midnight.
We encode each letter of the message (non-letter characters are not encoded) by first converting it to an integer using the above table, adding the integer and obtain the remainder of the sum divided by 26. the letter to replace w is given by 22 +11=33%26=7. hence w is replaced by h or H
Decoding(decryp tion) to decode an encoded message. For each letter we use the table to get its corresponding integer, subtract 11 from the integer and obtain the remainder of the difference divided by 26. if the result is negative we add 26. the letter to replace h is given by7-k=7-11=-4%26. since it is negative, we add 26 to get 22 so h is replaced by w or W
The task is to write two programs:
1. the fist program will read the shift Cipher key from the key board and filename from the keyboard. The program will then encode the message in the file and write it to a file called “ encrypted.txt”.
2. the second program will also read the shift cipher from the keyboard. The program will then decode the message in the file and write it to a file called “decrypted.txt” . the program should the be used to decode the following encoded message:.
Zebzh irq qeb obxi pfqrxqflk
Kxqflk txo xdxfkpq kxqflk
Tebob afa fq xii ybddfk?
Tebk tfii fq bka?
Tbii, fq pbbjp: qlqxi abpqorzqflk qeb lkiv plirqflk
Xka qebob xfk q kl rpb: kl lkb zxk pqlm qebj klt.
Xfk’ q kl rpb: klylav zxk pqlm qebj klt
1 5222 D_C 293
Contributor
I had this assignment too, but only in C. I'll post the encrypt/decrypt functions for you, and if you decide to understand it, go ahead and translate it. - const int AtoZ = 'Z'-'A'+1;
-
-
void decrypt(int offset, char *str) // offset = cipher
-
{
-
int i=0,l;
-
l=strlen(str);
-
printf("encrypted str = \n%s\n", str);
-
while(i<l)
-
{
-
if((*(str+i) >= 'A') && (*(str+i) < ('A' + AtoZ)))
-
*(str+i)= 'A' + (*(str+i) - 'A' - offset + AtoZ)%AtoZ;
-
if((*(str+i) >= 'a') && (*(str+i) < ('a' + AtoZ)))
-
*(str+i)= 'a' + (*(str+i) - 'a' - offset + AtoZ)%AtoZ;
-
i++;
-
}
-
printf("unencrypted str = \n%s \nlength = %d\n", str, l);
-
}
-
-
void encrypt(int offset, char *str) // offset = cipher
-
{
-
int i=0,l;
-
l=strlen(str);
-
printf("unencrypted str = \n%s\n", str);
-
while(i<l)
-
{
-
if((*(str+i) >= 'A') && (*(str+i) < ('A' + AtoZ)))
-
*(str+i)='A' + (*(str+i) - 'A' + offset)%AtoZ;
-
if((*(str+i) >= 'a') && (*(str+i) < ('a' + AtoZ)))
-
*(str+i)='a' + (*(str+i) - 'a' + offset)%AtoZ;
-
i++;
-
}
-
printf("encrypted str = \n%s \nlength = %d\n", str, l);
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: dot |
last post by:
Hi all, I have written a Python huffman Encoding Module, for my own
amusement. I thought it might be educational/entertaining for other
people, so I've put it on my website and wrote about it a little.
http://gumuz.looze.net/wordpress/index.php/archives/2004/11/25/huffman-encoding/
Your comments are highly appreciated!
cheers,
|
by: mubx2000 |
last post by:
Hi ,
I'm looking for code (Symbian C++) that can do the following things:
1-Analyzing the (MIME) types (Content-typemContent-transfere-encoding,Mime Version,Conent Description).
2-Download attached files from the (MMS/Email).
3-Uploading to email or (MMS) .
4-Dealing with Multi-Part Messages.
Here Is A Methods That Can HelP In doing Decoding:
|
by: KWSW |
last post by:
Having settled the huffman encoding/decoding and channel modeling(thanks to the previous part on bitwise operation), the last part would be hamming encoding/decoding.
Did some research as usual on hamming codes and how they work(well sort of) I got a general idea how to start constucting a (7,4) hamming code.
Unfortunately I have no idea how to start on the decoding/error correcting part and some direction would be nice.
---
for...
|
by: Michele |
last post by:
Hi there,
I'm using a python script in conjunction with a JPype, to run java classes.
So, here's the code:
from jpype import *
import os
import random
import math
import sys
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |