• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

generate unique fixed length code from a string

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic