New FAMILUG

The PyMiers

Showing posts with label encode. Show all posts
Showing posts with label encode. Show all posts

Saturday, 26 September 2015

base64 encoding

Loạt bài viết giới thiệu về các khái niệm liên quan đến việc chuyển hoá dữ liệu thành 1 dạng khác (encode), và chuyển ngược lại (decode).

Các từ khoá:
- encode/decode <verb>
- encoding/decoding <noun> việc "encode"/"decode"
- data encoding

Base64, Base32, Base16
- tên các thuật toán để encode và decode các chuỗi nhị phân tuỳ ý (binary string) thành dạng text tương ứng.
- Tại sao lại là 64? vì nó sử dụng 64 ký tự để biểu diễn. [A-Za-z0-9+/] là 26 + 26 + 10 + 2 = 64. Ngoài ra có ký tự "=" dùng để đệm (pad).
- Có biến thể khác sử dụng dấu -_ thay cho +/, dùng trong xử lý URL và filename

Tương tự, Base32 sử dụng bảng chữ cái [A-Z2-7] = 26 + 6 = 32
Base16 còn gọi là hex - sử dụng các ký tự [0-9A-F] = 10 + 6 = 16

Trên terminal, dùng lệnh base64 để encode một chuỗi bất kỳ thành dạng "Base64":
$ printf "FAMILUG" | base64
RkFNSUxVRw==
Python2.7 (sử dụng ipython):
In [3]: import base64
In [7]: base64.b64encode("FAMILUG")
Out[7]: 'RkFNSUxVRw==' 
Lấy 10 bytes từ urandom (/dev/urandom - nguồn sinh các byte ngẫu nhiên trên máy tính *NIX), encode thành dạng Base64:

Sunday, 4 August 2013

AudioCD, cdrom, iso 9660

1. AudioCD
Mua được quyển sách học ngoại ngữ kèm được 2 cái audio CD mang về. Vừa giở sách định học một tí thì phát hiện ra là phải nghe. Nhét cái CD phần 1 vào, chạy VLC mở thì nó treo cứng cả VLC, CPU 200% @@

Thế là kill VLC để mount bằng tay xem:

 mount -t iso9660 -o ro /dev/sr0 /mnt/cd

Đập ngay vào mặt cái lỗi:

mount: wrong fs type, bad option, bad superblock on /dev/sr0,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
Thế là công việc chuyển từ học ngoại ngữ giờ đã thành debug và tìm hiểu về CD ~.~

The reason is you cannot mount Audio CD's. Not now, not ever.
ISO9660 is a format, and Audio CD's have to comply with the Redbook specification; not with ISO9660 format specs.
https://bbs.archlinux.org/viewtopic.php?pid=1023931#p1023931

Tuesday, 2 July 2013

FFMPEG

FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation.

FFmpeg provides various tools: