GithubHelp home page GithubHelp logo

Blowfish representation:hex to base64 about jot HOT 13 CLOSED

alfg avatar alfg commented on August 23, 2024
Blowfish representation:hex to base64

from jot.

Comments (13)

alfg avatar alfg commented on August 23, 2024

Hi @huisman,

Do you have any examples you can show me? I tried converting a few samples of the generated hex code to base64 and the string output is longer, it seems.

A simple "Hello, World!" with a key of foobar outputs the following hex:
5689482A359F2AA08AEC0A4C0B19647EFED77C945C3B7EA3

Then converting to base64:

$ echo "5689482A359F2AA08AEC0A4C0B19647EFED77C945C3B7EA3" | base64
NTY4OTQ4MkEzNTlGMkFBMDhBRUMwQTRDMEIxOTY0N0VGRUQ3N0M5NDVDM0I3RUEzCg==

I also tried a paragraph of Lorem Ipsum with foobar as the key. The hex output was 1826 characters compared to 2469 when the hex is converted to base64.

Maybe it depends on the key size and/or text, or perhaps I'm misunderstanding your question. Can you provide the sample you tried?

Thanks,
Alf

from jot.

brenthuisman avatar brenthuisman commented on August 23, 2024

Hey @alfg,

Simply converting a hex-string to base64 doesnt increase the number of bits per char, as the conversion treats the input sequence naively as a string. But since a hex char encodes 4 bits, and a base64 char 6 bits, we need to convert the hex string to a bit representation and then express that number in base64 in order to get to the shorter string. base64.js only features UTF* <-> base64 conversion, so I suppose we need to find/write a routine that converts hex-chars and put that in front of the blowfish.js in-/output.

Is that more clear? I don't really know javascript, but I found one that appears to do what is required: http://en.ahotoke.com/tools/hexbase64.html

Cheers!

from jot.

alfg avatar alfg commented on August 23, 2024

Alrighty. So I've added an implementation of converting Hex<->Base64 based off of the link you referred to. Thanks!

Here is a sample:
http://alfg.co/jot/#brLFB58KKrzmc8U7Gpry9k3LsiGDKPM50H+0e/PikHTlx7VniPUVijMmrzRyZeiR9/td8lFw7fqM=
(key=foobar)

Compared to just the hex value:
ACB141E7C28AAF399CF14EC6A6BCBD9372EC8860CA3CCE741FED1EFCF8A41D3971ED59E23D45628CC9ABCD1C997A247DFED77C945C3B7EA3

Seems much shorter now after a few tests. Thanks for your help on this. Let me know if if you see any problems with the implementation.

Alf

from jot.

brenthuisman avatar brenthuisman commented on August 23, 2024

A that's great! The URLs are shorter here too. Nice work!

Small detail: perhaps it'd be nice that after you press Decrypt the regular Save/Clear/Add key buttons return.

from jot.

alfg avatar alfg commented on August 23, 2024

Thanks for testing it out!

The Clear button will make the regular buttons return. I leave the Decrypt button there for when you try decrypting with the wrong key, you won't have to refresh to try again. I haven't thought of a way to validate if the decryption was successful or not.

from jot.

brenthuisman avatar brenthuisman commented on August 23, 2024

The downside is that currently you need to copy, clear and paste to edit a protected text. You could add a second control char (after e) but ecrypted with the key. If after decryption this char is correct, you'll be good to go.

from jot.

alfg avatar alfg commented on August 23, 2024

Thanks for the suggestion. I will look into this.

from jot.

brenthuisman avatar brenthuisman commented on August 23, 2024

I discovered a bug that shows on messages of (at least) 1420 chars (I havent pinned down the exact number) that are encrypted. After decryption the last character of the original message is missing.

from jot.

alfg avatar alfg commented on August 23, 2024

Thanks, looking into this. I noticed it happens on some shorter messages after playing around with some variations. Not sure what is causing it yet.

http://alfg.co/jot/#bYwoTigrPd6TpdG4Z2+3p9hMv3b9w+Zrt (key=test)

It cuts off the trailing e in message.

from jot.

 avatar commented on August 23, 2024

Hi @alfg,

About the bug, I tried this code.

for (var i = 1, bf = new Blowfish("test"), a = []; i < 50; ++i)
  if (bf.decrypt(bf.encrypt(Array(i + 1).join("a"))).length !== i)
    a.push(i);
alert(a); //1,9,17,25,33,41,49

I guess that blowfish.js cause this bug when a number of characters is 8 * n + 1.
I found the library.
https://github.com/takezoh/blowfish.js
(en|de)crypt64 method is useful.
Maybe you dont need hexBase64.js.
Thank you.

from jot.

alfg avatar alfg commented on August 23, 2024

Thank you, @imu0x10! I will test out this library later tonight.

from jot.

alfg avatar alfg commented on August 23, 2024

Hi @imu0x10 and @huisman,

http://alfg.co/jot/ is now up to date with the updated blowfish.js library mentioned above and is also using the encrypt64/decrypt64 methods as well. The issue seems to be fixed for some samples I've tried. Go ahead and give it a shot and close ticket or respond if you still have any issues.

Thanks again!

from jot.

brenthuisman avatar brenthuisman commented on August 23, 2024

Excellent, the bug seems to be gone now! Thanks @imu0x10, @alfg!

from jot.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.