Ruby Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Ruby
Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
SFTP
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
DH Key Exchange
DSA
LZW

 

 

 

 

 

 

 

pad and unpad byte array

Demonstrates using the pad and unpad methods of CkByteArray.

Downloads for Windows/Linux and Install Instructions

require 'rubygems'
require 'chilkat'


data_bytes = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
data = Chilkat::CkByteData.new()
data.append(data_bytes.pack("C10"), 10)

#  These are the padding options for the "pad" method:
#  0 = Each padding byte is the pad count (16 extra added if size is already a multiple of 16)
#  1 = Random bytes except the last is the pad count (16 extra added if size is already multiple of 16)
#  2 = Pad with random data. (If already a multiple of 16, no padding is added).
#  3 = Pad with NULLs. (If already a multiple of 16, no padding is added).
#  4 = Pad with SPACE chars(0x20). (If already a multiple of 16, no padding is added).

#  We'll pad to a block size of 16 bytes.
blockSize = 16

paddingScheme = 0

#  Pad, display the padded byte data, unpad, then re-display
data.pad(blockSize,paddingScheme)
print data.getEncoded("hex") + "\n";
data.unpad(16,paddingScheme)
print data.getEncoded("hex") + "\n";
print "----" + "\n";

paddingScheme = 1
#  Pad, display the padded byte data, unpad, then re-display
data.pad(blockSize,paddingScheme)
print data.getEncoded("hex") + "\n";
data.unpad(16,paddingScheme)
print data.getEncoded("hex") + "\n";
print "----" + "\n";

#  There is no unpadding with schemes 2,3, and 4
data2_bytes = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
data2 = Chilkat::CkByteData.new()
data2.append(data2_bytes.pack("C10"), 10)
paddingScheme = 2
#  Pad and display the padded byte data
data2.pad(blockSize,paddingScheme)
print data2.getEncoded("hex") + "\n";
print "----" + "\n";

#  There is no unpadding with schemes 2,3, and 4
data3_bytes = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
data3 = Chilkat::CkByteData.new()
data3.append(data3_bytes.pack("C10"), 10)
paddingScheme = 3
#  Pad and display the padded byte data
data3.pad(blockSize,paddingScheme)
print data3.getEncoded("hex") + "\n";
print "----" + "\n";

#  There is no unpadding with schemes 2,3, and 4
data4_bytes = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
data4 = Chilkat::CkByteData.new()
data4.append(data4_bytes.pack("C10"), 10)
paddingScheme = 4
#  Pad and display the padded byte data
data4.pad(blockSize,paddingScheme)
print data4.getEncoded("hex") + "\n";
print "----" + "\n";
 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.