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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top