[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

how to encrypt string in easy way?

hello

im trying to encrypt  "jello252pop" into  "36bd893fgnb4874"

how can i do it?

any idea would b appreciate

thx
0
tom_mk
Asked:
tom_mk
  • 14
  • 10
  • 8
  • +4
1 Solution
 
petmagdyCommented:
ok what is the encryption technique that converted "jello252pop" into  "36bd893fgnb4874"?
0
 
tom_mkAuthor Commented:
i just make up s.t

i just want to demonstrate my idea

any easy way to encrypt s.t?

Thx
Tom
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
petmagdyCommented:
do u want a reveresable technique (Encypt and decrypt) or irreversable (one way encryption)?
0
 
tom_mkAuthor Commented:
reveresable technique
thx
Tom
0
 
mightyoneCommented:
what for, security or charactersafeness?

there are plenty of algorithms to use:

for encryption search web for bruce scheier, blowfish,...
for charsafety take UUencode, Base64,...

or are you looking for ideas how to crack an encryption?

there i suggest reading the red book.....
0
 
tom_mkAuthor Commented:
i have a few keys and their corresponding values...ie a -> 0,  b->1, c->2......how can i get the keys from their corresponding values??? for example

if i have the value "2" how can i get their keys which is "c"? how do i put them in a vector
0
 
mightyoneCommented:
so it is a one on one  algorithm? and you want to play around finding all corresponds?

trhen use a hashmap with key value, use the alphabet as key and add value for all knows and e.g. * for all unknown and then print your "cryptdata correspondiong to that"
0
 
tom_mkAuthor Commented:
says,,

i have "isa,nov30,2004"
wat is the easiest way to generate a combination of number and char out of those character??

this is wat im trying to find?

Tom
0
 
CEHJCommented:
What are you going to use this encryption for? Do you need to decrypt it?
0
 
tom_mkAuthor Commented:
yah

i also need to decrypt

Im planning to give my customer a discount code which is generated from their name and code expiry date.....
for instance "name: john HO, id : yuoyo123 , expiry date : nov 20, 2004"..I want to generate a number and character combination from those
data. I will then give that combination to my customer as a discount code
0
 
CEHJCommented:
If all you need is a discount code, all you need to do is generate an MD5 hash. This could be checked but not decrypted, but i don't see why you need to decrypt
0
 
objectsCommented:
so whats wrong with some of the examples already posted?
0
 
CEHJCommented:
You might also do something simpler like:

    String s = "jello252pop";
    int hash = s.hashCode() & Integer.MAX_VALUE;
    String customerCode = Integer.toString(hash, 36);
    System.out.println(customerCode);
0
 
objectsCommented:
> You might also do something simpler like:

and how would u reverse that?
0
 
CEHJCommented:
>>and how would u reverse that?

See my penultimate comment
0
 
objectsCommented:
read the requirements :)

0
 
CEHJCommented:
If you are certain you need to decrypt as well, then you can use something like this:


http://javaalmanac.com/egs/javax.crypto/PassKey.html

The parameter to this method would be your customer details

DesEncrypter(String passPhrase)
           
0
 
objectsCommented:
0
 
CEHJCommented:
>>Already been mentioned.

Post the link to where it was mentioned then please
0
 
tom_mkAuthor Commented:
the reason why i need to decrypt is.

when i receive back the code,
i only need to decrypt and see what the information inside.

and that, i think, easier that making another db to store those gave-away code and wat it meant

is that a good idea to do though?

Thx for any suggetion

tom
0
 
objectsCommented:
why do you need to actually encrypt the data?
Who are you protecting it against?

0
 
objectsCommented:
Why don't you want to store the discount details in your db?
How will you know who you've given what discount ot?
0
 
tom_mkAuthor Commented:
let say i wanna generate the discount code for my customer

wat is the best way to do?

Tom
0
 
objectsCommented:
Depends on your requirements
0
 
tom_mkAuthor Commented:
how can i reverse this?

// by CHEJ
    String s = "jello252pop";
    int hash = s.hashCode() & Integer.MAX_VALUE;
    String customerCode = Integer.toString(hash, 36);
    System.out.println(customerCode);
0
 
objectsCommented:
no
0
 
tom_mkAuthor Commented:
ToT'' too bad
0
 
objectsCommented:
what didn't you like about all the earlier suggestions, both one and two way?
Might help to determine what will meet your needs.

0
 
objectsCommented:
I posted another one way method earlier.
lots of two way methods have been posted, though I'm still not sure I understand why you need to encrypt a discount code.
0
 
NaeemgCommented:
Easy way.......
Make ur algorithms as,
get the int value of ur char. let suppose u want to encrypt the char 'A'
its code is 65 and after getting this code add 10  to it then it will become 75
and store it where u want,

on other end where u want to decrypt follow the same procedure said above only subtract 10 from ur char code. then u 'll get 65 and display its value.

0
 
objectsCommented:
If you're not storing the details of who is entitled to what discount then  you want to use a secure method, such as one of the ones mentioned earlier in the question.
Though storing the discount details in your database, would seem far more secure.
0
 
CEHJCommented:
>>how can i reverse this?

You can't reverse it, but you *cold* do the following:

a. check the original details against it
b. use it as a lookup key based on the customer details

Since you presumably will need some form of persistence to store data, it would probably be more useful in b
0
 
tom_mkAuthor Commented:
i tried

http://javaalmanac.com/egs/javax.crypto/DesString.html by GuJu23  

i like this one..

thx again for a lot of help, objects and CEHJ
0
 
objectsCommented:
No worries :)
0
 
CEHJCommented:
8-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 14
  • 10
  • 8
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now