This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

generate unique fixed length code from a string

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

I have a unique string obtained by combining 2 values

>>id(unique)
>>subject(sometimes not unique , variable length)

i have a logic where iam getting a unique code whose length is proportional to subject, but i want a fixed length code

So my requirement is to encode this string to obtain a unique code(fixed length 16 letter) using java

in order to do this what algorithm or logic i need to follow

help is appreciated...

thanks in advance
 
Rancher
Posts: 43015
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

If the ID is already unique, then you could just append the subject to it, and truncate the result to 16 characters, no? If the result is less than 16 characters, pad it with some filler character (like spaces).
 
Swapna Parimishetty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Welcome to JavaRanch.

If the ID is already unique, then you could just append the subject to it, and truncate the result to 16 characters, no? If the result is less than 16 characters, pad it with some filler character (like spaces).




thanks alot for your reply

my encoding logic generates 24 letter unique code(including special symbols) but i want only 16 letter code(containing 0-9 and A-Z)

is there any way to get 16 letter unique code(containing 0-9 and A-Z) for 16 letter unique input string

thanks once again
 
Ulf Dittmer
Rancher
Posts: 43015
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already have a unique 16 letter input string, how would a "16 letter unique code" be any different? Can you give an example of both, so that we know what the result should be?
 
Swapna Parimishetty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:If you already have a unique 16 letter input string, how would a "16 letter unique code" be any different? Can you give an example of both, so that we know what the result should be?



You are correct but i dont want a meaningful unique code

i need a encoded string with (0-9 and A-Z) characters only

thanks for your immediate reply..
 
Ulf Dittmer
Rancher
Posts: 43015
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the code need to be cryptographically secure? If not, you could just run the 16 letter string you have through something like ROT-13.
 
Swapna Parimishetty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Does the code need to be cryptographically secure? If not, you could just run the 16 letter string you have through something like ROT-13.



there is no need of the code to be secured cryptographically

but i want the unique code containing just 0-9 and A-Z
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either generate a more helpful ID from the beginning, or use a known, reversible transformation to move between the non-numeric characters to alpha-numeric.

You might just be able to use a hashing algorithm and convert the result to base 36.
 
author
Posts: 23874
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back to the original question... I don't think that this is possible.

If one of the inputs is a variable length string, that can be any size, then there are unlimited number of possibilities. Now, if you want your code to be unique, then this also needs to be an unlimited number of possibilities -- which isn't possible if the code is restricted to a fix length.

Henry
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic