Popular
Latest Articles
- Oracle 11g / Fedora 13 - Error in invoking target 'agent nmb nmo nmhs tclexec'
- Cisco Router Zone Based Firewall Configuation Guide - Video Tutorial
- Installing GNS3 0.7.2 onto Fedora 13
- Configuring a Pre-Shared Site to Site VPN between 2 Cisco Routers
- IPv4 Subnetting Notes
- Types of IDS Alerts
- How to run vSphere using SSH tunnelling
- Compiling Rancid on an x86 Solaris 10 platform
How to Encode / Decode a File
Wednesday, 06 January 2010 16:55
What is encoding / decoding ?
Encoding refers to the process of translating a file into an ASCII based string.Decoding refers to the process of decoding the ASCII based string.
Why would I want to do this ?
This is useful for situations were you need to transfer binary files across systems that have no network connectivity. Other applications were this is used is with SMTP which being a completely ASCII based protocol uses encoding to send any binary or not ASCII based data to the recipient.
Example
Below we will be encoding and decoding a floppy disc image.
1. On the first machine we will be encoding the file into an ASCII based string.
Note : we use the file command to confirm the file type.
[root@host1 tmp]# file vmscsi-1.2.0.4.flp
vmscsi-1.2.0.4.flp: DOS floppy 1440k, x86 hard disk boot sector
[root@host1 tmp]# base64 vmscsi-1.2.0.4.flp > vmscsi-1.2.0.4.flp.encoded
[root@host1 tmp]# head -n3 vmscsi-1.2.0.4.flp.encoded
6zyQTVNET1M1LjAAAgEBAALgAEAL8AkAEgACAAAAAAAAAAAAAAApUpcW7E5PIE5BTUUgICAgRkFU
MTIgICAzyY7RvPB7jtm4ACCOwPy9AHw4TiR9JIvBmeg8AXIcg+s6ZqEcfCZmOwcmilf8dQaAygKI
VgKAwxBz6zPJikYQmPdmFgNGHBNWHgNGDhPRi3YRYIlG/IlW/rggAPfmi14LA8NI9
[root@host1 tmp]# file vmscsi-1.2.0.4.flp.encoded
vmscsi-1.2.0.4.flp.encoded: ASCII text
2. Once we have copy and pasted the ASCII text to the other machine (into the file vmscsi-1.2.0.4.flp.encoded) we decode the file back into its original floppy image format.
[root@host2 tmp]# cat vmscsi-1.2.0.4.flp.encoded | base64 -di > vmscsi-1.2.0.4.flp.decoded
[root@host2 tmp]# file vmscsi-1.2.0.4.flp.decoded
vmscsi-1.2.0.4.flp.decoded: DOS floppy 1440k, x86 hard disk boot sector