mIRC Home    About    Download    Register    News    Help

Print Thread
convert base64 to jpg? #252941
18/05/15 02:27 AM
18/05/15 02:27 AM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
Perl  Offline OP
Ameglian cow
P

Joined: May 2014
Posts: 35
Hello, I would like to convert an encoded base64 I've read email, to its original format jpg file.
by socket I read this;

R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZ
u6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABA
AAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGI
gUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7

Is it possible to convert base64 encoded in a file photo.jpg to do with any photo viewer? greetings

Re: convert base64 to jpg? [Re: Perl] #252946
18/05/15 11:58 AM
18/05/15 11:58 AM
Joined: Jan 2004
Posts: 1,271
L
Loki12583 Online
Hoopy frood
Loki12583  Online
Hoopy frood
L

Joined: Jan 2004
Posts: 1,271
Code:
alias saveb64 {
  bset -t &b 1 $1
  var %file = $qt($$2-)
  if ($decode(&b,mb)) {
    bwrite %file -1 -1 &b
  }
}

Re: convert base64 to jpg? [Re: Loki12583] #252947
18/05/15 12:21 PM
18/05/15 12:21 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
Perl  Offline OP
Ameglian cow
P

Joined: May 2014
Posts: 35
Originally Posted By: Loki12583
Code:
alias saveb64 {
  var %file = $qt($1)
  bset -t &b 1 $$2-
  if ($decode(&b,mb)) {
    bwrite %file -1 -1 &b
  }
}


Thanks for answering, but I get it to work, as it would be used? I put filename origin and destination and would not generate anything you could put me as it used?

The purpose of this is to download an attached photo of an electronic mail, I wonder if this method also would be another possible, but as much as I read in the forum can not find it, use POP3 protocol to read email. regards

Last edited by Perl; 18/05/15 12:22 PM.
Re: convert base64 to jpg? [Re: Perl] #252948
18/05/15 12:44 PM
18/05/15 12:44 PM
Joined: Jan 2004
Posts: 1,271
L
Loki12583 Online
Hoopy frood
Loki12583  Online
Hoopy frood
L

Joined: Jan 2004
Posts: 1,271
I flipped the arguments around because the base64 should not have spaces and the filename can, so the filename should come second.

Call /saveb64 %text %file

Re: convert base64 to jpg? [Re: Loki12583] #252953
18/05/15 02:05 PM
18/05/15 02:05 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
Perl  Offline OP
Ameglian cow
P

Joined: May 2014
Posts: 35
Originally Posted By: Loki12583
I flipped the arguments around because the base64 should not have spaces and the filename can, so the filename should come second.

Call /saveb64 %text %file


thank iu Loki12583 ,
works very well with short lines, long lines to get in mIRC gives me error and not recomposed me photo, you can not view it, how you could do with those lines? because attempts to put in a variable line tells me too long and if I try to write it in a file tells me the same thing, but I'm testing to see if you can get it all on one line, is there any other option?

Last edited by Perl; 18/05/15 02:07 PM.
Re: convert base64 to jpg? [Re: Perl] #252959
18/05/15 03:39 PM
18/05/15 03:39 PM
Joined: Jan 2004
Posts: 1,271
L
Loki12583 Online
Hoopy frood
Loki12583  Online
Hoopy frood
L

Joined: Jan 2004
Posts: 1,271
mIRC has a line length limit, use whatever means necessary to get the base64 text into a file and then you can use these aliases to read from that file and decode into a new file:

Code:
alias file.base64.decode.save {
  var %source = $qt($1), %destination = $qt($2)
  if ($file.base64.decode(%source)) {
    bwrite %destination -1 -1 $v1
  }
}

alias file.base64.decode {
  var %file = $qt($1), %bvar = $iif(&* iswm $2,$2,&b)
  bread $qt(%file) 0 $file(%file).size %bvar
  if ($decode(%bvar,mb)) {
    if ($prop == text) return $bvar(%bvar,1-).text
    else return %bvar
  }
}


If the line is too wrong for you to read it from a text sockread you need to binary variables; you can ask specific questions but I'm not going to explain the general workings of binary variables and sockets in a forum post when the help files and many online tutorials have done that already.

Re: convert base64 to jpg? [Re: Loki12583] #252961
18/05/15 04:05 PM
18/05/15 04:05 PM
Joined: May 2014
Posts: 35
P
Perl Offline OP
Ameglian cow
Perl  Offline OP
Ameglian cow
P

Joined: May 2014
Posts: 35
Originally Posted By: Loki12583
mIRC has a line length limit, use whatever means necessary to get the base64 text into a file and then you can use these aliases to read from that file and decode into a new file:

Code:
alias file.base64.decode.save {
  var %source = $qt($1), %destination = $qt($2)
  if ($file.base64.decode(%source)) {
    bwrite %destination -1 -1 $v1
  }
}

alias file.base64.decode {
  var %file = $qt($1), %bvar = $iif(&* iswm $2,$2,&b)
  bread $qt(%file) 0 $file(%file).size %bvar
  if ($decode(%bvar,mb)) {
    if ($prop == text) return $bvar(%bvar,1-).text
    else return %bvar
  }
}


If the line is too wrong for you to read it from a text sockread you need to binary variables; you can ask specific questions but I'm not going to explain the general workings of binary variables and sockets in a forum post when the help files and many online tutorials have done that already.


thanks, will study the binary variables when you have some time, but that alias file.base64.decode.save gives me a defective picture, instead of leaving a file with star-shaped leaves a square of the same color orange, not if that I'm not wearing well, just I do this:
Code:
/file.base64.decode.save $mircscript $+ source.txt $mircscript $+ photo.jpg


Regards