Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35188 > unrolled thread

Base64 encode using using windows-1250 encoding

Started byJupi <nomail@gmail.com>
First post2018-06-08 16:21 +0200
Last post2018-06-09 13:33 +0200
Articles 6 on this page of 26 — 8 participants

Back to article view | Back to comp.lang.javascript


Contents

  Base64 encode using using windows-1250 encoding Jupi <nomail@gmail.com> - 2018-06-08 16:21 +0200
    Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-08 20:26 +0200
      Re: Base64 encode using using windows-1250 encoding Jupi <nomail@gmail.com> - 2018-06-08 22:09 +0200
        Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-08 22:57 +0200
      Re: Base64 encode using using windows-1250 encoding Jupi <nomail@gmail.com> - 2018-06-09 07:02 +0200
        Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-09 09:25 +0200
          Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 09:52 +0200
            Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-09 10:12 +0200
              Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 10:25 +0200
          Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-09 09:53 +0200
            Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 10:01 +0200
              Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-09 10:17 +0200
                Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 10:32 +0200
            Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 10:02 +0200
              Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-09 10:20 +0200
                Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 10:29 +0200
                  Re: Base64 encode using using windows-1250 encoding Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-09 12:07 +0200
        Re: Base64 encode using using windows-1250 encoding "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-06-09 09:30 +0200
          Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 09:55 +0200
            Re: Base64 encode using using windows-1250 encoding "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-06-09 13:11 +0200
          Re: Base64 encode using using windows-1250 encoding Frank Kozuschnik <franko@nurfuerspam.de> - 2018-06-09 12:45 +0200
            Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 13:13 +0200
              Re: Base64 encode using using windows-1250 encoding Mickey Finn <mfinn@gmail.com> - 2018-06-14 19:22 -0300
    Re: Base64 encode using using windows-1250 encoding "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-06-09 12:30 +0200
      Re: Base64 encode using using windows-1250 encoding Jupi Krem <nomail@gmail.com> - 2018-06-09 13:14 +0200
      Re: Base64 encode using using windows-1250 encoding Yappi <nomail@gmail.com> - 2018-06-09 13:33 +0200

Page 2 of 2 — ← Prev page 1 [2]


#35209

FromFrank Kozuschnik <franko@nurfuerspam.de>
Date2018-06-09 12:45 +0200
Message-ID<pfgb4v$2mb$1@solani.org>
In reply to#35194
Evertjan.:

> Jupi:
> 
>>>> I need to encode string using Central European Windows-1250 encoding.
>>>> I know how to use simple base64 but it is utf-8 encoded and I need
>>>> windows-1250.
> 
> IMHO:
> 
> base64 translates ["encodes"] any string into a human-readable string.

Base64 does not encode "strings" (= sequences of characters); it encodes 
sequences of octets (bytes).

To "base64-encode a string", you actually perform two steps:

1. Apply a character encoding to transform the string into a sequence of 
bytes.
2. Base64-encode the result to get a sequence of base64 characters.

I guess Jupi just wants to use Windows-1250 encoding for step 1.

He could use this code on node.js:

   var windows1250 = require("windows-1250");
   var btoa = require('btoa');
   var bytes = windows1250.encode("Perišić");
   var b64 = btoa(bytes);

<https://runkit.com/embed/tqtkt1s6ik5n>

Result: b64 == "UGVyaZpp5g=="


> It should[!] not matter what is in the input string,
> or what encoding is used.

It actually does matter which encoding is used for step 1.

[toc] | [prev] | [next] | [standalone]


#35211

FromJupi Krem <nomail@gmail.com>
Date2018-06-09 13:13 +0200
Message-ID<pfgcpb$e3b$1@sunce.iskon.hr>
In reply to#35209
on 09.06.2018, Frank Kozuschnik supposed :
> Evertjan.:
>
>> Jupi:
>> 
>>>>> I need to encode string using Central European Windows-1250 encoding.
>>>>> I know how to use simple base64 but it is utf-8 encoded and I need
>>>>> windows-1250.
>> 
>> IMHO:
>> 
>> base64 translates ["encodes"] any string into a human-readable string.
>
> Base64 does not encode "strings" (= sequences of characters); it encodes 
> sequences of octets (bytes).
>
> To "base64-encode a string", you actually perform two steps:
>
> 1. Apply a character encoding to transform the string into a sequence of 
> bytes.
> 2. Base64-encode the result to get a sequence of base64 characters.
>
> I guess Jupi just wants to use Windows-1250 encoding for step 1.
>
> He could use this code on node.js:
>
>    var windows1250 = require("windows-1250");
>    var btoa = require('btoa');
>    var bytes = windows1250.encode("Perišić");
>    var b64 = btoa(bytes);
>
> <https://runkit.com/embed/tqtkt1s6ik5n>
>
> Result: b64 == "UGVyaZpp5g=="

Awesome. Thank you so much for this. It works perfect. :-)
>
>> It should[!] not matter what is in the input string,
>> or what encoding is used.
>
> It actually does matter which encoding is used for step 1.

[toc] | [prev] | [next] | [standalone]


#35236

