Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 196221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:44:56+00:00 2026-05-11T16:44:56+00:00

I need a quick checksum (as fast as possilbe) for small strings (20-500 chars).

  • 0

I need a quick checksum (as fast as possilbe) for small strings (20-500 chars).

I need the source code and that must be small! (about 100 LOC max)

If it could generate strings in Base32/64. (or something similar) it would be perfect. Basically the checksums cannot use any “bad” chars.. you know.. the usual (){}[].,;:/+-\| etc

Clarifications

It could be strong/weak, that really doesn’t matter since it is only for behind-the-scenes purposes.

It need not contain all the data of the original string since I will be only doing comparison with generated checksums, I don’t expect any sort of “decryption”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:44:56+00:00Added an answer on May 11, 2026 at 4:44 pm

    Quick implementation in C, no copyrights from my side, so use it as you wish. But please note that this is a very weak “checksum”, so don’t use it for serious things 🙂 – but that’s what you wanted, isn’t it?

    This returns an 32-bit integer checksum encoded as an string containing its hex value.
    If the checksum function doesn’t satisfy your needs, you can change the chk += ((int)(str[i]) * (i + 1)); line to something better (f.e. multiplication, addition and bitwise rotating would be much better).

    EDIT: Following hughdbrown’s advice and one of the answers he linked, I changed the for loop so it doesn’t call strlen with every iteration.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string>
    
    char* hextab = "0123456789ABCDEF";
    
    char* encode_int(int i) {
      char* c = (char*)malloc(sizeof(char) * 9);
    
      for (int j = 0; j < 4; j++) {
        c[(j << 1)] = hextab[((i % 256) >> 4)];
        c[(j << 1) + 1] = hextab[((i % 256) % 16)];
    
        i = (i >> 8);
      }
      c[8] = 0;
    
      return c;
    }
    
    int checksum(char* str) {
      int i;
      int chk = 0x12345678;
    
      for (i = 0; str[i] != '\0'; i++) {
        chk += ((int)(str[i]) * (i + 1));
      }
    
      return chk;
    }
    
    int main() {
      char* str1 = "Teststring";
      char* str2 = "Teststring2";
    
      printf("string: %s, checksum string: %s\n", str1, encode_int(checksum(str1)));
      printf("string: %s, checksum string: %s\n", str2, encode_int(checksum(str2)));
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some (small amount) of data that I'll need quick access to on
Need Quick and fast list of configuration changes required while moving from single-tier to
What are your best usability testing tips? I need quick & cheap.
I need a quick algorithm to select 5 random elements from a generic list.
I need a quick easy way to get a string from a file in
I need a quick yes/no answer on this... Is it possible to get a
I need a quick way to find out if a given port is open
I need a quick no for DELETE/UPDATE/INSERT, since 3p reporting tool allows users to
What do the result codes in SVN mean? I need a quick reference.
I need a very quick fix in a mod_rewrite expression for drupal we have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.