aspose file tools*
The moose likes Java in General and the fly likes Encryption in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Encryption in Java" Watch "Encryption in Java" New topic
Author

Encryption in Java

Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
I need to write some codes to encrypt data and decrytp data using a set algorithm.
I am having some problems because I am not conversant with Java at all.
I have a system where all the ASCII and extended ASCII cahracters could be represented.
I mean all the characters used in written English words (0-191). The first 32 are unwritten.
That leaves us with 160 to use any way.

My Plan:

1. Establish a method of deriving my cipher from substituting and transposing the standard state.

2. I will have to write a code to identify all these ASCII characters (upper and lower cases are included) as a standard state. e.g 0-25 will be A-Z.
The only thing is that I will need to have a scope. My scope will be 16 by 16 square units or 16 rows by 16 columns.

3. Genrate some numbers (CPRNG) from an external context. I don't think PRNG or seeding will work for my purpose.

4. I will assign indices or numeric superscript to the characters in number #2.

5. I will map the numbers in #3 to corresponding supercript in #4: This is transposition and substitution.
You have to follow a certain order to fill in the scope. Note 256 element (this elements are accessed by numbbers) will be populated with 160 characters.
That will leave about 96 elements. We can populat this by repeating any character of our chosen. It must be done in way so that we can encrypt and decrypt.

6. Now you have a a cipher (no modular math). You can complicate things the more by defusing the repeats. How do you achieve this? You can do and xor or multiply(use the properties of modular math) the cipher obtained by numbers initialy obtained in #3. From here on you must use modular math.

7. You now have cipher2. You can keep the defusion up by multiplying cipher2 by cipher to obtain cipher3: You can multiply cipher3 by the numbers in #3 to obtain cipher4.

You can do this for the half the number of the 96 characters repeated to guarantee absolute encrypt and decrypt. What you will have is a cipher that have been moved around many
time and hard to crack because the method is very abnormal for this kind of stuff. So you use these by product to represent whatever you want to write.

8. Encryption: Make a key(it could be a short or long key of periods) add it to your plaintext which was rearranged with the cipher in view. Do the regular modular math and there is your
ciphertext.

9. Decryption will just be the reverse of the process in #8.

My problem is the #2 part. I guess we can start from there. Thanks a lot.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

well...good luck with this. We're happy to help, if you have any questions.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18989
    
  40


Am I reading this correctly? Are you looking to invent your own encryption algorithm?

Java has encryption algorithms built in -- AES, Triple DES, Blowfish, RSA, etc. -- unless this is a homework assignment, there isn't any reason to reinvent the wheel here.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Victor M. Pereira
Ranch Hand

Joined: Mar 02, 2012
Posts: 50
By simple curiosity, do you want to create your implementation of a standard encryption algorithm or are you trying to make a playfair cypher or viginere cypher?

From what I read it seems to be closest to the second one. If it is you could create a alphabet class that obtains the ascii code and compares it to the values acceptable.


regards,
Victor M. Pereira
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Victor M. Pereira wrote:By simple curiosity, do you want to create your implementation of a standard encryption algorithm or are you trying to make a playfair cypher or viginere cypher?

From what I read it seems to be closest to the second one. If it is you could create a alphabet class that obtains the ascii code and compares it to the values acceptable.


I am geared towards something different for a start. I have thought about this for ages. I am sure it will be impossible to explain it away in one piece. But it does have a semblance of all encryption systems. Typically, we have as I read it, symmetrical and assymetrical. I see many people discouraging me already. I know that am not great in java but I believe my math is sound. I am happy that you
did not discourage my intent.

My question to all those discouraging me is this: What do you thing AES is doing with Mixcolumn and Shiftrow?

So what do you say is we use a single move of a knight or a horse following the standard move in chess?

Don't you think it will achieve Shiftrows and mixcolumns absent rigourous codes?

This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computer. I say we better start chessing a better encryption system. In this case I propose an encryption system that is open source and yet secure. Oxymoron huh!!
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Henry Wong wrote:
Am I reading this correctly? Are you looking to invent your own encryption algorithm?

Java has encryption algorithms built in -- AES, Triple DES, Blowfish, RSA, etc. -- unless this is a homework assignment, there isn't any reason to reinvent the wheel here.

