Is there a simple way to generate a un-duplicate string? - asp.net
I know I can use GUID to generate a unique string, but it's too long.
Now I only need generate un-duplicate string within an website, how can I do? Thanks!
For example: In the website http://mathurl.com/, you can generate a permanent URL, such as http://mathurl.com/75ujy7b and 75ujy7b is very short and un-duplicate.
First of all you can start with a counter that you make sure using Mutex/lock that return unique incremental numbers, and you save the last number somewhere on your site, maybe in web.config, maybe in database, or in a file.
Then you convert this unique number to a different base number, eg to a base-64. Here is some code, and mode details on how you can do that
https://stackoverflow.com/a/5901201/159270
And you can get results like
value: 0 encoded: A
value: 1 encoded: B
value: 9999999999 encoded: SrYsNt
value: 4294965286 encoded: ZNGEvT
value: 2292964213 encoded: rHd24J
value: 1000000000 encoded: TrNVzD
Now, if you scramble the map on the characters you can also make a not so easy to find number.
you can use a random number of sufficient length.. between lets say 10,000 and 99,999..
if that aint good enough for you, you could look into some hashing algorithms.. i think..
Related
ARM Template - complex calculation
numOfVolumes = round(-1.1966 + (27.0/400.0)*(((400*400) - ((400 - (vsnapSizeInGB/1024))**2))**0.5)) "copy": [ { "name": "dataDisks", "count":<formula to calculate amount of disks>, "input": { "diskSizeGB":<formula to calculate each disk size - besides maybe a leftover disk>, "lun": "[copyIndex('dataDisks')]", "createOption": "Empty" } } ] 2. I have the following password requirement to be validated in arm template, using regex looks difficult, is there a way I can a powershell command to validate the value of the parameter and then return true / false based on that the arm template throws an error. The minimum acceptable password length is 15 characters. There must be eight characters in the new password that are not present in the previous password(provided). The new password must contain at least one character from each of the classes (numbers, uppercase letters, lowercase letters, and other). The maximum number of identical consecutive characters that are allowed in the new password is three characters. The maximum number of identical consecutive class of characters that are allowed in the new password is four characters.
I recommend to use PowerShell to perform the calculation for numOfVolumes and then pass in the value as a parameter. If you must perform the calculation in an ARM template then I suggest you have a look at https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-numeric You're probably not going to enjoy writing the formula with: add, copyIndex, div, float, int, max, min, mod, mul, and sub. As for the question about a password generator, Google provides some good links, such as http://www.theservergeeks.com/how-to-powershell-password-generator/ Again, PowerShell will be the best bet on generating the type of password that meets your requirements.
Given final block not properly padded. Such issues can arise if a bad key is used during decryption
Hi guys I encrypted school project but my AES saved txt has been deleted, I pictured it before and I filled a new file. But new AES key file is not equal to the typed in jpeg file. Which character is wrong I couldn't find it. Could you please help me. Pic : https://i.stack.imgur.com/pAXzl.jpg Text file : http://textuploader.com/dfop6
If you directly convert bytes with any value to Unicode you may lose information because some bytes will not correspond to a Unicode character, a whitespace character or other information that cannot be easily distinguished in printed out form. Of course there may be ways to brute force your way out of this, but this could easily result in very complex code and possibly near infinite running time. Better start over, and if you want to use screen shots or similar printed text: base 64 or hex encode your results; those can be easily converted back.
SQLite X'...' notation with column data
I am trying to write a custom report in Spiceworks, which uses SQLite queries. This report will fetch me hard drive serial numbers that are unfortunately stored in a few different ways depending on what version of Windows and WMI were on the machine. Three common examples (which are enough to get to the actual question) are as follows: Actual serial number: 5VG95AZF Hexadecimal string with leading spaces: 2020202057202d44585730354341543934383433 Hexadecimal string with leading zeroes: 3030303030303030313131343330423137454342 The two hex strings are further complicated in that even after they are converted to ASCII representation, each pair of numbers are actually backwards. Here is an example: 3030303030303030313131343330423137454342 evaluates to 00000000111430B17ECB However, the actual serial number on that hard drive is 1141031BE7BC, without leading zeroes and with the bytes swapped around. According to other questions and answers I have read on this site, this has to do with the "endianness" of the data. My temporary query so far looks something like this (shortened to only the pertinent section): SELECT pd.model as HDModel, CASE WHEN pd.serial like "30303030%" THEN cast(('X''' || pd.serial || '''') as TEXT) WHEN pd.serial like "202020%" THEN LTRIM(X'2020202057202d44585730354341543934383433') ELSE pd.serial END as HDSerial The result of that query is something like this: HDModel HDSerial ----------------- ------------------------------------------- Normal Serial 5VG95AZF 202020% test case W -DXW05CAT94843 303030% test case X'3030303030303030313131343330423137454342' This shows that the X'....' notation style does convert into the correct (but backwards) result of W -DXW05CAT94843 when given a fully literal number (the 202020% line). However, I need to find a way to do the same thing to the actual data in the column, pd.serial, and I can't find a way. My initial thought was that if I could build a string representation of the X'...' notation, then perhaps cast() would evaluate it. But as you can see, that just ends up spitting out X'3030303030303030313131343330423137454342' instead of the expected 00000000111430B17ECB. This means the concatenation is working correctly, but I can't find a way to evaluate it as hex the same was as in the manual test case. I have been googling all morning to see if there is just some syntax I am missing, but the closest I have come is this concatenation using the || operator. EDIT: Ultimately I just want to be able to have a simple case statement in my query like this: SELECT pd.model as HDModel, CASE WHEN pd.serial like "30303030%" THEN LTRIM(X'pd.serial') WHEN pd.serial like "202020%" THEN LTRIM(X'pd.serial') ELSE pd.serial END as HDSerial But because pd.serial gets wrapped in single quotes, it is taken as a literal string instead of taken as the data contained in that column. My hope was/is that there is just a character or operator I need to specify, like X'$pd.serial' or something. END EDIT If I can get past this first hurdle, my next task will be to try and remove the leading zeroes (the way LTRIM eats the leading spaces) and reverse the bytes, but to be honest, I would be content even if that part isn't possible because it wouldn't be hard to post-process this report in Excel to do that. If anyone can point me in the right direction I would greatly appreciate it! It would obviously be much easier if I was using PHP or something else to do this processing, but because I am trying to have it be an embedded report in Spiceworks, I have to do this all in a single SQLite query.
X'...' is the binary representation in sqlite. If the values are string, you can just use them as such. This should be a start: sqlite> select X'3030303030303030313131343330423137454342'; 00000000111430B17ECB sqlite> select ltrim(X'3030303030303030313131343330423137454342','0'); 111430B17ECB I hope this puts you on the right path.
rewrite rules that converts tokens to integer parameters
After much wrestling with the idea of ranking records, I finally settled on numeric based scores for my documents, which I emit to have them sorted based on these scores. Now these numbers have meaning, where the 1st 2 digits represent a specific type of document. Therefore, to get documents of type 22 sorted based on their scores, I simply query the view with start key being 220000 and end key being 229999 This is all great and works, my problems occur when I try to use url rewrites. I'm basically trying to reroute: /_rewrite/rankings/{doctype} to /_list/rankings?startkey=xx0000&endkeyxx9999 where xx is the {doctype} my issue is with specifying rewrite rule: [ { "from":"rankings/:doctype", "to":"_list/rankings", "query": ??? //what will this be? ] How can I construct the start and end keys by appending 0000 and 9999 respectively? how can I specify a numeric value? since using place holder ":doctype" will result in a string type rather than a numberic type, resulting in a failed query even if I were to modify my pretty url to input both start and end keys. I worked around the issue by filtering the results in my list view (ignoring docs im not interested in from getRow()), my concern here, should I worry about efficiency of list function now? feel free to comment also on my sorting strategy .. would be interested to know how others solved their sorting and slicing problems with couchdb
Solution First, you should emit the type and the score separately in an array instead of concatenating them: emit([doc.type, doc.score], doc); Then you can rewrite like this [ { "from" : "rankings/:doctype", "to" : "_list/rankings/rankings", "query" : { "startkey" : [":doctype", 0], "endkey" : [":doctype", 9999] }, "formats": { "doctype" : "int" } } ] I tested it on CouchDB 1.1.1 and it works. Reference The relevant documentation is buried in this issue on JIRA: COUCHDB-1074 As you can see, the issue was resolved on April 2011, so it should work in CouchDB 1.0.3 and above.
Please help identify multi-byte character encoding scheme on ASP Classic page
I'm working with a 3rd party (Commidea.com) payment processing system and one of the parameters being sent along with the processing result is a "signature" field. This is used to provide a SHA1 hash of the result message wrapped in an RSA encrypted envelope to provide both integrity and authenticity control. I have the API from Commidea but it doesn't give details of encoding and uses artificially created signatures derived from Base64 strings to illustrate the examples. I'm struggling to work out what encoding is being used on this parameter and hoped someone might recognise the quite distinctive pattern. I initially thought it was UTF8 but having looked at the individual characters I am less sure. Here is a short sample of the content which was created by the following code where I am looping through each "byte" in the string: sig = Request.Form("signature") For x = 1 To LenB(sig) s = s & AscB(MidB(sig,x,1)) & "," Next ' Print s to a debug log file When I look in the log I get something like this: 129,0,144,0,187,0,67,0,234,0,71,0,197,0,208,0,191,0,9,0,43,0,230,0,19,32,195,0,248,0,102,0,183,0,73,0,192,0,73,0,175,0,34,0,163,0,174,0,218,0,230,0,157,0,229,0,234,0,182,0,26,32,42,0,123,0,217,0,143,0,65,0,42,0,239,0,90,0,92,0,57,0,111,0,218,0,31,0,216,0,57,32,117,0,160,0,244,0,29,0,58,32,56,0,36,0,48,0,160,0,233,0,173,0,2,0,34,32,204,0,221,0,246,0,68,0,238,0,28,0,4,0,92,0,29,32,5,0,102,0,98,0,33,0,5,0,53,0,192,0,64,0,212,0,111,0,31,0,219,0,48,32,29,32,89,0,187,0,48,0,28,0,57,32,213,0,206,0,45,0,46,0,88,0,96,0,34,0,235,0,184,0,16,0,187,0,122,0,33,32,50,0,69,0,160,0,11,0,39,0,172,0,176,0,113,0,39,0,218,0,13,0,239,0,30,32,96,0,41,0,233,0,214,0,34,0,191,0,173,0,235,0,126,0,62,0,249,0,87,0,24,0,119,0,82,0 Note that every other value is a zero except occasionally where it is 32 (0x20). I'm familiar with UTF8 where it represents characters above 127 by using two bytes but if this was UTF8 encoding then I would expect the "32" value to be more like 194 (0xC2) or (0xC3) and the other value would be greater than 0x80. Ultimately what I'm trying to do is convert this signature parameter into a hex encoded string (eg. "12ab0528...") which is then used by the RSA/SHA1 function to verify the message is intact. This part is already working but I can't for the life of me figure out how to get the signature parameter decoded. For historical reasons we are having to use classic ASP and the SHA1/RSA functions are javascript based. Any help would be much appreciated. Regards, Craig. Update: Tried looking into UTF-16 encoding on Wikipedia and other sites. Can't find anything to explain why I am seeing only 0x20 or 0x00 in the (assumed) high order byte positions. I don't think this is relevant any more as the example below shows other values in this high order position. Tried adding some code to log the values using Asc instead of AscB (Len,Mid instead of LenB,MidB too). Got some surprising results. Here is a new stream of byte-wise characters followed by the equivalent stream of word-wise (if you know what I mean) characters. 21,0,83,1,214,0,201,0,88,0,172,0,98,0,182,0,43,0,103,0,88,0,103,0,34,33,88,0,254,0,173,0,188,0,44,0,66,0,120,1,246,0,64,0,47,0,110,0,160,0,84,0,4,0,201,0,176,0,251,0,166,0,211,0,67,0,115,0,209,0,53,0,12,0,243,0,6,0,78,0,106,0,250,0,19,0,204,0,235,0,28,0,243,0,165,0,94,0,60,0,82,0,82,0,172,32,248,0,220,2,176,0,141,0,239,0,34,33,47,0,61,0,72,0,248,0,230,0,191,0,219,0,61,0,105,0,246,0,3,0,57,32,54,0,34,33,127,0,224,0,17,0,224,0,76,0,51,0,91,0,210,0,35,0,89,0,178,0,235,0,161,0,114,0,195,0,119,0,69,0,32,32,188,0,82,0,237,0,183,0,220,0,83,1,10,0,94,0,239,0,187,0,178,0,19,0,168,0,211,0,110,0,101,0,233,0,83,0,75,0,218,0,4,0,241,0,58,0,170,0,168,0,82,0,61,0,35,0,184,0,240,0,117,0,76,0,32,0,247,0,74,0,64,0,163,0 And now the word-wise data stream: 21,156,214,201,88,172,98,182,43,103,88,103,153,88,254,173,188,44,66,159,246,64,47,110,160,84,4,201,176,251,166,211,67,115,209,53,12,243,6,78,106,250,19,204,235,28,243,165,94,60,82,82,128,248,152,176,141,239,153,47,61,72,248,230,191,219,61,105,246,3,139,54,153,127,224,17,224,76,51,91,210,35,89,178,235,161,114,195,119,69,134,188,82,237,183,220,156,10,94,239,187,178,19,168,211,110,101,233,83,75,218,4,241,58,170,168,82,61,35,184,240,117,76,32,247,74,64,163 Note the second pair of byte-wise characters (83,1) seem to be interpreted as 156 in the word-wise stream. We also see (34,33) as 153 and (120,1) as 159 and (220,2) as 152. Does this give any clues as the encoding? Why are these 15[2369] values apparently being treated differently from other values? What I'm trying to figure out is whether I should use the byte-wise data and carry out some post-processing to get back to the intended values or if I should trust the word-wise data with whatever implicit decoding it is apparently performing. At the moment, neither seem to give me a match between data content and signature so I need to change something. Thanks.
Quick observation tells me that you are likely dealing with UTF-16. Start from there.