Welcome to PhoneASK, where you can ask questions and receive answers from other members of the community.

get hash from strings, like hashids

asked 8 days ago by Nenad Zivkovic

with the package hashids, I can get hash (and encode y decode) from numbers

var Hashids = require("hashids"),
    hashids = new Hashids("this is my salt", 8);

var id = hashids.encode(1);

exist some similar package for get hash from string ? (with encode/decode)

Your answer

1 Answers

answered 8 days ago by Michael Perrenoud
var Hashids = require("hashids");
var hashids = new Hashids("this is my salt");

var hex = Buffer('Hello World').toString('hex');
console.log (hex); // '48656c6c6f20576f726c64'

var encoded = hashids.encodeHex(hex);
console.log (encoded); // 'rZ4pPgYxegCarB3eXbg'

var decodedHex = hashids.decodeHex('rZ4pPgYxegCarB3eXbg');
console.log (decodedHex); // '48656c6c6f20576f726c64'

var string = Buffer('48656c6c6f20576f726c64', 'hex').toString('utf8');
console.log (string); // 'Hello World'

Related Questions

My question is relate to security level of JVM How we can we get the object from memory by proving hash code? Today i was thinking. I create an object of class A in an execution environment One. And g
Basically my program reads a text file with the following format: 3 chairs tables refrigerators The number on the first line indicates the number of items in the file to read. Here's my hash function
Say we've some strings like these and need the unit from them: 'rotate(90deg)' // 'deg'` 'rect(0 0 5px 5px)' // 'px' 'rgba(0, 0, 0, 0.5)' // '' How can i accomplish that?
The website is sort of a gallery. But to prevent duplicate entries. I want to match them. It wont be 100% bulletproof image match, but for my needs its absolutely perfect solution. Only problem is, th
May I know what is the keycode for hash sign (#)? I have searched through some resources but couldn't find. Is it possible to get keycode for this symbol? How about other punctuations? Thanks.
Possible Duplicate: How to extract a file extension in PHP? I have a variable $filename=filename.ext or $filename=filena.m.e.ext or so on.. How can i extract the extension (here ext) from the va
I have a problem, I only want to get the strings that contains up to 30 characters each time I run it. import random test=[test1 up to 30 characters, test2 passing 30 characters easy, test3 up to
I'm using JavaScript to turn user input into a String that looks like an array of hashes and pass it to a hidden field in a Rails form. I.e. something like this gets passed to my controller: <input
I am trying to pull numbers and dates from text using R. Say I have a vector of text strings, V.text. The text strings are sentences that contain numbers and dates. For example: listed on 2/14/2015 f
If I have a hash in ruby like this, first = {:a=>1,:b=>2,:c=>3,:d=>4,:e=>5} How can I achieve this by single line script second = {:a=>1,:c=>3,:e=>5} Thank you very much.
I'm looking for a hash function that: Hashes textual strings well (e.g. few collisions) Is written in Java, and widely used Bonus: works on several fields (instead of me concatenating them and applyi
I'm curious how others have solved this problem, and what problems might lurk behind the naive solution: I have a system which processes stock market data. There are tens of thousands of symbols, with
I have a row which contains 'asa' string in my MySQL database. Then I am trying to get result from query when input is like that 'asas2s' But I couldn't get result. My query is like that: SELECT * F
This question already has an answer here: How can I get file extensions with JavaScript? 20 answers I have a varable var file = testfile.txt; I am using the following script to find its exten
I have strings (called Alleles) in a table (called Antigens) that I'm having trouble sorting into the correct order. A representative sample set of Alleles maybe:- 01:01 01:02 02:01 04:01 09:01N 10:0
People search in my website and some of these searches are these ones: tapoktrpasawe qweasd qwa as aıe qwo ıak kqw qwe qwe qwe a My question is there any way to detect strings that similar to ones ab
I'm new to JS and I'm trying to figure out how I can take a list of hashes and convert them to one hash. For example, lst = [{a: 10, b: 2}, {a: 10, c: 5}, {a: 10, b: 2, d: 20}] to: hash
I have a column, 'col2', that has a list of strings. The current code I have is too slow, there's about 2000 unique strings (the letters in the example below), and 4000 rows. Ending up as 2000 columns
I'm trying to follow the Symfony Book and to get values from the inserted url. In my controller I have: namespace Developer\MarkBundle\Controller; use Symfony\Component\HttpFoundation\Response; use Sy
I'm kind of a newb with Redis, so I apologize if this is a stupid question. I'm using Django with Redis as a cache. I'm pickling a collection of ~200 objects and storing it in Redis. When I request th
What I am trying to do is create a 12 character id for articles on my website similar to how youtube handles their video id (http://www.youtube.com/watch?v=53iddd5IcSU). Right now I am generating an M
Following java code returns hash code of a string. String uri = Some URI public int hashCode() { return uri.hashCode(); } I want to translate this code to c++. Is there any function availabe in c+
I am building a forum site where the post is retrieved on the same page as the listing via AJAX. When a new post is shown, the URI fragment is changed (ex: .php#1_This-is-the-first-post). Also the tit
I have a class (MethodsClass) with methods signature: public double Method() And a DataGrid with ComboBoxColumn. The ComboBox has the names of all methods of MethodsClass. At runtime I need to invoke
I am trying to open a file which a user can set. In other words it will never be a set path or file. so when the user has selected the file they want to open this button below will open it. I have dec
I have the following strings in a text file test Table Name.type Market Drinks.tea I wana split the strings so that I get the following output ObjectName = Table AttributeName = Name Attribute Type
I'm trying to brush up on my LINQ by writing some simple extension methods. Is there any better way to write such a function as below that removes a given list of characters from a string (using LINQ)
I'm doing a work that imply the use of instructions to do certain operations in files, that will be read from an archive, or will be given by input. Precisely my question involves the operations with
I have a string like this: mysz = name=john age=13 year=2001; I want to remove the whitespaces in the string. I tried trim() but this removes only whitespaces before and after the whole string. I
What differentiates them generally? According to Wikipedia, a dictionary is synonymous with an associative array. abstract data type, collection, contains key-value pairs in which each key is allo
I am a newb and trying to work with a nested hash. I have a deck of cards represented as follows: deck_of_cards = { :hearts => {:two => 2, :three => 3, :four => 4, :five => 5, :six =>
I use an HMAC in both javasript and PHP and get two different values of the HMAC when I run both porgams with the parameters to both functions as variables. However, if I run them as string literals,
The users of my app have their points. I want to assign them different ranks based on their points. This is my rank mapping hash: RANKS = { (1..20) => 'Private' (21..40) => 'Corporal' (41..60) =
In C# Given a hash table like {id:'1', name:'foo'} How can I dynamically create an instance of a class that has the same members? public class product { public int id; public string name; } I know I'
I'm trying to build a hash from a Model. This is the type of hash I want to build. {United Sates => us, United Kingdom => uk .....} I have tried so many ways now I'm just going around i
I have such url - http://www.coolsite.com/daily-plan/#id=1 What the easiest way to parse that string and read a hash value (the value after #id=)? Thank you
In 64 bit Python 2.7.6 this is True, however in 32 bit Python 2.7.3 it is False: random.Random(hash(a)).random() == random.Random(a).random() So how does Python 2.7.3 hash strings used to seed ra
I would like to parse a string like this: -o 1 --long Some long string into this: [-o, 1, --long, 'Some long string'] or similar. This is different than either getopt, or optparse, which sta
The function levenshtein in PHP works on strings with maximum length 255. What are good alternatives to compute a similarity score of sentences in PHP. Basically I have a database of sentences, and I
Is there any way to get the title of a song if its being played from Spotify,Pandora or some other music app, Assuming the app supports iOS 5's or 6's.
I'm not very experienced in Regex. Can you tell me how to get a string value from between two strings? The subject will always be in this format : //subject/some_other_stuff I need to get the string f
I have a text file that contains this text: What's New in this Version ========================== -This is the text I want to get -It can have 1 or many lines -These equal signs are repeated througho
I have this string : # userid name uniqueid connected ping loss state rate # 529 2 arioch83 STEAM_1:0:86796179 55:58 99 0 active 80000 # 619 3 Snake STEAM_1:0:27678629 06:42 61 0 active 80000 # 62
I'm looking for a way to determine the differences between two strings, and highlight them in both strings. I would suspect that most 'diff' libraries won't work since they show differences in lines (
Is it possible to get window.location.hash on the server-side code alone? http://mysite.com/#here I want to get here
In red is using hash, I need to store hash key with multiple fields and values. I tried as below: client.hmset(Table1, Id, 9324324, ReqNo, 23432, redis.print); client.hmset(Table1, Id,
When I compile a c++ application I'm writing that makes use of hash_map, I get this warning on g++ 4.3.2: You are using the deprecated header . To eliminate this warning, use an ANSI-standard header f
What's the most efficient way to get all the hash keys from a given value. my_hash = {a=>aa, b=>bb, c=>bb} I want to give the hash bb as an input value and get all they keys (b
I wonder if something like this is possible without iterating over the whole hash: collection = { red: 1000, green: 120, yellow => 1, blue: 999 } Something like this: collection.next_key(:red) #
I am trying to get the first 10bits of sha256 hash as an integer, at the moment, I convert to a string and then trim that to 10 bits and convert back to an int. This seems quite convoluted, is there a
...