Henry


Well you could think am nut but am just afraid that AES is a matter of time.

My question to all those discouraging me is this is: What do you think AES is doing with Mixcolumn and Shiftrow?

So what do you say if we use a single move of a knight or a horse following the standard move in chess for the AES approach?

Don't you think it will achieve Shiftrows and mixcolumns absent rigorous codes which ligthens memory?

This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computers. I say we better start chasing a better encryption system. In this case I propose an encryption system that is open source and yet secure. Oxymoron huh!!
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jossy Johnson Um wrote:I see many people discouraging me already.


No, they're trying to inject a bit of realism, to make sure you have a clear picture of the playing field.

I believe my math is sound.


If you're truly interested in developing a new encryption algorithm, then your math will need need to be much, much better than just "sound". Algorithms in current use were developed by guys with PhDs, after months or years of research and rigorous study of the specific mathematical properties of the existing state of the art algorithms at the time.

What do you thing AES is doing with Mixcolumn and Shiftrow?


No idea what you mean by this. A better question would be: What, specifically and mathematically, is better about your approach than AES, RSA, etc.? What weaknesses do they have that you have overcome?

So what do you say is we use a single move of a knight or a horse following the standard move in chess?


What???

No idea what you're talking about here.

This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computer. I say we better start chessing a better encryption system.


Yes, it's true that weaknesses will probably be found eventually in today's state of the art approaches, or something like quantum computing will render them vulnerable to brute-force attacks. But just because something is different, that doesn't make it better. So, again, what specific improvements does your approach offer over others?

I propose an encryption system that is open source and yet secure. Oxymoron huh!!


Not an oxymoron at all. It has been known for quite a while now that trying to keep the algorithm secret is a huge weakness in an encryption approach. Better to assume the algorithm will be well known and well understood, and focus on making that algorithm uncrackable--that is, make it so that knowing the algorithm doesn't by itself enable you to decrypt a message.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18989
    
  40

Jossy Johnson Um wrote:
Well you could think am nut but am just afraid that AES is a matter of time.

My question to all those discouraging me is this is: What do you think AES is doing with Mixcolumn and Shiftrow?

So what do you say if we use a single move of a knight or a horse following the standard move in chess for the AES approach?

Don't you think it will achieve Shiftrows and mixcolumns absent rigorous codes which ligthens memory?

This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computers. I say we better start chasing a better encryption system. In this case I propose an encryption system that is open source and yet secure. Oxymoron huh!!



I am not trying to discourage you at all -- if your goal is to invent a new algorithm, then by all means go for it. I was just pointing out that you may not know that the algorithms are already implemented -- just in case, you didn't know.

Jeff Verdegan wrote:
This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computer. I say we better start chessing a better encryption system.


Yes, it's true that weaknesses will probably be found eventually in today's state of the art approaches, or something like quantum computing will render them vulnerable to brute-force attacks. But just because something is different, that doesn't make it better. So, again, what specific improvements does your approach offer over others?

I propose an encryption system that is open source and yet secure. Oxymoron huh!!


Not an oxymoron at all. It has been known for quite a while now that trying to keep the algorithm secret is a huge weakness in an encryption approach. Better to assume the algorithm will be well known and well understood, and focus on making that algorithm uncrackable--that is, make it so that knowing the algorithm doesn't by itself enable you to decrypt a message.


Agreed. Not only are the algorithms public, but many implementations are provided as source. The goal is to make an algorithm robust by having many of the best minds look for the weak spots -- not protect it by complexity, obfuscation, etc.

Henry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18989
    
  40

Jossy Johnson Um wrote:
This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computers. I say we better start chasing a better encryption system. In this case I propose an encryption system that is open source and yet secure. Oxymoron huh!!


Side discussion. Hopefully, it is interesting. A little history.... The DES standard was invented in the 1970s. And sometime in the 1990, it was broken. And it was broken via a brute force algorithm -- use a super computer and you can break the algorithm in a day or so (in theory). This was enforced with Triple DES, but since Triple DES was based on DES, people got paranoid and invented a ton of much stronger algorithms.

And another 20 years later, you have AES, RSA, Blowfish, etc. Many with ridiculously long keys. Many support variable sized keys, so you can balance your paranoia with the processing time that you are willing to endure..... which interestingly, means that with faster computers, you will have longer keys and hence, stronger encryption.

