How Can I Improve My Encryption Code?

  • Thread starter Thread starter kkissofdeath
  • Start date Start date
  • Tags Tags
    Homework
AI Thread Summary
The discussion revolves around a programming code snippet intended for encryption and decryption using a matrix key and prime numbers. The user seeks assistance in resolving issues with their code, which is meant to transform a plaintext message into ciphertext and vice versa. However, several participants express confusion about the user's request, noting that the code is poorly structured and lacks clarity regarding expected inputs and outputs. They emphasize the importance of providing clear details about the problem and suggest that the user should demonstrate some effort in troubleshooting the code. The conversation highlights the need for better formatting and clearer communication in programming queries, as well as the expectation for users to articulate their challenges more effectively.
kkissofdeath
Messages
3
Reaction score
0
I Need This Solved Please




Code

public class harness {
public static void main(String[] args) {
int[][] key = {{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

int direction = 1;
int[] primes = {2,3,5,7,11,13,17,19};
String plainString = new String("I PUT THE TEXT IN HERE");
char[] plainCharArray = plainString.toCharArray();
int[] plainIntArray = new int[plainCharArray.length];
int[] cipherIntArray = new int[plainCharArray.length];
char[] cipherCharArray = new char[plainCharArray.length];
for(int x =0; x<plainIntArray.length; x++)
plainIntArray[x] = (int)plainCharArray[x] -97;
for(int x = 0; x < plainIntArray.length; x++){
int k = 0;
for(int y = 0; y <8; y++){
k+= key[y][x%primes[y]] %26;
}
cipherIntArray[x] = (plainIntArray[x] +direction*k +260)%26;
}
for(int x =0; x< cipherIntArray.length; x++)
cipherCharArray[x] = (char)(cipherIntArray[x] +97);
String myString = new String(cipherCharArray);
System.out.println(myString);


}
}


for decription you enter the ciphertext at the same place, and you set direction to -1
the key is that matrix, the 1's are spots that can be entered, and the spots that are 0 do not change
by the way, everything is lowercase and there are no spaces
here is what is generated by encrypting my message to you guys:

charsxrowtrvizrrcvnlcftgdkhhnafgewhefszmfdwvqmvujqflkpapjwwhobliliodhlawtkkjwgzzhdzcqqxuywfwuhvaultavvemlfvmvoewlpqsjybrlrpdtnluyixodgahozgiswirvvikyhmeacnxhxpcfefptagvukxzumqlpshprzfsjrgvhjqmijbqrehcnavwalyuyxfluvvayseqmkaalvzkyvpflfxafywgcmhlfeaykncgguvlttziuwwjapupyublggnkygaasam






This Isnt Homework I've Done School
 
Technology news on Phys.org
It's not clear what you are asking for. And even if it isn't homework or coursework, you need to show some effort toward the solution that you are asking for.
 
Yes I Understand What This Site Is About I Think This Was Covered In School By Some1

I Just Didnt Do This Course

So I Figured What Might Be Hard For Me Would Be Easy For You?


I Honestly Cannot Tell You What Attempts I've Tried

When I Feel Like I am Getting Close To An Answer It Just Slips Away :(
 
It might be easy for us, but I can't tell what you're trying to do. Can you explain?
 
Its Programming..

This Is A Psysic's Forum Thats Y No Help :D

Sry Guys
 
I am a programmer. The code above is not even remotely valid code, with static void main() embedded inside a public class. For starters.

What are your expected inputs and outputs? Since you know programming, you also know that you surround code with code tags on a website, or nobody can read it.

Fix your code then do not tell us how YOU want to solve it programmatically. Tell us what you expect input and outputs to be. We'll be glad to help.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top