base36 | Base36 implementation in golang | Dataset library

 by   martinlindhe Go Version: v1.1.0 License: MIT

kandi X-RAY | base36 Summary

kandi X-RAY | base36 Summary

base36 is a Go library typically used in Artificial Intelligence, Dataset applications. base36 has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

Implements Base36 encoding and decoding, which is useful to represent large integers in a case-insensitive alphanumeric way.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              base36 has a low active ecosystem.
              It has 38 star(s) with 9 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 0 open issues and 2 have been closed. On average issues are closed in 1 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of base36 is v1.1.0

            kandi-Quality Quality

              base36 has 0 bugs and 0 code smells.

            kandi-Security Security

              base36 has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              base36 code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              base36 is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              base36 releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.
              It has 184 lines of code, 14 functions and 3 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed base36 and discovered the below as its top functions. This is intended to give you an instant insight into base36 implemented functionality, and help decide if they suit your requirements.
            • DecodeToBytes converts base36 string to bytes .
            • EncodeBytesAsBytes converts a byte slice to a byte slice .
            • Encode encodes a uint64 to base36
            • Decode decodes a base 64 - encoded string
            • EncodeBytes encodes b as a string
            Get all kandi verified functions for this library.

            base36 Key Features

            No Key Features are available at this moment for base36.

            base36 Examples and Code Snippets

            About,Examples
            Godot img1Lines of Code : 13dot img1License : Permissive (MIT)
            copy iconCopy
            import "github.com/martinlindhe/base36"
            
            fmt.Println(base36.Encode(5481594952936519619))
            // Output: 15N9Z8L3AU4EB
            
            fmt.Println(base36.Decode("15N9Z8L3AU4EB"))
            // Output: 5481594952936519619
            
            fmt.Println(base36.EncodeBytes([]byte{1, 2, 3, 4}))
            // Outp  

            Community Discussions

            QUESTION

            How do I optimize serial communication for large data strings?
            Asked 2021-Dec-26 at 09:14

            I'm working with an Arduino Uno and WS2812b LED stripes.

            What I'm trying to do:

            So I've a 12 x 10 grid of LEDs and I've made a software that maps these LEDs to a texture of the same size, which I can draw to. I now want to make multiple textures and send them one by one to the arduino to create something like an animation, so that I don't have to code the pixel positions by myself.

            The problem:

            If I just sent this data over as numbers in a string, I'd need 120 * 12 Bytes = 1440 Bytes for the buffer size. I've tried to convert the numbers into hex values. But then I still need 960 Bytes for the buffer. Any higher bases won't help here, because even with base36 I'd need 2 characters to represent 255.

            My approaches:

            • I can change the buffer size for the Arduino to 960 but then the RAM is 99% used up and the arduino software tells me that stability problems can occour and I guess that is happening, because this approach does not work.
            • Another approach was to use ASCII characters for each value from 0 to 255. That could reduce the total amount of bytes to 480 but the Arduino only knows 128 and the first 32 are taken by the system.
            • I've also tried to send the data sequentially with different buffer sizes but the serial communication is to slow. You can see how it "draws" the image from top to bottom. So I really want to draw it all at once.

            Can I somehow extend the ASCII character table or make my own? Or can I send the raw byte data over to the arduino instead of using strings/char arrays?

            Or do you have other approaches? I'm really curious.

            ...

            ANSWER

            Answered 2021-Dec-26 at 08:13

            I have now a more or less good solution.

            I just send over the LED index as a hex string combined with a char that tells me if it turns on or off. That reduces the total amount to 360 Bytes but I can only set the colors on the arduino side.

            Source https://stackoverflow.com/questions/70480903

            QUESTION

            How to encode/decode a Uint8Array in Base36 in JavaScript?
            Asked 2021-Aug-16 at 12:19

            I want to encode and decode Bytes from an Uint8Array (or an ArrayBuffer) to/from a string in Base36. JavaScript has the toString and parseInt functions which both support base36 but I am not sure if first converting 8 Bytes to a 64 bit floating point is the right idea.

            In JS one can encode a BigInt (a number of arbitrary length) in Base36. However the other direction does not work.

            How can I do this?

            ...

            ANSWER

            Answered 2021-Aug-16 at 12:19

            QUESTION

            What kind of PRNG would match such scatter plots?
            Asked 2021-Aug-09 at 10:36

            I've been given the challenge to find the seed from a series of pseudo-randomly generated alphanumerical IDs and after some analysis, I'm stuck in a dead end that I hope you'll be able to get me out of.

            Each ID is obtained by passing the previous one through the encryption algorithm, that I'm supposed to reverse engineer in order to find the seed. The list given to me is composed of the 2070 first IDs (without the seed obviously). The IDs start as 4 alphanumerical characters, and switch to 5 after some time (e.g. "2xm1", "34nj", "avdfe", "2lgq9")

            This switch happens once the algorithm, after encrypting an ID, returns an ID that has already been generated previously. At this point, it adds one character to this returned ID, making it longer and thus unique. It then proceeds as usual, generating IDs of the new length. This effectively means that the generation algorithm is surjective.

            My first reflex was to try to convert those IDs from base36 to some other base, notably decimal. I used the results to scatter plot a chart of the IDs' decimal values in terms of their rank in the list, when I noticed a pattern that I couldn't understand the origin of.

            After isolating the two parts of the list in terms of ID length, I scatter plotted the same graph for the 4-characters IDs sub-list and 5-characters IDs sub-list, allowing me to notice the strange density patterns.

            After some analysis, I've observed 2 things :

            • For each sub-list, the delimitation between the 2 densities is 6x36^(n-1), n being the number of characters in the ID. In other terms, it is 1/6th of the entire range of values for a given ID length. The range of values is [0; (36^n)-1]
            • The repartition of those IDs in relation to this limit tends towards 50/50, half of them being above the 1/6th limit, half of them being under it.

            I've tried to correlate such a behavior with other known PRNG scatter-plots, but none of them matched what I get on my graphs.

            I'm hoping some of you might know about an encryption method, formula, or function matching such a specific scatter plot, or have any idea about what could be going on behind the scenes.

            Thanks in advance for your answers.

            ...

            ANSWER

            Answered 2021-Aug-09 at 10:36

            This answer may not be very useful but I think it can help. the graph plot you shown is most likely that it doesn't belong to one of the most known PRNG used and of course it would never belong to cryptographic PRNG.

            But I have a notice I dont know if it can help. This PRNG seems to have a full period equals to full cycle of numbers generated for a fixed character places. I mean it operate with a pattern for 4 digits then repeat pattern but with higher magnitude for 5 characters which will propably means that this same pattern of distribution will repeat for 6 characters but with higher magnitude.

            So, in summery, this can mean that this pattern can be exploited if you know what is the value of this magnitude so you know the increments for 6 characters graph plot and then you can just stretch the 5 characters graph on the Y-Axis to get some kind of a solution (which would be the seed for 6 characters graph).

            EDIT: To clear things more clearly regarding your comment. what I mean is that this PRNG generate random numbers but these random numbers would not be repeated to infinity instead there will be some point in time were the same sequence will be regenerated. The I've inadvertantly left behind a piece of information: confirm this since when it encounter same number generated before ( reached this point in time where same sequence is regenerated ). It will just add 1 extra character to the sequence which would not change the distribution on the graph but instead will make the graph appear like if it was stretched along Y-Axis (like if Y intercept of the graph function just got bigger).

            Source https://stackoverflow.com/questions/68704626

            QUESTION

            Preprocessing primary keys in a controller method's model type hinted route parameter
            Asked 2021-Mar-02 at 14:25

            I have some models where I use a custom non-sequential unique id, similar to a standard UUIDs. They are 64 bits long, which should last me over 8000 years, so I store them as an unsigned big integer.

            However as a base10 number they are a bit long and unwieldy at 19 digits. To help with this I can transform them into a base36 number (a string containing 0-9 and a-z). They max out at 15 chars, though it should be only 11 or 12 for the next 30 years or so.

            My question is whether there is a way to hook into Laravel's type hinted dependency injection so that a constructor method like this:

            ...

            ANSWER

            Answered 2021-Mar-01 at 07:22

            If I understood correctly, route binding will solve your problem:

            In your RouteServiceProvider's boot function:

            Source https://stackoverflow.com/questions/66385104

            QUESTION

            Curious about base36 encoding
            Asked 2021-Jan-20 at 13:29

            I want to base36 encode 128bit hexadecimal number, but 128bit exceeds the range of the largest number supported by c language. So, i can't get the value of 36 numbers by finding the remainder and finding the quotient.

            I'm curious about the internal algorithm in base36 that handles such long strings. I am wondering how to express the number that cannot be expressed in the number range of c language. Can you tell me about the algorithm for base36? Or, I would like a book or site for reference.

            ...

            ANSWER

            Answered 2021-Jan-20 at 13:29

            I am wondering how to express the number that cannot be expressed in the number range of c language.

            Consider an array of bytes. Those bytes consist of bits. Now, assume that the byte consists of 8 bits. Next, consider an array of 16 bytes. There are a total of 128 bits in that array. You can use the lowest element to represent the first 8 bits of a 128 bit integer, the next element to represent bits 8...15 and so on.

            That is how arbitrarily large integers can be represented in C: Using arrays of smaller integers each of the elements representing a high radix digit. In the scheme that I described, the number is represented using a radix of 256. You don't necessarily need to use an array of bytes. Typically, arbitrary precision math uses elements of the CPU word size for efficiency. In case of 32 bit element for example, that would be a radix of 4'294'967'296.

            In the base36 encoding, the radix i.e. the base of the represenation is - you may have guessed this - 36. It is a textual representation, so elements of the array are chars. Instead of using all 256 values, this representation only uses 36 of those values; specifically those values that encode the upper case latin letter characters and the arabic numeral characters.

            Can you tell me about the algorithm for base36?

            There are essentially two steps:

            • First convert the input data to radix-36.
            • Next map those digits to text so that the digit 0 maps to the character '0', the digit 10 maps to 'A' and 35 maps to 'Z'. You can iterpolate the mappings that I did not provide.

            Source https://stackoverflow.com/questions/65809905

            QUESTION

            Designing a URL Shortening service like TinyURL
            Asked 2020-Apr-22 at 12:55

            I'm reading an online document that explains how to design a url shortening service. The website is https://www.educative.io/courses/grokking-the-system-design-interview .

            In the section, Encoding actual URL, they said -> "We can compute a unique hash (e.g., MD5 or SHA256, etc.) of the given URL. The hash can then be encoded for displaying. This encoding could be base36 ([a-z ,0-9]) or base62 ([A-Z, a-z, 0-9]) and if we add ‘+’ and ‘/’ we can use Base64 encoding. A reasonable question would be, what should be the length of the short key? 6, 8, or 10 characters."

            "If we use the MD5 algorithm as our hash function, it’ll produce a 128-bit hash value. After base64 encoding, we’ll get a string having more than 21 characters (since each base64 character encodes 6 bits of the hash value).Since we only have space for 8 characters per short key, how will we choose our key then? We can take the first 6 (or 8) letters for the key. This could result in key duplication, to resolve that, we can choose some other characters out of the encoding string or swap some characters."

            I used online MD5 hash generator (http://onlinemd5.com/) and Base64 encoder (https://www.base64encode.org/) to verify the above. I used "www.yahoo.com" as the input string for MD5 hash and output is 1B03577ED104F16AADC00A639D33CB44 . Then I Base64 encoded it and got MUIwMzU3N0VEMTA0RjE2QUFEQzAwQTYzOUQzM0NCNDQ= with UTF-8 destination charset and Unix newline seperator.

            Can anyone explain if I'm doing it correctly? I see the number of characters are way more than 21.

            ...

            ANSWER

            Answered 2020-Jan-11 at 07:40

            The problem is that you are using the output of MD5 as a string of hexadecimal digits, and then base64 encoding that string. There's no reason to base64 encode that string - base64 encoding is intended for binary data. What you probably wanted to do is base64 the actual 128-bit binary value of the MD5 hash. Here is some Python code that does what I think you are trying to do:

            Source https://stackoverflow.com/questions/59692297

            QUESTION

            How do I convert a float to base36 in Python?
            Asked 2020-Apr-14 at 11:45

            I have been migrating javascript code to python and I am stuck trying to get a python version of Math.random().toString(36)

            I'm not sure how to do this since Math.random() returns a float, in python I have not been able to figure out how to convert a float to base36. From what I understand it's only int but then how does javascript do it?

            for getting a random float in python I just use the following:

            ...

            ANSWER

            Answered 2020-Apr-14 at 11:45

            Going from comments. In JS using base36 is done to generate random alphanumeric characters. That is 26 from the alphabet + 10 digits.

            In python you can generate a random alphanumeric string of a given length like this:

            Source https://stackoverflow.com/questions/61205931

            QUESTION

            Is it safe to store reset password token in html post form?
            Asked 2020-Feb-13 at 22:58

            I want to add reset/forgot password functionality to my personal express.js app. I decided to implement it in similar way how Django does it.

            Basically, it generates unique token based on user (id, hashed password, email, last login time and current time, all mixed with unqiue password and salt). Then, user receives that token in his "reset password link". Someone explained it better than me in one of stackoverflow answers.

            And here is the source code of Django PasswordResetTokenGenerator class

            I will post my javascript implementation on the bottom. It would be nice if you check it for possible flaws, but it is not my main question :)

            So, user gets e-mail with "reset password link". Link looks like this https://example.com/reset-password/MQ/58ix7l-35858854f74c35d0c64a5a17bd127f71cd3ad1da, where:

            • MQ is base64 encoded user id (1 in this example)
            • 58ix7l is base36 encoded timestamp
            • 35858... is actual token

            User clicks on link. Server receives GET request -> server checks if user with that id exist -> then server checks correctness of the token. If everything is OK, server sends user html response with "set new password" form.

            So far, everything was almost exactly the same how django does it (few minor differences). But now I want to do somewhat different. Django (after receiving GET request) establishes anonymous session, stores token in session, and redirect (302) to reset password form. There is no any sign of token on the client side. User fills a form, POST request is send to server with new password. Server checks token (stored in session) again. If everything is right - password is changed.

            For some reason (it will make my app a lot more complicated :)), I don't want to add anonymous session, I don't want to store token in session.

            I want to just take token from req.params -> escape it -> check if it is valid -> and send to user with form, like this:

            ...

            ANSWER

            Answered 2020-Feb-13 at 22:58

            From a security standpoint there isn't a huge difference between storing the reset token in the URL (a get variable) or in the form (as a post variable). In both cases anyone who has access to the URL is going to have access to reset the password.

            As you mention, you'll want to watch out for XSS attacks (embedding javascript in the token that then gets displayed in page), and validating that the token is just alpha numeric should resolve that particular issue. You'll also want to watch out for CORS style attacks as well, which most frameworks can handle for you.

            For me the other two things to consider are-

            1. That the token expires in a reasonable amount of time, as it basically is a password and can be used to take over an account.

            2. That notifications are sent after any password request, so that if the user did not purposefully reset their own password they can be made aware of the incident.

            Source https://stackoverflow.com/questions/60217576

            QUESTION

            Convert long integer(decimal) to base 36 string (strtol inverted function in C)
            Asked 2020-Jan-16 at 18:35

            I can use the strtol function for turning a base36 based value (saved as a string) into a long int:

            ...

            ANSWER

            Answered 2020-Jan-16 at 02:59

            There's no standard function for this. You'll need to write your own one.

            Usage example: https://godbolt.org/z/MhRcNA

            Source https://stackoverflow.com/questions/59751447

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install base36

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/martinlindhe/base36.git

          • CLI

            gh repo clone martinlindhe/base36

          • sshUrl

            git@github.com:martinlindhe/base36.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link