Once, I had to encrypt (for a really paranoid client) data with two different encryption algorithms. The reasoning is... it is unlikely that both algorithms will be broken at the same time, so when it happens, we can run with one good algorithm for the period of time needed to reprocess the data to replace the broken algorithm.


Here is a counter point.... Twenty years after DES was broken via brute force, it is still only broken by brute force -- and IMO, that is not really a feasible way to break an algorithm (too much work to be useful). Triple DES still has not been broken (even the version that uses a key length that is only double of the DES length key). Etc. And for my paranoid client? More than fifteen years later, neither algorithm has been broken.


Anyway, this is why I would rather use an encryption library -- as they are done by people who are much smarter, and definitely much much more paranoid than me.

Henry
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Jeff Verdegan wrote:
Jossy Johnson Um wrote:I see many people discouraging me already.


No, they're trying to inject a bit of realism, to make sure you have a clear picture of the playing field.

I believe my math is sound.


If you're truly interested in developing a new encryption algorithm, then your math will need need to be much, much better than just "sound". Algorithms in current use were developed by guys with PhDs, after months or years of research and rigorous study of the specific mathematical properties of the existing state of the art algorithms at the time.

What do you thing AES is doing with Mixcolumn and Shiftrow?


No idea what you mean by this. A better question would be: What, specifically and mathematically, is better about your approach than AES, RSA, etc.? What weaknesses do they have that you have overcome?

So what do you say is we use a single move of a knight or a horse following the standard move in chess?


What???

No idea what you're talking about here.

This is just a tip of the iceberg. Nothing is static with the advent of more and more powerful computer. I say we better start chessing a better encryption system.


Yes, it's true that weaknesses will probably be found eventually in today's state of the art approaches, or something like quantum computing will render them vulnerable to brute-force attacks. But just because something is different, that doesn't make it better. So, again, what specific improvements does your approach offer over others?

I propose an encryption system that is open source and yet secure. Oxymoron huh!!


Not an oxymoron at all. It has been known for quite a while now that trying to keep the algorithm secret is a huge weakness in an encryption approach. Better to assume the algorithm will be well known and well understood, and focus on making that algorithm uncrackable--that is, make it so that knowing the algorithm doesn't by itself enable you to decrypt a message.


Well, I have sat on your feedback and thought about it for more than a minute. Yes! They were trying to let me realize things I might have overlooked.
RSA is slow as we all know. AES has a funny s-box for mapping plaintext-cipher(Bruce Schneier noted that).
In theory we also know that OTP is uncrackable. Designing an algorithm that can embrace the OTP quality in an foreign context could probably yield a better result.
The key is to emulate something different in cryptographic approach.

For all those conversant with AES: The shiftrow and mixcolumn play a major role in the algorithm. We can make that faster while achieving similar or better defusion by using a single movement of a knight (in a standard chess).
Also note AES is of defined scope 128, 192, 256. My proposal will not be of any defined block at all. It will be aligned with the equation of irreducible polynomial while playing along an extensive Galois field(not just 2^8). We will
be playing in bits level i.e re-assigning the characters by gaining more space or elements in Galois Field. Substituting characters within elements of the Galois field and transforming them simultaneously. All these will happen upon a blue print
of open path in a knight's tour. This alone guarantees a CPRNG and through confusion. This part makes it really difficult because of the permutation involved when variables are repeated in the GF. For e.g 32^26 is the arrangement of 26 variables
within a 32 square unit or grid. Can you imagine 256 square unit to be filled with about 192 variables(characters). This is the main thing which sets this system apart from AES.

THERE ARE many algorithm for open knight's tour out there. None until now knows precisely how to use it for encryption. The numbers gives us CPRNG (external context added to the whole crypto idea) In a sense these numbers some how xors or multiplies out with plaintext; ciphertext to yield more primes. Again it will be like chess game in the background and that means someone will always win. If none wins it is a stalemate: Again in a stalemate someone will have more points than the other person. I think this system is viable when carefully examined but it is not the work of one person. I can't see it any other way after 10 years of self directed work I think this is ready.

