#!/usr/bin/env ruby # # $Id: testmcrypt.rb,v 1.2 2001/06/20 11:33:07 hds Exp $ # require "MCrypt" KEY = "BrokenArrow" IVEC = "Time4Bed" PLAINTEXT = "Hi World!" def hexstring( s ) rs = "" s.each_byte { |b| rs << "%02X" % [b] } return rs end # # Start test suite # print( "\nRuby MCrypt Test Suite:\n\n" ) print( "Supported algorithms:\n" ) puts( MCrypt.mcrypt_list_algorithms( nil ).join( "\n" ) ) puts print( "Supported modes:\n" ) puts( MCrypt.mcrypt_list_modes( nil ).join( "\n" ) ) puts mc = MCrypt.new( "twofish", nil, "cfb", nil, KEY, IVEC ) print( "%s, %s:\n" % [mc.mcrypt_enc_get_algorithms_name, mc.mcrypt_enc_get_modes_name] ) print( "Supported key sizes:" ) mc.mcrypt_enc_get_supported_key_sizes.each { | s | print( " %d" % [s] ) } puts print( "Block size: %d\n" % [mc.mcrypt_enc_get_block_size] ) print( "Block algorithm: %s\n" % [mc.mcrypt_enc_is_block_algorithm.to_s] ) print( "Block mode: %s\n" % [mc.mcrypt_enc_is_block_mode.to_s] ) print( "Plaintext: %s\n" % [PLAINTEXT] ) enc = mc.mcrypt_generic( PLAINTEXT ) print( "enc: %s\n" % [hexstring( enc )] ) dec = mc.mdecrypt_generic( enc ) print( "dec: %s\n" % [dec] ) mc.mcrypt_generic_end puts mc = MCrypt.new( "twofish", nil, "cbc", nil, KEY, IVEC ) print( "%s, %s:\n" % [mc.mcrypt_enc_get_algorithms_name, mc.mcrypt_enc_get_modes_name] ) print( "Supported key sizes:" ) mc.mcrypt_enc_get_supported_key_sizes.each { | s | print( " %d" % [s] ) } puts print( "Block size: %d\n" % [mc.mcrypt_enc_get_block_size] ) print( "Block algorithm: %s\n" % [mc.mcrypt_enc_is_block_algorithm.to_s] ) print( "Block mode: %s\n" % [mc.mcrypt_enc_is_block_mode.to_s] ) print( "Plaintext: %s\n" % [PLAINTEXT] ) enc = mc.mcrypt_generic( PLAINTEXT ) print( "enc: %s\n" % [hexstring( enc )] ) dec = mc.mdecrypt_generic( enc ) print( "dec: %s\n" % [dec] ) mc.mcrypt_generic_end puts mc = MCrypt.new( "twofish", nil, "ecb", nil, KEY, nil ) print( "%s, %s:\n" % [mc.mcrypt_enc_get_algorithms_name, mc.mcrypt_enc_get_modes_name] ) print( "Supported key sizes:" ) mc.mcrypt_enc_get_supported_key_sizes.each { | s | print( " %d" % [s] ) } puts print( "Block size: %d\n" % [mc.mcrypt_enc_get_block_size] ) print( "Block algorithm: %s\n" % [mc.mcrypt_enc_is_block_algorithm.to_s] ) print( "Block mode: %s\n" % [mc.mcrypt_enc_is_block_mode.to_s] ) print( "Plaintext: %s\n" % [PLAINTEXT] ) enc = mc.mcrypt_generic( PLAINTEXT ) print( "enc: %s\n" % [hexstring( enc )] ) dec = mc.mdecrypt_generic( enc ) print( "dec: %s\n" % [dec] ) mc.mcrypt_generic_end puts mc = MCrypt.new( "rijndael-128", nil, "cfb", nil, KEY, IVEC ) print( "%s, %s:\n" % [mc.mcrypt_enc_get_algorithms_name, mc.mcrypt_enc_get_modes_name] ) print( "Supported key sizes:" ) mc.mcrypt_enc_get_supported_key_sizes.each { | s | print( " %d" % [s] ) } puts print( "Block size: %d\n" % [mc.mcrypt_enc_get_block_size] ) print( "Block algorithm: %s\n" % [mc.mcrypt_enc_is_block_algorithm.to_s] ) print( "Block mode: %s\n" % [mc.mcrypt_enc_is_block_mode.to_s] ) print( "Plaintext: %s\n" % [PLAINTEXT] ) enc = mc.mcrypt_generic( PLAINTEXT ) print( "enc: %s\n" % [hexstring( enc )] ) dec = mc.mdecrypt_generic( enc ) print( "dec: %s\n" % [dec] ) mc.mcrypt_generic_end puts mc = MCrypt.new( "rijndael-128", nil, "cbc", nil, KEY, IVEC ) print( "%s, %s:\n" % [mc.mcrypt_enc_get_algorithms_name, mc.mcrypt_enc_get_modes_name] ) print( "Supported key sizes:" ) mc.mcrypt_enc_get_supported_key_sizes.each { | s | print( " %d" % [s] ) } puts print( "Block size: %d\n" % [mc.mcrypt_enc_get_block_size] ) print( "Block algorithm: %s\n" % [mc.mcrypt_enc_is_block_algorithm.to_s] ) print( "Block mode: %s\n" % [mc.mcrypt_enc_is_block_mode.to_s] ) print( "Plaintext: %s\n" % [PLAINTEXT] ) enc = mc.mcrypt_generic( PLAINTEXT ) print( "enc: %s\n" % [hexstring( enc )] ) dec = mc.mdecrypt_generic( enc ) print( "dec: %s\n" % [dec] ) mc.mcrypt_generic_end puts # # EOF # # Copyright 2001, Hans-Dieter Stich #