Small unique hash for Strings???

I have a list of Strings that can have maximum length 25.
I want to map each String to another unique String that is 25 character long.
One way i try was to use md5 (Java Security API) but the md5 hash(in hex) generated for
each String was around 40 character long! but i only have 25 character length
(yes i can not increase it due to some reason).
Is there any way to map a String on another hash or String that is unique?
regards,
TH

well, the md5 hash is 16 bytes. You can encode this as 32 characters using ASCII hex encoding. You can then keep the first 25 bytes and throw the rest away. That is one solution.
A better solution is to base64 encode the md5 hash. The base64 encoding of 16 bytes takes only 22 characters, so this is better.
When using md5, or any other cryptographic hash function, there is very small probability of having two strings hash to the same value at random. Using the methods outlined above, this probability is neglible. However, there are recent cryptanalytic results on md5 and even sha1 that show that, in certain scenarios, it may be much easier to choose a string that hashes to the same value as another string.
Perhaps the best option is to investigate algorithms for constructing what are called perfect hash functions. Just google "perfect hash function".

Similar Messages

  • Unique Hash Codes

    Hi
    I'm interested to know what the maximum String length is to guarantee a
    unique hashCode for each possible String value?
    Also, how would one go about calculating this value?
    Thanks

    JoachimSauer wrote:
    As you noted yourself a perfect hash is usually not necessary.
    But the answer is easy: a char are 16 bit in Java. A hashCode is an int, which is 32 bit. So you can only guarantee a perfect hash for Strings of length <= 2. Note that the hashCode() implementation in String does not implement such an algorithm, so you can even have collisions with 2 characters.So the answer is 1 ;-)

  • "buffer too small for string or missing null byte" inserting CR in excel

    I have created a Crystal Report based on below stored procedure.
    DELIMITER $$
    DROP PROCEDURE IF EXISTS `ww_test`.`PRD_Data_sp` $$
    CREATE PROCEDURE `ww_test`.`PRD_Data_sp` (in cyear int, in cmonth int, in groupby varchar(20), in Inv_type varchar(4))
    BEGIN
      select
              CASE WHEN groupby='Date' THEN  (p.FKDAT)
                   WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
              END ,
              sum(p.QTYSAM),
              sum(p.CASESSOLD),
              sum(p.SOLDDOL)
              from ww_test.prd_data p
              where (month(p.FKDAT)=cmonth and year(p.FKDAT)=cyear) and
                     ((p.FKART) is null or not(p.FKART in ("FAZ","ZMBB","FAS",Inv_Type))) and
                     ((p.AUART) is null or not(p.AUART in ("ZMBB")))
              Group by
                  CASE WHEN groupby='Date' THEN  (p.FKDAT)
                       WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
                  END
              Order by
                  CASE WHEN groupby='Date' THEN  (p.FKDAT)
                       WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
                  END;
    END $$
    DELIMITER ;
    I have used Add Command to create report based on this.
    call ww_test.prd_data_sp({?Year},{?Month},{?GroupBy},{?InvType});
    I am able to refresh the report in crystal and as well in Infoview without any problem.
    But when i try to insert this report in Excel using Live Office it gives me error. I able to insert other crystal reports without any problem.
    An error occurred while opening the report. The report does not exist; you have insufficient rights to open the report; or you cannot make a connection to the BusinessObjects Web Service. (LO 02010)
    Failed to open report (LO 26619)
    Cannot open report document 
    Buffer too small for string or missing null byte.
    can anyone suggest where i am going wrong? Any input is appreciated.
    Crystal Reports 2008
    Live Office XI 3.1
    BOEdge XI 3.1
    Xcelsius 2008
    Thanks ,
    Madhavi

    With the CurrentValue method
    Crpt.ParamFields[3].CurrentValue := memo1.Text;
    Is there another solution ?

  • Buffer too small for string - Crystal Report for Vs2010

    Hello,
        I have recently upgrade my VS2010 project to Crystal Report for Visual Studion 2010.
        I have some reports that contains more than 512 characters in the Report Comments section.
        When I try to do a RptDoc.SaveAs(vPath, false) the following error is raised:
    Buffer too small for string or missing null byte.
          at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.SaveAs in :line 0
          at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.SaveAs in :line 0
          at CrystalDecisions.CrystalReports.Engine.ReportDocument.SaveAs in :line 0
        This line SaveAs was working has expected with Crystal Report 2008. Any idea on why it is not working anymore.
    Thank you.
    Charles

    Hello Don,
        I have start a little project to retest the behavior.
       I have create a new report in Crystal Report 2008 just by clicking New, Finish and Save.
       In a new Windows Application in Vs2010 ,I have added the following Crystal Report Reference.
        CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0
       CrystalDecisions.Shared, Version=13.0.2000.0
    I have then try the following code and found out the limit of ReportComment is 511 but in the Crystal Report 2008 designer and runtime the limit did not apply.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim objRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
          Dim i As Integer = 0
          Try
             objRpt.Load("c:\temp\empty.rpt", CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
             Do
                i += 1
                objRpt.SummaryInfo.ReportComments = New String("X", i)
             Loop
             objRpt.SaveAs("c:\temp\dfh_save.rpt", False)
          Catch ex As Exception
             MsgBox("i: " & i)
             MsgBox(ex.Message)
          End Try
    End Sub
         I am able to put has many characters if I insert the report in the Vs2010 Solution.
         If you prefer I can send you my little project.
    Thank you.
    Charles
    <code> should be
    Edited by: Don Williams on Feb 4, 2011 12:47 PM

  • Generate Unique Hash Key in PL/SQL

    I have a document that i want to send to certain customers. What I've decided to do is send the customer a link to the document that will be stored locally on our server. Obviously for security reasons i don't want to simply send the sequential doc ID allowing customers to change the query string to get other information.
    What would be the best way in pl/sql to generate a unique hash key to include in the url? The key would have to be both unique and not easily edited by customers to view other documents.
    Any help would be much appreciated.
    Faoilean.

    faoilean wrote:
    I've been experimenting with SHA-1 and it works very well in producing a 40 character hash. My one concern is that for example hashing '1025' produces the following hash 'B74E9CAD775D997FC742B45E1BA7BD5295D63D13'.
    Would someone not just simply be able to use SHA-1 to create a hash for '1026' (since i'm using a sequential number for my input) and consequently retrieve somebody elses information and leave my system vulnerable?
    Might i be better off to encrytp the input?I thought the point was that the "user" would only be provided with the hash value as a reference to the document and they would not have a clue how to alter that hash value to another value in order to retrieve a different document. Surely they don't know that the hash value they have relates to '1025' so a) how would they know that they can obtain the hash for '1026' to get the next document and b) how would they go about creating their own hash values unless you somehow give them access to Oracle's DBMS_CRYPTO package?
    If you really want to be sure then you could also also incorporate the date/time of the document into the string that you hash, so they would have to a) have access to the dbms_crpto package, b) know the filename and the date/time of the document and c) know what order to combine those things (and the format mask you've used on the date/time etc.) to provide the correct hash to obtain the document.
    If you use encryption then you leave yourself open to decryption.
    If you use hash then this is generally a 1 way mechanism, hence details are better hidden.
    I think you'll find when it comes to things like password storage, most will use a 1 way hash (or similar) algorithm rather than an encrypted password so that the stored passwords can never be reverse engineered. Also, such password algorithms usually combine the username or some other feature to prevent two users with the same password getting the same hash value.

  • How to Genarate a Unique ID for each Payload in XI

    Hi,
    My Question is How to Genarate Unique ID for each Paylod that we send in a particular Interface.
    Is that we can do it in Mapping...If Yes, How its possible...
    Thanks
    Amaresh

    Hi Amaresh !
    XI generates and stamps a messageID to each message header. That ID is unique. You could use that one. To get that number from inside message mapping to put it in the payload, you could use a java UDF with this code:
    String msgid;
    java.util.Map map;
    map = container.getTransformationParameters();
    msgid = (String) map.get(StreamTransformationConstants.MESSAGE_ID);
    return msgid;
    Of course you can generate another number, but maybe you will need to use a common storage to avoid repeating the assigned numbers, and that will require more work.
    Regards,
    Matias.

  • Hashing a string

    Using Oracle 10g R2.
    I want to hash a string using SHA-1 and the documentation that comes with 10g R2 talks about using the DBMS_CRYPTO package. It apparently has a nice little Hash function where you pass it your string and the type of crypto you want to use.
    Unfortunately there isn't a DBMS_CRYPTO package.
    There is however a DBMS_CRYPTO_TOOLKIT package which also has a Hash function in it, but this seems to take a few more parameters including "Persona"'s etc. and there's no documentation on this package included in the Oracle documentation.
    All I want to do is generate a SHA-1 hash value for a string.
    Can anyone give me any pointers please.
    Cheers

    Through both TOAD and SQL*Plus (logged on as sys user) it doesn't exist...
    (output from SQL Plus session)
    SQL> exec dbms_crypto.hash('a');
    BEGIN dbms_crypto.hash('a'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'DBMS_CRYPTO' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    SQL> exec dbms_crypto_toolkit.hash('a');
    BEGIN dbms_crypto_toolkit.hash('a'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'HASH'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignoredThe dbms_crypto_toolkit exists, but not the dbms_crypto package.

  • Generate unique 10 char string

    Hi,
    i have to generate a unique 10 char string ( a string with length of 10 ) which has numbers and alphabets with no special characters, is there any code of doing it
    Ashish

    class UniqueString {
      private static final int NUM_CHARS = 10;
      private static int[] lastString = new int[NUM_CHARS];
      private static final String chars =
    "0123456789abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
      static String getUnique() {   
         char[] buf = new char[NUM_CHARS];   
         carry(lastString, buf.length-1);
         for(int i=0;i<buf.length;i++) {
           buf[i] = chars.charAt(lastString);
    return new String(buf);
    private static void carry(int[] ca, int index) {
    if(ca[index]==(chars.length()-1)) {
    ca[index]=0;
    carry(ca,--index);
    else ca[index]= ca[index]+1;
    public static void main(String[] args) {
    for(int i=0;i<10000;i++)
         System.out.println(UniqueString.getUnique());
    Guarenteed to be unique within one VM instance.
    matfud

  • Create unique handle for ALV grid layout

    Hi,
    in some generic classes we display internal tables in a grid. We want to activate the save&maintain layouts feature by passing the DISVARIANT structure, Here wen have to give Report and handle. As we display some more tables using the same method, we must set a unique handle so that saved ALV layouts do not get merged /confused. As we do not have a table name at this point, my idea is to create a hash key based on the fields in the field catalog (field catalog is only distinguishable object here).
    I need an algorithm to create the 4-character handle as a hash value based on the (concatenated) field names in field catalog.
    Or a better idea to create unique handles in the generic ALV calls in one program.
    Please: Serious answers only.
    Regards,
    Clemens

    Here it is
    function enqueuecomputehash.
    *"*"Lokale Schnittstelle:
    *"  IMPORTING
    *"     VALUE(INPUT) TYPE  STRING
    *"     VALUE(INPUT_LEN) TYPE  I
    *"     VALUE(HASH_LEN) TYPE  I
    *"  EXPORTING
    *"     REFERENCE(HASH) TYPE  STRING
    *"     REFERENCE(TIME_USEC) TYPE  I
    *"  EXCEPTIONS
    *"      INVALID_ARGUMENT
    field-symbols <text>.
    field-symbols <hash>.
    data: tmp_input type text8192.
    data: tmp_hash  type text8192.
    if input_len < 1 or hash_len < 1.
       raise invalid_argument.
    endif.
    assign tmp_input(input_len) to <text>.
    assign tmp_hash(hash_len) to <hash>.
    data: t1 type i,
          t2 type i.
    <text> = input.
    get run time field t1.
    call 'C_ENQ_WILDCARD' id 'TEXT'     field <text>
                          id 'TEXTHASH' field <hash>.
    get run time field t2.
    hash = <hash>.
    time_usec = t2 - t1.
    endfunction.

  • Compareto versus equals performance for strings equality

    Hi
    Just wanted to know whether compareto and equals method performance for checking whether the two strings are equal or not .
    Which one is good with respect to bytecode , speed performance.
    Im not asking for the difference, only asking which one is good to use most number of times for comparing two strings for equilaty.
    Thanks.

    Hi
    Ya they are both for different purposes. No doubt.
    t which one is faster among the two for string
    equality?
    compareto or equals.
    thanksHis point is that it doesn't matter. You shouldn't worry about optimization for small details like this. Unless you are profiling your code and find a large slowdown with that code, then don't worry about their performance. Use the one that best suits your purpose. If you want to know if they're equal, use equals(), if you want to know their order, use compareTo().

  • Does anybody know a reliable hashCode-function for strings?

    Hello,
    I would like to exchange hashcodes between clients and server, both running at different jre's (even msjvms are running it) - and for the same string they should be identical.
    Javadoc mentions that Object.hashCode() may vary from imlpementation, but I would need an implementation which would be consistent across jvms.
    Does anybody know a reliable function which does compute a integer-hash-value out of string?
    Reliable means that its quite unlikely that two different strings get the same hash-value (although I know this cannot be guaranteed 100%).
    Thanks in advance, lg Clemens

    Even the hashcode() API points out that
    it is just a suggestion that it returns the memory
    address of an object, an implementation that might
    differ from other JVMs. So if you'd rely on that
    behaviour, you'd need to check JVM vendors as well.True, and that is why you shouldn't rely on the fact that Object.hashCode returns the memory address, but I think it's safe to rely on the fact that String.hashCode returns the same hashCode on all platforms (if they are using the same Java version).
    The javadoc for String.hashCode says:
         * Returns a hash code for this string. The hash code for a
         * <code>String</code> object is computed as
         * <blockquote><pre>
         * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
         * </pre></blockquote>
         * using <code>int</code> arithmetic, where <code>s</code> is the
    * <i>i</i>th character of the string, <code>n</code> is the length of
    * the string, and <code>^</code> indicates exponentiation.
    * (The hash value of the empty string is zero.)
    * @return a hash code value for this object.
    So that contract must be fulfilled by all implementations.
    Kaj

  • IPhone 6Plus on every reboot after putting in my password it opens to a small window asking for apple id password

    everything works on phone and wow it's big compared to my iPhone 5s. went with space grey since i have had 3 white phones in a row. restored via iCloud backup. updated iTunes as i have about 3,000 songs. 250 bought the rest ripped to AAC from my cc's....what a pain but switched from my windows desktop to this new rMBP late 2013 for xmas and iTunes is slightly different on a mac than windows and where everything is stored on drive.
    anyhow problem is every time i reboot after putting in my password and arriving at whatever page i left at i get a very small window asking for my Apple id password. Now the top half is pre filled in with the email address i use for iCloud/itunes/apple/etc.
    i did see in settings there is a checkmark i cannot remove that says for apple password "ask immediately" there are no other choices. it can't be unchecked by any method i found.
    any help appreciated.

    In case anyone else gets this I hit cancel once and it has never come back.

  • Unique ID For Node Locking an Application?

    I want to restrict the computers that a client application can run on. My original idea was to refuse server access outside of a restricted set of MAC addresses, but it seems difficult to grab the MAC address in a platform neutral way. (assume DHCP evironment so IP addresses may not be stable). Does anyone know of a way to access a hardware unique ID for doing a sort of node locking?

    Would the CommAPI ( http://java.sun.com/products/javacomm/ ) and a dongle help?

  • Unique id for calling thread

    A stored proc can be called by any of the say 200 threads from within a pool of java connections that all sign on with say USER1. Another similar pool can call the same proc that are signed on with USER2. Inside the proc I need to store some SYS_CONTEXT info and retrive it within the same call. I cannot use a package HEADER variable beacuse this is not private to the thread. I cannot use a global variable in the package BODY because between storing the value in the BDY global variable and retrieving it another thread can call the same proc and access the BODY global variable.
    I decide to store in the info ina SYS_CONTEXT using a unique identifier for this thread as the ATTRIBUTE and the info in the VALUE. To compose the unique id for this thread I can issue the following SQl. Which combo will guarantee me a unique id for tis thread that called the stored proc. The calls are synchronous meaning once a thread obtains a connection from the pool to call the stored proc it does not give it up until the proc completes and returns a result to the thread.
    SELECT
    SYS_CONTEXT('USERENV','SESSIONID')
    ,SYS_CONTEXT('USERENV','SESSION_USER')
    ,SYS_CONTEXT('USERENV','SESSION_USERID')
    , ,SYS_CONTEXT('USERENV','SID')
    ,SYS_CONTEXT('USERENV','HOST')
    ,SYS_CONTEXT('USERENV','INSTANCE')
    INTO
    v_sessionid
    ,v_session_user
    ,v_session_userid
    ,v_host
    ,v_instance
    FROM
    DUAL
    ;

    Please don't abuse the forums by posting in many places.
    General Database Discussions

  • Unique id For System Message

    Dear all,
       Any one can please tell me the unique id for System Message.  Also i want to know the unique id for 'yes' and 'No' in System Message. Its very urgent
    Thanks in advance
    with Regards
    G.shankar

    System message has formtype = 0. The Yes and No button has no ids for sap, but when you want to press one of this button, use sendkeys as SBO_Application.SendKeys("") or tab for No (default is Yes).
    For accesing to correct system message, use some global variable and there before showing system msgbox set some value and compare it after showing.
    hope it helps

Maybe you are looking for

  • Web cam driver not found

    i have a hp pavillion dv6700 laptop,product no is KD311PA#ACJ.ITS WEB CAM IS NOT WORKING.i tried using youcam n lenovo web cam but no help.also the driver for this computer is also not displayed on your hp site. i'm currently using windows7 as os.

  • Problem in desktop layout in "Building fluid grid layouts in Adobe Dreamweaver CS6"

    In this tutorial you taught to design a responsive site ....but the Terrestrial Nursery completed page doesnot work well in Internet Explorer in 14 inches Square Monitor........that you have placed the three columns in the same alignment...but while

  • Pages having Korean font issues after iOS 7 update.

    iWork on my ipad and iphone cannot handle Korean font after iOS 7 update.  It displays Korean correctly in those documents I created before the recent iOS 7 update, but breaks down as soon as I try to edit them.  Anyone has the same problem with inte

  • Movies from my itunes to my husband's ipad?

    I  would like to copy movies from my itunes account to my husband's ipad. But he has a different itunes account. Can I do that and if so, how?

  • Dirt trapped inside camera lens

    Hi, I noticed a small speck of dirt on my N95 camera lens which cannot be wiped off. I looked at the lens under a 40X microscope and discovered that the dirt is trapped inside the glass cover. No wonder it cannot be wiped off! Not only that, I can se