There are more things that you will be surprised to have been worked out so far for your inquisitive mind. I only lack extensive and precise comprehension of java. My codes are not that sophisticated as yet. Thanks for your probing.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jossy Johnson Um wrote:
There are more things that you will be surprised to have been worked out so far for your inquisitive mind. I only lack extensive and precise comprehension of java. My codes are not that sophisticated as yet. Thanks for your probing.


Okay, well, I don't know enough about cryptography to know if any of what you said even makes sense (other than that the "chess game/someone always wins" bit is, shall we say, stretching things a bit). If you're convinced you're onto a better algorithm though, that's your call.

So, going back to your original post:

2. I will have to write a code to identify all these ASCII characters (upper and lower cases are included) as a standard state. e.g 0-25 will be A-Z.
The only thing is that I will need to have a scope. My scope will be 16 by 16 square units or 16 rows by 16 columns.
...
My problem is the #2 part. I guess we can start from there. Thanks a lot.


What specific problem are you having? There's not a whole lot of advanced Java knowledge needed for what you're trying to do. From what I understand (and I admit I don't really know much at all about cryptography), it will primarily be things like ADD, MUL, XOR, SHIFT, and some array manipulations. Where it might get trickier is if you're trying to do it in multiple threads, but I would save that until it's working in a single thread.

It's not clear what you're trying to do in #2 or what specific problem you're having with it (which was pointed out in the first reply in this thread, and which you have yet to address).
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Jeff Verdegan wrote:
Jossy Johnson Um wrote:
There are more things that you will be surprised to have been worked out so far for your inquisitive mind. I only lack extensive and precise comprehension of java. My codes are not that sophisticated as yet. Thanks for your probing.


Okay, well, I don't know enough about cryptography to know if any of what you said even makes sense (other than that the "chess game/someone always wins" bit is, shall we say, stretching things a bit). If you're convinced you're onto a better algorithm though, that's your call.

So, going back to your original post:

2. I will have to write a code to identify all these ASCII characters (upper and lower cases are included) as a standard state. e.g 0-25 will be A-Z.
The only thing is that I will need to have a scope. My scope will be 16 by 16 square units or 16 rows by 16 columns.
...
My problem is the #2 part. I guess we can start from there. Thanks a lot.


This is what I tried so far.



Jeff Verdegan wrote:What specific problem are you having? There's not a whole lot of advanced Java knowledge needed for what you're trying to do. From what I understand (and I admit I don't really know much at all about cryptography), it will primarily be things like ADD, MUL, XOR, SHIFT, and some array manipulations. Where it might get trickier is if you're trying to do it in multiple threads, but I would save that until it's working in a single thread.

It's not clear what you're trying to do in #2 or what specific problem you're having with it (which was pointed out in the first reply in this thread, and which you have yet to address).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Why have you written that array out? Why don’t you fill it with a pair of nested loops? Much less error-prone than counting. And I would have preferred to see the numbers in hexadecimal if they run in 16s.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

So, once again, what specific problem are you having?

All we know is that you're trying to "identify all these ASCII characters" (whatever that means) and that you "need to have a scope" (whatever that means) and that you're having some problem doing that.
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Jeff Verdegan wrote:So, once again, what specific problem are you having?

All we know is that you're trying to "identify all these ASCII characters" (whatever that means) and that you "need to have a scope" (whatever that means) and that you're having some problem doing that.


My problem is on how to effectively put all these stuff in a working code. It could be easier said than done. In any case do you think you can contribute at all. It seems to me that you are a bit cynical about it...
I take it that "whatever that means"; simply equates to the fact that you might not be familiar with this approach. i will like to know if you can help in knowing what it means in advance. Thank you very much.
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Campbell Ritchie wrote:Why have you written that array out? Why don’t you fill it with a pair of nested loops? Much less error-prone than counting. And I would have preferred to see the numbers in hexadecimal if they run in 16s.



I wanted to see if I can do it. Well, nested loop will be great, I read a little on it. I see my problem will be getting my numbers alligned in 16row by 16cols or 8 by 16 (rc). Do you have any ideas?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
It is really easy to fill 16 16‑member arrays with numbers. You simply need a loop. I think two loops nested inside each other would be much more elegant and efficient. You might find something in the Java Tutorials, but it is only a short section.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jossy Johnson Um wrote:
Jeff Verdegan wrote:So, once again, what specific problem are you having?

All we know is that you're trying to "identify all these ASCII characters" (whatever that means) and that you "need to have a scope" (whatever that means) and that you're having some problem doing that.


My problem is on how to effectively put all these stuff in a working code.


Right. Got that. But what in particular are you having trouble with. I see some code there, but I don't know in what way it doesn't meet your needs. "I don't know how to write the code to do (some broad task)" is not specific enough.

Do you not know how to populate an array in Java?
Do you not know how to do a bit shift in Java?
Do you not know how to do an XOR in Java?
What specific piece are you having trouble with?

In any case do you think you can contribute at all. It seems to me that you are a bit cynical about it...


Yes, I am cynical about the actual value of your encryption scheme, but that's not relevant. I'd be happy to try to help you with the Java parts that are giving you trouble if I knew what they were.

I take it that "whatever that means"; simply equates to the fact that you might not be familiar with this approach.


It's more than that. "Identify these ASCII characters" is a rather broad and general statement. What exactly do you mean by that, and what exact problem did you have writing the corresponding Java code?

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Earlier, I wrote:It is really easy to fill 16 16‑member arrays with numbers. You simply need a loop. . . .
You appear to know how to print the contents of that array, so you ought to be able to populate it. I suspect you might not even need such an array, if you can use the two hex numbers and add them together after a 4‑place bitshift to the left.
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Campbell Ritchie wrote:
Earlier, I wrote:It is really easy to fill 16 16‑member arrays with numbers. You simply need a loop. . . .
You appear to know how to print the contents of that array, so you ought to be able to populate it. I suspect you might not even need such an array, if you can use the two hex numbers and add them together after a 4‑place bitshift to the left.


Jeff Verdegan wrote:Do you not know how to populate an array in Java?
Do you not know how to do a bit shift in Java?
Do you not know how to do an XOR in Java?
What specific piece are you having trouble with?


To these questions, I am most deficient but I can learn. I have been reading up some.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jossy Johnson Um wrote:
Jeff Verdegan wrote:Do you not know how to populate an array in Java?
Do you not know how to do a bit shift in Java?
Do you not know how to do an XOR in Java?
What specific piece are you having trouble with?


To these questions, I am most deficient but I can learn. I have been reading up some.


I wasn't asking to try to belittle you or denigrate your Java knowledge. I was using them as examples of the kind of focused, specific topics that work best here. I honestly still nave no idea whatsoever what your Java question is.
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Jeff Verdegan wrote:
Jossy Johnson Um wrote:
Jeff Verdegan wrote:Do you not know how to populate an array in Java?
Do you not know how to do a bit shift in Java?
Do you not know how to do an XOR in Java?
What specific piece are you having trouble with?


To these questions, I am most deficient but I can learn. I have been reading up some.


I wasn't asking to try to belittle you or denigrate your Java knowledge. I was using them as examples of the kind of focused, specific topics that work best here. I honestly still nave no idea whatsoever what your Java question is.



However I can learn so where do you think I should start.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jossy Johnson Um wrote:
Jeff Verdegan wrote:I honestly still nave no idea whatsoever what your Java question is.



However I can learn so where do you think I should start.


Here maybe: http://docs.oracle.com/javase/tutorial/java/index.html

Or here or here (or the previous version, which is available free online here).
Jossy Johnson Um
Greenhorn

Joined: Feb 11, 2012
Posts: 13
Jeff Verdegan wrote:
Jossy Johnson Um wrote:
Jeff Verdegan wrote:I honestly still nave no idea whatsoever what your Java question is.



However I can learn so where do you think I should start.


Here maybe: http://docs.oracle.com/javase/tutorial/java/index.html

Or here or here (or the previous version, which is available free online here).


Thanks for your help. The site you shot at me looks more promising than the book I picked up at barnes and noble.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 877
    
    5
Henry Wong wrote:but since Triple DES was based on DES, people got paranoid and invented a ton of much stronger algorithms.

And another 20 years later, you have AES, RSA, Blowfish, etc.


Symmetric (e.g. 3DES) and asymmetric (e.g. RSA) schemes are different kinds of encryption serving different purposes.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Encryption in Java