YouTube Unique Identifier [duplicate] - c#

This question already has answers here:
YouTube URL algorithm?
(11 answers)
Closed 3 years ago.
I noticed on YouTube their keys look like this "BwgT06NY1FE". I was just wondering how is this type of key created? Is this based on a GUID?

This is most likely Base36. All letters and numbers. It's pretty common, because you can use a "SERIAL" in a database and just increment it, and then just parse from Base36 in your URL.
It makes for nice URLs (bit.ly also uses this format), but has some drawbacks. Ie, you wouldn't want to use it for any sort of private data because people can just type in a random number and get a result (it's unlikely someone could guess a GUID in use by your database unless they try a few billion)..

Related

Can two guids (keys) be the same? [duplicate]

This question already has answers here:
Is a GUID unique 100% of the time?
(24 answers)
Are GUID collisions possible?
(19 answers)
Closed 9 years ago.
I generate keys for my software as:
Guid.NewGuid().ToString();
that returns something like: 15c6bd70-8d3c-42d0-bb24-40da6e08ed9d
anyways everytime someone purchases a new software I generate a new key. can it be possible that I generate the same key twice? Everytime someone purchase the software I call the method: Guid.NewGuid().ToString() Should I append a counter at the end of each guid to be 100% sure that there cannot be duplicates?
Edit
A constructor of the Guid class takes a byte array of 16 bytes as a parameter. If you serialize the current date (8 bytes) then append another 8 random bytes to the constructor of the GUID will that be 100% secure? I am just asking for learning based on your answers I will probably just have Guid.NewGuid()
An excerpt from one of the best blog series ever written about the Guid:
There are a number of possible strategies for making a unique GUID, and in fact information about the strategy used is encoded in the first four bits of the third "group"; almost every GUID you see will be of the form {xxxxxxxx-xxxx-1xxx-xxxx-xxxxxxxxxxxx} or {xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx}.
If there is a one in that place then the algorithm used to guarantee uniqueness is essentially a variation on the ISBN strategy. The GUID is guaranteed to be unique "in space" by choosing some of the bits as the MAC address of the network card in the machine. (The tricky problem of ensuring that no two network cards in the world have the same MAC address is solved somehow by someone else; how that problem is solved, we don't particularly care. The cost of solving that problem is passed on to you, the consumer, in the purchase cost of the network card.)
In short, it's very unlikely that they would ever collide.
Yes, it's possible, but extremely unlikely. The probability for a GUID collision is about as likely as a bit in the GUID changing spontaneously in memory, and that kind of thing is not something that you normally worry about.
You can already be 100% sure, that is of course if you dont mean that you need to be 100.000000000000000000000000000000000000% sure.
Just use the Guid.. no need to append anything. Unless you expect to sell more copies than there are atoms in the universe (unlikely).

C# is valid UTF-8 [duplicate]

This question already has answers here:
Determine a string's encoding in C#
(10 answers)
Closed 9 years ago.
I have a string read as a UTF8 (not from a file, can't check BOM).
The problem is that sometimes the original text was formed with another encoding, but was converted to UTF8 - so the string is not readable, sort of gibberish.
is it possible to detect that this string is not actual UTF8?
Thanks!
No. They're just bytes. You could try to guess, if you wanted, by trying different conversions and seeing whether there are valid dictionary words, etc., but in a theoretical sense it's impossible without knowing something about the data itself, i.e. knowing that it never uses certain characters, or always uses certain characters, or that it contains mostly words found in a given dictionary, etc. It might look like gibberish to a person, but the computer has no way of quantifying "gibberish".

Why does RSACryptoServiceProvider.SignHash have a "hash algorithm identifier" parameter? [duplicate]

This question already has answers here:
Why does SignHash need to know what hash algorithm was used?
(2 answers)
Closed 9 years ago.
Since RSACryptoServiceProvider.SignHash signs an already hashed message - why does it need to know which hash algorithm was used?
It seems that in order to make the signature more useful to the recipient, the OID of the hashing algorithm that was used is included in the signature (per PKCS1). That way, it does not have to be communicated separately.

Realtime complination in C# [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Is there a method that will evaluate a string and produce an integer (assuming the string is an equation) in C#
Hi all, i just wonder how to make a realtime complination in C#
For example: i have a string like this
string math = "1 + 2 + (4 - 6)";
And i want to complie it to get the result
How to do that? and is that the bad idea because i want to make a calculator in C#?
Edited:
The main question properly is that i want to do it in WP7, not exactly in C# windows lol, i tried all the solutions below but not at all is correct!
and is that the bad idea because i want to make a calculator in C#?
One problem with that is that your calculator language is probably supposed to be just a subset of C#. So using the C# compiler may be too flexible and allow arbitrary C#. Kind of like problems with SQL injection attacks.
Expresion Evalution is an application of STACK (Data Structure)
You can see these link If you want Sample projects
http://www.vbforums.com/showthread.php?t=397264
http://www.codeproject.com/KB/cs/runtime_eval.aspx
http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx

C# - Which is faster: String.Contains() or Regex.isMatch()? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Regex.IsMatch vs string.Contains
Which is faster, preferable and why?
What the difference in mechanisms between two?
I need to search for some values from UserAgent, most of values can be used without wildcards (e.g. if I want to catch cellular phones I search for iPhone instead of *iPhone* wildcards).
What is faster
Try measuring. But this is the wrong question, see below.
preferable
If I want to match a fixed string String.Contains does just what I need. If I need to pattern match, then String.Contains is useless.
Comparing the performance of these is irrelevant, they do completely different things. Use the right tool first, and only then if your performance is a problem use profiling to identify hot parts of your code to look at.

Categories