16-Dec-2018 08:40:56 CHRPAK_TEST: MATLAB version Test the CHRPAK library. TEST001 A_TO_I4: Alphabetic character => I I4_TO_A: I => Alphabetic character 1:26 = A:Z 27:52 = a:z I ==> A ==> I 0 " " 0 3 "C" 3 6 "F" 6 9 "I" 9 12 "L" 12 15 "O" 15 18 "R" 18 21 "U" 21 24 "X" 24 27 "a" 27 30 "d" 30 33 "g" 33 36 "j" 36 39 "m" 39 42 "p" 42 45 "s" 45 48 "v" 48 51 "y" 51 54 " " 0 TEST005 BASE_TO_I4 converts an integer in some other base into base 10. I4_TO_BASE converts an integer base 10 to its representation in another base; BASE, I, I4_TO_BASE(I), BASE_TO_I4(I4_TO_BASE(I)) -1 5 101010101 5 1 5 11111 5 2 21 10101 21 3 -243 -100000 -243 4 16 100 16 8 15 17 15 TEST006 BINARY_TO_I4 converts a binary to an integer. I4_TO_BINARY converts an integer to binary, I4 ==> BINARY ==> I4 21 10101 21 -32 -100000 -32 2 10 2 128 10000000 128 CH_CAP_TEST CH_CAP uppercases a character. C CH_CAP(C) F F f F 1 1 b B & & CH_IS_DIGIT_TEST CH_IS_DIGIT is TRUE if a character represents a digit. C CH_IS_DIGIT(C) "0" 1 "1" 1 "2" 1 "3" 1 "4" 1 "5" 1 "6" 1 "7" 1 "8" 1 "9" 1 "X" 0 "?" 0 " " 0 CH_IS_ISBN_DIGIT_TEST CH_IS_ISBN_DIGIT is TRUE if a character represents an ISBN digit. C CH_IS_ISBN_DIGIT(C) "0" 1 "1" 1 "2" 1 "3" 1 "4" 1 "5" 1 "6" 1 "7" 1 "8" 1 "9" 1 "X" 1 "x" 1 "Y" 0 "?" 0 "*" 0 " " 0 CH_LOW_TEST CH_LOW lowercases a character. C CH_LOW(C) F f f f 1 1 b b & & CH_TO_DIGIT_TEST CH_TO_DIGIT: character -> decimal digit 1 "0" 0 2 "1" 1 3 "2" 2 4 "3" 3 5 "4" 4 6 "5" 5 7 "6" 6 8 "7" 7 9 "8" 8 10 "9" 9 11 "X" -1 12 "?" -1 13 " " -1 TEST022 I4_TO_HEX_DIGIT: I4 -> hexadecimal digit HEX_DIGIT_TO_I4: hexadecimal digit -> I4. -2 "?" -1 -1 "?" -1 0 "0" 0 1 "1" 1 2 "2" 2 3 "3" 3 4 "4" 4 5 "5" 5 6 "6" 6 7 "7" 7 8 "8" 8 9 "9" 9 10 "A" 10 11 "B" 11 CH_TO_ROT13_TEST CH_TO_ROT13 "encodes" characters using ROT13 (and digits using ROT5). A second application of the function returns the original character. CH : ABCDEFGHIJKLMNOPQRSTUVWXYZ ROT13(CH) : NOPQRSTUVWXYZABCDEFGHIJKLM ROT13(ROT13(CH)): ABCDEFGHIJKLMNOPQRSTUVWXYZ CH : CH_TO_ROT13 "encodes" characters using ROT13 ROT13(CH) : PU_GB_EBG68 "rapbqrf" punenpgref hfvat EBG68 ROT13(ROT13(CH)): CH_TO_ROT13 "encodes" characters using ROT13 CH_UNIFORM_TEST CH_UNIFORM returns a random character in a range. All characters will be between "D" and "W" I A Count 1 A 0 2 B 0 3 C 0 4 D 5327 5 E 5277 6 F 5131 7 G 5174 8 H 5331 9 I 5352 10 J 5334 11 K 5279 12 L 5266 13 M 5173 14 N 5428 15 O 5316 16 P 5279 17 Q 5226 18 R 5235 19 S 5221 20 T 5279 21 U 5289 22 V 5083 23 W 0 24 X 0 25 Y 0 26 Z 0 DIGIT_TO_CH_TEST DIGIT_TO_CH: decimal digit -> character. -2 "*" -1 -1 "*" -1 0 "0" 0 1 "1" 1 2 "2" 2 3 "3" 3 4 "4" 4 5 "5" 5 6 "6" 6 7 "7" 7 8 "8" 8 9 "9" 9 10 "*" -1 11 "*" -1 TEST046 HEX_TO_I4, hexadecimal->integer. I4_TO_HEX, integer->hexadecimal I I4_TO_HEX(I) HEX_TO_I4(I4_TO_HEX(I)) 21 15 21 -32 -20 -32 1776 6F0 1776 I4_LENGTH_TEST I4_LENGTH computes an integer's "length". I4 Length 0 1 1 1 -1 2 140 3 -1952 5 123456 6 I4_TO_BINHEX_TEST I4_TO_BINHEX: I => BINHEX character The BINHEX alphabet "!"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTVWXYZ[`abcdefhijklmpqr" I4_TO_ISBN_DIGIT_TEST I4_TO_ISBN_DIGIT converts digits 0 to 10 to an ISBN digit. 0 48 1 49 2 50 3 51 4 52 5 53 6 54 7 55 8 56 9 57 10 88 I4_TO_NUNARY_TEST I4_TO_NUNARY converts an integer to negative unary. I4 NUNARY -5 1010101010 0 0 7 1010101010101 TEST057 OCT_TO_I4, octal->integer. I4_TO_OCT, integer->octal I4 OCT I4 21 25 21 -32 -40 -32 1776 3360 1776 I4_TO_UNARY_TEST I4_TO_UNARY converts an integer to unary. I4 UNARY -5 -11111 0 0 7 1111111 I4_UNIFORM_AB_TEST I4_UNIFORM_AB computes pseudorandom values in an interval [A,B]. The lower endpoint A = -100.000000 The upper endpoint B = 200.000000 The initial seed is 123456789 1 -35 2 187 3 149 4 69 5 25 6 -81 7 -23 8 -67 9 -87 10 90 11 -82 12 35 13 20 14 127 15 139 16 -100 17 170 18 5 19 -72 20 -96 I4VEC_PRINT_TEST I4VEC_PRINT prints an I4VEC The I4VEC: 1: 91 2: 92 3: 93 4: 94 TEST066 I4_TO_UUDECODE: I => UUDECODE character The UUDECODE alphabet "`!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_" TEST067 I4_TO_XXDECODE: I => XXDECODE character The XXDECODE alphabet "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ISBN_DIGIT_TO_I4_TEST ISBN_DIGIT_TO_I4 converts an ISBN digit to an I4 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 X 10 TEST083 S_TO_R4, string -> real number; R4_TO_S_LEFT, real number -> string. S --> S_TO_R4 --> R4_TO_S_LEFT 52.134ABCDE 52.134000 52.134000 8.0/2.0 8.000000 8.000000 12E1, 34, 56 120.000000 120.000000 TEST090 S_BEGIN checks the beginning of a string for a substring, ignoring case and spaces. S1 S2 S_BEGIN(S1,S2) Bob BOB 1 B o b bo b 1 Bob BOBBY 1 Bobo Bobb 0 Bob 0 cubic meter cubic meter 1 TEST091 S_BEHEAD_SUBSTRING removes an initial substring from a string, if it occurs. ------String-------- -----SUB------------ ---Beheaded---- HELLO World! HELLO World! 12345678901234567890 12345 678901234567890 0.314159E+01 314 0.314159E+01 !@#$%a^&A(){}[]\\|<>? !@#$%a^&A(){}[]\\|<>? S_DIGITS_COUNT_TEST S_DIGITS_COUNT counts the digits in a string. We count 7 digits in "34E94-70.6" We count 0 digits in "Not a one!" We count 3 digits in "%8*k >>>> # SEVEN-0.3" TEST1015 S_EQI compares two strings for equality, ignoring case and trailing blanks. A B S_EQI(A,B) 0 = FALSE, 1 = TRUE "NixoN" "niXon" 1 "animal" "CRACKER" 0 "Yes" "y" 0 "ALPHA" "zeta" 0 "NIX on" "Nixon" 0 "blank" "blank " 1 TEST102 S_ESCAPE_TEX "protects" characters in a string that might otherwise be interpreted as TeX escape characters. Original string: "The file A_B.TXT is {I think__so} of size 2^8 or C\B.". De-escaped string: "ThefileA\_B.TXTis\{Ithink\_\_so\}ofsize2\^8orC\\B.". TEST105 S_INC_C can "increment" the characters in a string. Starting string: "Tax" Incremented forms: "Tay" "Taz" "Tba" "Tbb" "Tbc" Starting string: "aB34c* 8zY" Incremented forms: "aB34c* 8zZ" "aB34d* 8aA" "aB34d* 8aB" "aB34d* 8aC" "aB34d* 8aD" S_QUOTE_TEST S_QUOTE quotes a string S1 with a mark MARK. ----S1---- ---MARK--- ----S2---- Hi, Bob! " "Hi, Bob!" De Loop LoopDeLoop TEST115 S_REPLACE_CH replaces one character by another; C1 C2 Original String Modified String n t No pennies now. No petties tow. TEST1155 S_REPLACE_CH_BY_S replaces one character by a string; C S_REP Original String Modified String n 1\1 No pennies now. No pe1\11\1ies 1\1ow. TEST1225 S_S_SUBANAGRAM is TRUE if S2 is a "subanagram" of S1. "Get a priest!" "stripe" 1 "Get a priest!" "pastor" 0 "Get a priest!" "a sip " 1 "Get a priest!" "tag! " 0 CHRPAK_TEST1227 S_SCRABBLE_POINTS returns the value of a string as a Scrabble word. I ----S------- Value 1 January 17 2 February 16 3 March 12 4 April 7 5 May 8 6 June 11 7 July 14 8 August 7 9 September 15 10 October 11 11 November 15 12 December 15 TEST1255 S_SORT_A ascending sorts a string. -------String------- -------Sorted------- "HELLO World !! ! " " !!!EHLLOWdlor" "12345678901234567890" "00112233445566778899" "Abc Def Ghi Jkl Mno " " ADGJMbcefhiklno" "AbleBakerCharlieDelt" "ABCDaabeeeehiklllrrt" "What? You have seen?" " ??WYaaeeehhnostuv" S_TO_CAESAR_TEST S_TO_CAESAR applies a Caesar Shift cipher to a string. S2 = S_TO_CAESAR ( S1, K ), varying K. K ---------------S1---------------- ---------------S2---------------- -5 "A man, a plan, a canal: Panama!" "A hai, a kgai, a aaiag: Kaiaha!" -4 "A man, a plan, a canal: Panama!" "A iaj, a lhaj, a aajah: Lajaia!" -3 "A man, a plan, a canal: Panama!" "A jak, a miak, a aakai: Makaja!" -2 "A man, a plan, a canal: Panama!" "A kal, a njal, a aalaj: Nalaka!" -1 "A man, a plan, a canal: Panama!" "A lam, a okam, a bamak: Oamala!" 0 "A man, a plan, a canal: Panama!" "A man, a plan, a canal: Panama!" 1 "A man, a plan, a canal: Panama!" "B nbo, b qmbo, b dbobm: Qbobnb!" 2 "A man, a plan, a canal: Panama!" "C ocp, c rncp, c ecpcn: Rcpcoc!" 3 "A man, a plan, a canal: Panama!" "D pdq, d sodq, d fdqdo: Sdqdpd!" 4 "A man, a plan, a canal: Panama!" "E qer, e tper, e gerep: Tereqe!" 5 "A man, a plan, a canal: Panama!" "F rfs, f uqfs, f hfsfq: Ufsfrf!" S2 = S_TO_CAESAR ( S1, K ). S3 = S_TO_CAESAR ( S2, -K ) K ------------S1------------ ------------S2------------ ------------S3------------ -5 "The key is under the mat" "Oca fat dn piaam oca hao" "Thf kfy is unffr thf mft" -4 "The key is under the mat" "Pda gau eo qjaan pda iap" "The key is uneer the met" -3 "The key is under the mat" "Qeb hbv fp rkabo qeb jaq" "The key is under the mdt" -2 "The key is under the mat" "Rfc icw gq slbcp rfc kar" "The key is under the mct" -1 "The key is under the mat" "Sgd jdx hr tmcdq sgd las" "The key is under the mbt" 0 "The key is under the mat" "The key is under the mat" "The key is under the mat" 1 "The key is under the mat" "Uif lfz jt voefs uif nbu" "The key is under the mat" 2 "The key is under the mat" "Vjg mga ku wpfgt vjg ocv" "The kea is under the mat" 3 "The key is under the mat" "Wkh nhb lv xqghu wkh pdw" "The kea is under the mat" 4 "The key is under the mat" "Xli oic mw yrhiv xli qex" "The kea is under the mat" 5 "The key is under the mat" "Ymj pjd nx zsijw ymj rfy" "The kea is under the mat" S_TO_DIGITS_TEST S_TO_DIGITS: string -> digit vector Test string: "34E94-70.6" Extracted 5 digits: 1: 3 2: 4 3: 9 4: 4 5: 7 Test string: "34E94-70.6" Extracted 7 digits: 1: 3 2: 4 3: 9 4: 4 5: 7 6: 0 7: 6 S_TO_FORMAT_TEST S_TO_FORMAT, string -> FORTRAN format RcW.M; --------String------ R c W M a80 1 a 80 0 f8.4 1 f 8 4 3g14.6 3 g 14 6 i12 1 i 12 0 12l1 12 l 1 0 (10o11) 10 o 11 0 ( 5 z 11.7 ) 5 z 11 7 S_TO_ISBN_DIGITS_TEST S_TO_ISBN_DIGITS: string -> ISBN digit vector Test string: "34E9X-70.6" Extracted 5 digits: 1: 3 2: 4 3: 9 4: 10 5: 7 Test string: "34E9X-70.6" Extracted 7 digits: 1: 3 2: 4 3: 9 4: 10 5: 7 6: 0 7: 6 S_TO_L4_TEST S_TO_L4 reads logical data from a string. S L4 "0 " 0 "F " 0 "f " 0 "1 " 1 "T " 1 "t " 1 " 0 " 0 " 1 0 " 1 " 01 " 0 " Talse" 1 S_TO_ROT13_TEST S_TO_ROT13 applies the ROT13 cipher to a string. S2 = S_TO_ROT13 ( S1 ). -------------------S1------------------- -------------------S2------------------- "abcdefghijklmnopqrstuvwxyz" "nopqrstuvwxyzabcdefghijklm" "Cher" "Pure" "James Thurston Howell III" "Wnzrf Guhefgba Ubjryy VVV" "The bill is $1,205,837.49 so pay now!" "Gur ovyy vf $6,750,382.94 fb cnl abj!" S2 = S_TO_ROT13 ( S1 ). S3 = S_TO_ROT13 ( S2 ). -------------------S1------------------- -------------------S3------------------- "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" "Cher" "Cher" "James Thurston Howell III" "James Thurston Howell III" "The bill is $1,205,837.49 so pay now!" "The bill is $1,205,837.49 so pay now!" S_WORD_COUNT_TEST S_WORD_COUNT counts the words in a string STRING Words "? " 1 "A man, a plan, a canal - Panama!" 8 " justone!word,-@#$ " 1 "How about a day in the park? " 7 S_WORD_EXTRACT_FIRST_TEST S_WORD_EXTRACT_FIRST extracts the first word from a string. Our input string is: "Just an incontrovertible sample of text!" "Just" "an" "incontrovertible" "sample" "of" "text!" Reached the last word. CHRPAK_TEST: Normal end of execution. 16-Dec-2018 08:41:08