FromMickey Finn <mfinn@gmail.com>
Date2018-06-14 19:22 -0300
Message-ID<pfupqo$1fio$1@gioia.aioe.org>
In reply to#35211
Jupi Krem wrote:
> on 09.06.2018, Frank Kozuschnik supposed :
>>
>> Base64 does not encode "strings" (= sequences of characters); it 
>> encodes sequences of octets (bytes).
>>
>> To "base64-encode a string", you actually perform two steps:
>>
>> 1. Apply a character encoding to transform the string into a sequence 
>> of bytes.
>> 2. Base64-encode the result to get a sequence of base64 characters.
>>
>> I guess Jupi just wants to use Windows-1250 encoding for step 1.
>>
>> He could use this code on node.js:
>>
>>    var windows1250 = require("windows-1250");
>>    var btoa = require('btoa');
>>    var bytes = windows1250.encode("Perišić");
>>    var b64 = btoa(bytes);
>>
>> <https://runkit.com/embed/tqtkt1s6ik5n>
>>
>> Result: b64 == "UGVyaZpp5g=="
> 
> Awesome. Thank you so much for this. It works perfect. :-)
>>
>>> It should[!] not matter what is in the input string,
>>> or what encoding is used.
>>
>> It actually does matter which encoding is used for step 1.

Thomas Lahn is always playing the role of Court Jester, except it is not 
fun.

[toc] | [prev] | [next] | [standalone]


#35208

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2018-06-09 12:30 +0200
Message-ID<pfga7a$1vv$1@solani.org>
In reply to#35188
On 08.06.2018 at 16:21, Jupi wrote:

> I need to encode string using Central European Windows-1250 encoding.
> I know how to use simple base64 but it is utf-8 encoded and I need
> windows-1250.

From reading the rest of the discussion so far, it seems to me that you
have some (UTF-16/UCS-2 encoded) string, and you want to base64 encode
the string's CP-1250 representation.  Since you have not told in which
environment you're working, and since some examples used “windows”, I
assume you're working in a browser enviroment, where, to my knowledge,
there is no readily available solution for this task.  You can, however,
write your own encoding function by doing the mapping manually.  A
simplified, inelegant and incomplete example:

    function encode(str) {
        var map = {"š": "\x9a", "ć": "\xe6"};
        var dest = "";
        Array.prototype.forEach.call(str, function (ch) {
            dest += ch in map ? map[ch] : ch;
        });
        return btoa(dest);
    }

    encode("Perišić");

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#35212

FromJupi Krem <nomail@gmail.com>
Date2018-06-09 13:14 +0200
Message-ID<pfgcq4$e3d$1@sunce.iskon.hr>
In reply to#35208
Christoph M. Becker presented the following explanation :
> On 08.06.2018 at 16:21, Jupi wrote:
>
>> I need to encode string using Central European Windows-1250 encoding.
>> I know how to use simple base64 but it is utf-8 encoded and I need
>> windows-1250.
>
> From reading the rest of the discussion so far, it seems to me that you
> have some (UTF-16/UCS-2 encoded) string, and you want to base64 encode
> the string's CP-1250 representation.  Since you have not told in which
> environment you're working, and since some examples used “windows”, I
> assume you're working in a browser enviroment, where, to my knowledge,
> there is no readily available solution for this task.  You can, however,
> write your own encoding function by doing the mapping manually.  A
> simplified, inelegant and incomplete example:
>
>     function encode(str) {
>         var map = {"š": "\x9a", "ć": "\xe6"};
>         var dest = "";
>         Array.prototype.forEach.call(str, function (ch) {
>             dest += ch in map ? map[ch] : ch;
>         });
>         return btoa(dest);
>     }
>
>     encode("Perišić");

Big THANK YOU. Yes it works awesome. Tahnk you so much. :')

[toc] | [prev] | [next] | [standalone]


#35213

FromYappi <nomail@gmail.com>
Date2018-06-09 13:33 +0200
Message-ID<pfgdua$f0s$1@sunce.iskon.hr>
In reply to#35208
Christoph M. Becker expressed precisely :
> On 08.06.2018 at 16:21, Jupi wrote:
>
>> I need to encode string using Central European Windows-1250 encoding.
>> I know how to use simple base64 but it is utf-8 encoded and I need
>> windows-1250.
>
> From reading the rest of the discussion so far, it seems to me that you
> have some (UTF-16/UCS-2 encoded) string, and you want to base64 encode
> the string's CP-1250 representation.  Since you have not told in which
> environment you're working, and since some examples used “windows”, I
> assume you're working in a browser enviroment, where, to my knowledge,
> there is no readily available solution for this task.  You can, however,
> write your own encoding function by doing the mapping manually.  A
> simplified, inelegant and incomplete example:
>
>     function encode(str) {
>         var map = {"š": "\x9a", "ć": "\xe6"};
>         var dest = "";
>         Array.prototype.forEach.call(str, function (ch) {
>             dest += ch in map ? map[ch] : ch;
>         });
>         return btoa(dest);
>     }
>
>     encode("Perišić");

In case someone else need it, here is complete example:
function encode(str) {
  var map = {"š": "\x9a", "Š": "\x8a", "đ": "\xf0", "Đ": "\xd0", "ž": 
"\x9e", "Ž": "\x8e", "č": "\xe8", "Č": "\xc8", "ć": "\xe6", "Ć": 
"\xc6"};
  var dest = "";
  Array.prototype.forEach.call(str, function (ch) {
  	dest += ch in map ? map[ch] : ch;
 	});
  return btoa(dest);
}

Thank you again, you made my day ;o)

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web