pub struct DES_Generic<const ROUND: usize = 16, const SHIFT: u128 = 33027, const PC101: u8 = 57, const PC102: u8 = 49, const PC103: u8 = 41, const PC104: u8 = 33, const PC105: u8 = 25, const PC106: u8 = 17, const PC107: u8 = 9, const PC108: u8 = 1, const PC109: u8 = 58, const PC110: u8 = 50, const PC111: u8 = 42, const PC112: u8 = 34, const PC113: u8 = 26, const PC114: u8 = 18, const PC115: u8 = 10, const PC116: u8 = 2, const PC117: u8 = 59, const PC118: u8 = 51, const PC119: u8 = 43, const PC120: u8 = 35, const PC121: u8 = 27, const PC122: u8 = 19, const PC123: u8 = 11, const PC124: u8 = 3, const PC125: u8 = 60, const PC126: u8 = 52, const PC127: u8 = 44, const PC128: u8 = 36, const PC129: u8 = 63, const PC130: u8 = 55, const PC131: u8 = 47, const PC132: u8 = 39, const PC133: u8 = 31, const PC134: u8 = 23, const PC135: u8 = 15, const PC136: u8 = 7, const PC137: u8 = 62, const PC138: u8 = 54, const PC139: u8 = 46, const PC140: u8 = 38, const PC141: u8 = 30, const PC142: u8 = 22, const PC143: u8 = 14, const PC144: u8 = 6, const PC145: u8 = 61, const PC146: u8 = 53, const PC147: u8 = 45, const PC148: u8 = 37, const PC149: u8 = 29, const PC150: u8 = 21, const PC151: u8 = 13, const PC152: u8 = 5, const PC153: u8 = 28, const PC154: u8 = 20, const PC155: u8 = 12, const PC156: u8 = 4, const PC201: u8 = 14, const PC202: u8 = 17, const PC203: u8 = 11, const PC204: u8 = 24, const PC205: u8 = 1, const PC206: u8 = 5, const PC207: u8 = 3, const PC208: u8 = 28, const PC209: u8 = 15, const PC210: u8 = 6, const PC211: u8 = 21, const PC212: u8 = 10, const PC213: u8 = 23, const PC214: u8 = 19, const PC215: u8 = 12, const PC216: u8 = 4, const PC217: u8 = 26, const PC218: u8 = 8, const PC219: u8 = 16, const PC220: u8 = 7, const PC221: u8 = 27, const PC222: u8 = 20, const PC223: u8 = 13, const PC224: u8 = 2, const PC225: u8 = 41, const PC226: u8 = 52, const PC227: u8 = 31, const PC228: u8 = 37, const PC229: u8 = 47, const PC230: u8 = 55, const PC231: u8 = 30, const PC232: u8 = 40, const PC233: u8 = 51, const PC234: u8 = 45, const PC235: u8 = 33, const PC236: u8 = 48, const PC237: u8 = 44, const PC238: u8 = 49, const PC239: u8 = 39, const PC240: u8 = 56, const PC241: u8 = 34, const PC242: u8 = 53, const PC243: u8 = 46, const PC244: u8 = 42, const PC245: u8 = 50, const PC246: u8 = 36, const PC247: u8 = 29, const PC248: u8 = 32, const IP01: u8 = 58, const IP02: u8 = 50, const IP03: u8 = 42, const IP04: u8 = 34, const IP05: u8 = 26, const IP06: u8 = 18, const IP07: u8 = 10, const IP08: u8 = 2, const IP09: u8 = 60, const IP10: u8 = 52, const IP11: u8 = 44, const IP12: u8 = 36, const IP13: u8 = 28, const IP14: u8 = 20, const IP15: u8 = 12, const IP16: u8 = 4, const IP17: u8 = 62, const IP18: u8 = 54, const IP19: u8 = 46, const IP20: u8 = 38, const IP21: u8 = 30, const IP22: u8 = 22, const IP23: u8 = 14, const IP24: u8 = 6, const IP25: u8 = 64, const IP26: u8 = 56, const IP27: u8 = 48, const IP28: u8 = 40, const IP29: u8 = 32, const IP30: u8 = 24, const IP31: u8 = 16, const IP32: u8 = 8, const IP33: u8 = 57, const IP34: u8 = 49, const IP35: u8 = 41, const IP36: u8 = 33, const IP37: u8 = 25, const IP38: u8 = 17, const IP39: u8 = 9, const IP40: u8 = 1, const IP41: u8 = 59, const IP42: u8 = 51, const IP43: u8 = 43, const IP44: u8 = 35, const IP45: u8 = 27, const IP46: u8 = 19, const IP47: u8 = 11, const IP48: u8 = 3, const IP49: u8 = 61, const IP50: u8 = 53, const IP51: u8 = 45, const IP52: u8 = 37, const IP53: u8 = 29, const IP54: u8 = 21, const IP55: u8 = 13, const IP56: u8 = 5, const IP57: u8 = 63, const IP58: u8 = 55, const IP59: u8 = 47, const IP60: u8 = 39, const IP61: u8 = 31, const IP62: u8 = 23, const IP63: u8 = 15, const IP64: u8 = 7, const EP01: u8 = 32, const EP02: u8 = 1, const EP03: u8 = 2, const EP04: u8 = 3, const EP05: u8 = 4, const EP06: u8 = 5, const EP07: u8 = 4, const EP08: u8 = 5, const EP09: u8 = 6, const EP10: u8 = 7, const EP11: u8 = 8, const EP12: u8 = 9, const EP13: u8 = 8, const EP14: u8 = 9, const EP15: u8 = 10, const EP16: u8 = 11, const EP17: u8 = 12, const EP18: u8 = 13, const EP19: u8 = 12, const EP20: u8 = 13, const EP21: u8 = 14, const EP22: u8 = 15, const EP23: u8 = 16, const EP24: u8 = 17, const EP25: u8 = 16, const EP26: u8 = 17, const EP27: u8 = 18, const EP28: u8 = 19, const EP29: u8 = 20, const EP30: u8 = 21, const EP31: u8 = 20, const EP32: u8 = 21, const EP33: u8 = 22, const EP34: u8 = 23, const EP35: u8 = 24, const EP36: u8 = 25, const EP37: u8 = 24, const EP38: u8 = 25, const EP39: u8 = 26, const EP40: u8 = 27, const EP41: u8 = 28, const EP42: u8 = 29, const EP43: u8 = 28, const EP44: u8 = 29, const EP45: u8 = 30, const EP46: u8 = 31, const EP47: u8 = 32, const EP48: u8 = 1, const TP01: u8 = 16, const TP02: u8 = 7, const TP03: u8 = 20, const TP04: u8 = 21, const TP05: u8 = 29, const TP06: u8 = 12, const TP07: u8 = 28, const TP08: u8 = 17, const TP09: u8 = 1, const TP10: u8 = 15, const TP11: u8 = 23, const TP12: u8 = 26, const TP13: u8 = 5, const TP14: u8 = 18, const TP15: u8 = 31, const TP16: u8 = 10, const TP17: u8 = 2, const TP18: u8 = 8, const TP19: u8 = 24, const TP20: u8 = 14, const TP21: u8 = 32, const TP22: u8 = 27, const TP23: u8 = 3, const TP24: u8 = 9, const TP25: u8 = 19, const TP26: u8 = 13, const TP27: u8 = 30, const TP28: u8 = 6, const TP29: u8 = 22, const TP30: u8 = 11, const TP31: u8 = 4, const TP32: u8 = 25, const S000: u8 = 14, const S001: u8 = 0, const S002: u8 = 4, const S003: u8 = 15, const S004: u8 = 13, const S005: u8 = 7, const S006: u8 = 1, const S007: u8 = 4, const S008: u8 = 2, const S009: u8 = 14, const S010: u8 = 15, const S011: u8 = 2, const S012: u8 = 11, const S013: u8 = 13, const S014: u8 = 8, const S015: u8 = 1, const S016: u8 = 3, const S017: u8 = 10, const S018: u8 = 10, const S019: u8 = 6, const S020: u8 = 6, const S021: u8 = 12, const S022: u8 = 12, const S023: u8 = 11, const S024: u8 = 5, const S025: u8 = 9, const S026: u8 = 9, const S027: u8 = 5, const S028: u8 = 0, const S029: u8 = 3, const S030: u8 = 7, const S031: u8 = 8, const S032: u8 = 4, const S033: u8 = 15, const S034: u8 = 1, const S035: u8 = 12, const S036: u8 = 14, const S037: u8 = 8, const S038: u8 = 8, const S039: u8 = 2, const S040: u8 = 13, const S041: u8 = 4, const S042: u8 = 6, const S043: u8 = 9, const S044: u8 = 2, const S045: u8 = 1, const S046: u8 = 11, const S047: u8 = 7, const S048: u8 = 15, const S049: u8 = 5, const S050: u8 = 12, const S051: u8 = 11, const S052: u8 = 9, const S053: u8 = 3, const S054: u8 = 7, const S055: u8 = 14, const S056: u8 = 3, const S057: u8 = 10, const S058: u8 = 10, const S059: u8 = 0, const S060: u8 = 5, const S061: u8 = 6, const S062: u8 = 0, const S063: u8 = 13, const S100: u8 = 15, const S101: u8 = 3, const S102: u8 = 1, const S103: u8 = 13, const S104: u8 = 8, const S105: u8 = 4, const S106: u8 = 14, const S107: u8 = 7, const S108: u8 = 6, const S109: u8 = 15, const S110: u8 = 11, const S111: u8 = 2, const S112: u8 = 3, const S113: u8 = 8, const S114: u8 = 4, const S115: u8 = 14, const S116: u8 = 9, const S117: u8 = 12, const S118: u8 = 7, const S119: u8 = 0, const S120: u8 = 2, const S121: u8 = 1, const S122: u8 = 13, const S123: u8 = 10, const S124: u8 = 12, const S125: u8 = 6, const S126: u8 = 0, const S127: u8 = 9, const S128: u8 = 5, const S129: u8 = 11, const S130: u8 = 10, const S131: u8 = 5, const S132: u8 = 0, const S133: u8 = 13, const S134: u8 = 14, const S135: u8 = 8, const S136: u8 = 7, const S137: u8 = 10, const S138: u8 = 11, const S139: u8 = 1, const S140: u8 = 10, const S141: u8 = 3, const S142: u8 = 4, const S143: u8 = 15, const S144: u8 = 13, const S145: u8 = 4, const S146: u8 = 1, const S147: u8 = 2, const S148: u8 = 5, const S149: u8 = 11, const S150: u8 = 8, const S151: u8 = 6, const S152: u8 = 12, const S153: u8 = 7, const S154: u8 = 6, const S155: u8 = 12, const S156: u8 = 9, const S157: u8 = 0, const S158: u8 = 3, const S159: u8 = 5, const S160: u8 = 2, const S161: u8 = 14, const S162: u8 = 15, const S163: u8 = 9, const S200: u8 = 10, const S201: u8 = 13, const S202: u8 = 0, const S203: u8 = 7, const S204: u8 = 9, const S205: u8 = 0, const S206: u8 = 14, const S207: u8 = 9, const S208: u8 = 6, const S209: u8 = 3, const S210: u8 = 3, const S211: u8 = 4, const S212: u8 = 15, const S213: u8 = 6, const S214: u8 = 5, const S215: u8 = 10, const S216: u8 = 1, const S217: u8 = 2, const S218: u8 = 13, const S219: u8 = 8, const S220: u8 = 12, const S221: u8 = 5, const S222: u8 = 7, const S223: u8 = 14, const S224: u8 = 11, const S225: u8 = 12, const S226: u8 = 4, const S227: u8 = 11, const S228: u8 = 2, const S229: u8 = 15, const S230: u8 = 8, const S231: u8 = 1, const S232: u8 = 13, const S233: u8 = 1, const S234: u8 = 6, const S235: u8 = 10, const S236: u8 = 4, const S237: u8 = 13, const S238: u8 = 9, const S239: u8 = 0, const S240: u8 = 8, const S241: u8 = 6, const S242: u8 = 15, const S243: u8 = 9, const S244: u8 = 3, const S245: u8 = 8, const S246: u8 = 0, const S247: u8 = 7, const S248: u8 = 11, const S249: u8 = 4, const S250: u8 = 1, const S251: u8 = 15, const S252: u8 = 2, const S253: u8 = 14, const S254: u8 = 12, const S255: u8 = 3, const S256: u8 = 5, const S257: u8 = 11, const S258: u8 = 10, const S259: u8 = 5, const S260: u8 = 14, const S261: u8 = 2, const S262: u8 = 7, const S263: u8 = 12, const S300: u8 = 7, const S301: u8 = 13, const S302: u8 = 13, const S303: u8 = 8, const S304: u8 = 14, const S305: u8 = 11, const S306: u8 = 3, const S307: u8 = 5, const S308: u8 = 0, const S309: u8 = 6, const S310: u8 = 6, const S311: u8 = 15, const S312: u8 = 9, const S313: u8 = 0, const S314: u8 = 10, const S315: u8 = 3, const S316: u8 = 1, const S317: u8 = 4, const S318: u8 = 2, const S319: u8 = 7, const S320: u8 = 8, const S321: u8 = 2, const S322: u8 = 5, const S323: u8 = 12, const S324: u8 = 11, const S325: u8 = 1, const S326: u8 = 12, const S327: u8 = 10, const S328: u8 = 4, const S329: u8 = 14, const S330: u8 = 15, const S331: u8 = 9, const S332: u8 = 10, const S333: u8 = 3, const S334: u8 = 6, const S335: u8 = 15, const S336: u8 = 9, const S337: u8 = 0, const S338: u8 = 0, const S339: u8 = 6, const S340: u8 = 12, const S341: u8 = 10, const S342: u8 = 11, const S343: u8 = 1, const S344: u8 = 7, const S345: u8 = 13, const S346: u8 = 13, const S347: u8 = 8, const S348: u8 = 15, const S349: u8 = 9, const S350: u8 = 1, const S351: u8 = 4, const S352: u8 = 3, const S353: u8 = 5, const S354: u8 = 14, const S355: u8 = 11, const S356: u8 = 5, const S357: u8 = 12, const S358: u8 = 2, const S359: u8 = 7, const S360: u8 = 8, const S361: u8 = 2, const S362: u8 = 4, const S363: u8 = 14, const S400: u8 = 2, const S401: u8 = 14, const S402: u8 = 12, const S403: u8 = 11, const S404: u8 = 4, const S405: u8 = 2, const S406: u8 = 1, const S407: u8 = 12, const S408: u8 = 7, const S409: u8 = 4, const S410: u8 = 10, const S411: u8 = 7, const S412: u8 = 11, const S413: u8 = 13, const S414: u8 = 6, const S415: u8 = 1, const S416: u8 = 8, const S417: u8 = 5, const S418: u8 = 5, const S419: u8 = 0, const S420: u8 = 3, const S421: u8 = 15, const S422: u8 = 15, const S423: u8 = 10, const S424: u8 = 13, const S425: u8 = 3, const S426: u8 = 0, const S427: u8 = 9, const S428: u8 = 14, const S429: u8 = 8, const S430: u8 = 9, const S431: u8 = 6, const S432: u8 = 4, const S433: u8 = 11, const S434: u8 = 2, const S435: u8 = 8, const S436: u8 = 1, const S437: u8 = 12, const S438: u8 = 11, const S439: u8 = 7, const S440: u8 = 10, const S441: u8 = 1, const S442: u8 = 13, const S443: u8 = 14, const S444: u8 = 7, const S445: u8 = 2, const S446: u8 = 8, const S447: u8 = 13, const S448: u8 = 15, const S449: u8 = 6, const S450: u8 = 9, const S451: u8 = 15, const S452: u8 = 12, const S453: u8 = 0, const S454: u8 = 5, const S455: u8 = 9, const S456: u8 = 6, const S457: u8 = 10, const S458: u8 = 3, const S459: u8 = 4, const S460: u8 = 0, const S461: u8 = 5, const S462: u8 = 14, const S463: u8 = 3, const S500: u8 = 12, const S501: u8 = 10, const S502: u8 = 1, const S503: u8 = 15, const S504: u8 = 10, const S505: u8 = 4, const S506: u8 = 15, const S507: u8 = 2, const S508: u8 = 9, const S509: u8 = 7, const S510: u8 = 2, const S511: u8 = 12, const S512: u8 = 6, const S513: u8 = 9, const S514: u8 = 8, const S515: u8 = 5, const S516: u8 = 0, const S517: u8 = 6, const S518: u8 = 13, const S519: u8 = 1, const S520: u8 = 3, const S521: u8 = 13, const S522: u8 = 4, const S523: u8 = 14, const S524: u8 = 14, const S525: u8 = 0, const S526: u8 = 7, const S527: u8 = 11, const S528: u8 = 5, const S529: u8 = 3, const S530: u8 = 11, const S531: u8 = 8, const S532: u8 = 9, const S533: u8 = 4, const S534: u8 = 14, const S535: u8 = 3, const S536: u8 = 15, const S537: u8 = 2, const S538: u8 = 5, const S539: u8 = 12, const S540: u8 = 2, const S541: u8 = 9, const S542: u8 = 8, const S543: u8 = 5, const S544: u8 = 12, const S545: u8 = 15, const S546: u8 = 3, const S547: u8 = 10, const S548: u8 = 7, const S549: u8 = 11, const S550: u8 = 0, const S551: u8 = 14, const S552: u8 = 4, const S553: u8 = 1, const S554: u8 = 10, const S555: u8 = 7, const S556: u8 = 1, const S557: u8 = 6, const S558: u8 = 13, const S559: u8 = 0, const S560: u8 = 11, const S561: u8 = 8, const S562: u8 = 6, const S563: u8 = 13, const S600: u8 = 4, const S601: u8 = 13, const S602: u8 = 11, const S603: u8 = 0, const S604: u8 = 2, const S605: u8 = 11, const S606: u8 = 14, const S607: u8 = 7, const S608: u8 = 15, const S609: u8 = 4, const S610: u8 = 0, const S611: u8 = 9, const S612: u8 = 8, const S613: u8 = 1, const S614: u8 = 13, const S615: u8 = 10, const S616: u8 = 3, const S617: u8 = 14, const S618: u8 = 12, const S619: u8 = 3, const S620: u8 = 9, const S621: u8 = 5, const S622: u8 = 7, const S623: u8 = 12, const S624: u8 = 5, const S625: u8 = 2, const S626: u8 = 10, const S627: u8 = 15, const S628: u8 = 6, const S629: u8 = 8, const S630: u8 = 1, const S631: u8 = 6, const S632: u8 = 1, const S633: u8 = 6, const S634: u8 = 4, const S635: u8 = 11, const S636: u8 = 11, const S637: u8 = 13, const S638: u8 = 13, const S639: u8 = 8, const S640: u8 = 12, const S641: u8 = 1, const S642: u8 = 3, const S643: u8 = 4, const S644: u8 = 7, const S645: u8 = 10, const S646: u8 = 14, const S647: u8 = 7, const S648: u8 = 10, const S649: u8 = 9, const S650: u8 = 15, const S651: u8 = 5, const S652: u8 = 6, const S653: u8 = 0, const S654: u8 = 8, const S655: u8 = 15, const S656: u8 = 0, const S657: u8 = 14, const S658: u8 = 5, const S659: u8 = 2, const S660: u8 = 9, const S661: u8 = 3, const S662: u8 = 2, const S663: u8 = 12, const S700: u8 = 13, const S701: u8 = 1, const S702: u8 = 2, const S703: u8 = 15, const S704: u8 = 8, const S705: u8 = 13, const S706: u8 = 4, const S707: u8 = 8, const S708: u8 = 6, const S709: u8 = 10, const S710: u8 = 15, const S711: u8 = 3, const S712: u8 = 11, const S713: u8 = 7, const S714: u8 = 1, const S715: u8 = 4, const S716: u8 = 10, const S717: u8 = 12, const S718: u8 = 9, const S719: u8 = 5, const S720: u8 = 3, const S721: u8 = 6, const S722: u8 = 14, const S723: u8 = 11, const S724: u8 = 5, const S725: u8 = 0, const S726: u8 = 0, const S727: u8 = 14, const S728: u8 = 12, const S729: u8 = 9, const S730: u8 = 7, const S731: u8 = 2, const S732: u8 = 7, const S733: u8 = 2, const S734: u8 = 11, const S735: u8 = 1, const S736: u8 = 4, const S737: u8 = 14, const S738: u8 = 1, const S739: u8 = 7, const S740: u8 = 9, const S741: u8 = 4, const S742: u8 = 12, const S743: u8 = 10, const S744: u8 = 14, const S745: u8 = 8, const S746: u8 = 2, const S747: u8 = 13, const S748: u8 = 0, const S749: u8 = 15, const S750: u8 = 6, const S751: u8 = 12, const S752: u8 = 10, const S753: u8 = 9, const S754: u8 = 13, const S755: u8 = 0, const S756: u8 = 15, const S757: u8 = 3, const S758: u8 = 3, const S759: u8 = 5, const S760: u8 = 5, const S761: u8 = 6, const S762: u8 = 8, const S763: u8 = 11> { /* private fields */ }Expand description
A DES symmetric-key algorithm for the encryption of digital data
§Note
This descryption about DES is according to big endianness. MSB (Most Significant Bit) is the first bit and LSB (Least Significant Bit) is the 64th bit in this descryption unless otherwise mentioned.
§Introduction
DES is the acronym of Data Encryption Standard. It is the symmetric key encryption/decryption algorithm. It was originally developed based on Lucifer encryption/decryption algorithm made by IBM. DES was approved as a federal standard in November 1976.
§Vulnerability
- Its key length is only 56-bit. It is considered to be too short against modern computing power. Actually, in July, 1998, the DES key was broken by brute-force attack within 56 hours with a machine DES cracker (Deep Crack) made by EEF (Electronic Frontier Foundation). And, in January, 1999, Deep Crack and distributed.net broke a DES key together within 22 hours and 15 minutes.
- Weak keys: 0x0000000000000000, 0x0101010101010101, 0xFFFFFFFFFFFFFFFF, 0xFEFEFEFEFEFEFEFE, 0xE0E0E0E0F1F1F1F1, 0xE1E1E1E1F0F0F0F0, 0x1F1F1F1F0E0E0E0E, 0x1E1E1E1E0F0F0F0F in big-endianness. Actually, if the parity bits in keys are ignored, the keys 0x0000000000000000 and 0x0101010101010101 are the same key. In fact, not only 0x0101010101010101 is the same key as 0x0000000000000000. 0x0100000000000000 is also the same key. All the 256 keys that have only different parity bits and all other bits same are the same key as 0x0000000000000000, too. Though only representative keys will be mentioned in this description, please keep in mind that all the 256 keys that have only different parity bits and all other bits same are the same key. And, the keys 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE are also the same key. And, The keys 0xE0E0E0E0F1F1F1F1 and 0xE1E1E1E1F0F0F0F0 are also the same key. And, the keys 0x1F1F1F1F0E0E0E0E and 0x1E1E1E1E0F0F0F0F are the same key, too. For instance, if you encrypt your data with the key 0x0000000000000000 and encrypt the output ciphertext again with the same key 0x0000000000000000, you will get the original plaintext! So, the ciphertext is only secure-looking.
- Semi-week keys: The pairs 0x011F011F010E010E and 0x1F011F010E010E01, 0x01E001E001F101F1 and 0xE001E001F101F101, 0x01FE01FE01FE01FE and 0xFE01FE01FE01FE01, 0x1FE01FE00EF10EF1 and 0xE01FE01FF10EF10E, 0x1FFE1FFE0EFE0EFE and 0xFE1FFE1FFE0EFE0E, and 0xE0FEE0FEF1FEF1FE and 0xFEE0FEE0FEF1FEF1 in big-endianness are considered to be week. For example, if you encrypt your data with the key 0x011F011F010E010E and encrypt the output ciphertext again with its counterpart key 0xE001E001F101F101, you will get the original plaintext! So, the ciphertext is only secure-looking.
§Use of DES and its variants
This algorithm is implemented generic way. Most of the constants are implemented as generic constants. So, without changing any line of code, you can change the algorithm by changing the generic parameter. You can design and implement your own algorithm based on DES which uses Feistel structure.
§Generic Parameters
- ROUND: You can determine how many times the Fiestel network will be repeated. Its maximum value is 128 and its minimum value is 0. Original DES has 16 rounds for its Feistel structure but you can increase the number of rounds up to 128 rounds, and decrease it down to 0.
- SHIFT: According to the number of rounds, you have to determine
SHIFTwhich is used for generating round keys. You can determine how many bits the half keys will be rotated left for the corresponding round in the key generator. IfSHIFTis ‘0b10011001’, the half keys will be rotated left by one bit for the first round, and will be rotated left by two bits for the second round, and will be rotated left by two bits for the third round, and so on. The LSB (Least Significant Bit) is for the first round and the MSB (Most Significant Bit) is for the 128th round.0means that the half keys will be rotated left by two bits and1means that the half keys will be rotated left by one bit. Up to onlyROUNDbits from the LSB ofSHIFTwill be meaningful. For example, ifROUNDis 5 andSHIFTis ‘0b10011001’, only ‘0b11001’ out of ‘0b10011001’ is meaningful. IfROUNDis 16 andSHIFTis ‘0b10011001’,SHIFTwill be understood to be ‘0b0000000010011001’. - PC101 ~ PC248: Permutation compression. In key generator, the 64-bit key which includes parity bits is compressed into 56-bit key by dropping all the parity bits (8th, 16th, 24th, 32th, 40th, 48th, 56th, and 64th bits) and permutating (or transposing or shuffling) all bits. They are 1-based. For this operation, PC101 ~ PC156 are used. You can change the permutation compression algorithm by changing these parameters. Note that PC101 ~ PC248 should not include 8, 16, 24, 32, 40, 48, 56, and 64 because they are all parity bits. If you include any of those numbers, the whole DES encryption/decryption algorithm is broken or unstable or collapses. Also, in key generator, 56-bit key is compressed into 48-bit key by dropping all the bits (9th, 18th, 22nd, 25th, 35th, 43rd, and 54th bits) and permutating (or transposing or shuffling) all bits. For this operation, PC201 ~ PC248 are used. You can change the permutation compression algorithm by changing these parameters. In this case, you can drop other bits intead of dropping 9th, 18th, 22nd, 25th, 35th, 43rd, and 54th bits. Dropping other bits does not kill the whole DES encryption/decryption algorithm.
- IP01 ~ IP64: Inital permutation constants. They are 1-based. For example,
IP01 = 58means that the 58th bit of data is moved to the first bit of the data which is MSB at initial permutation. You can change inital permutation wire by changing these constants. However, when you change these constants, you have to remember that you should included all the bits. You cannot drop any bit. Your dropping any bit will surely kill the whole DES encryption/decryption algorithm. Final permutation constants is automatically calculated from Inital permutation constants. FP01 ~ FP64 is inverse version of IP01 ~ IP64. So, FP01 ~ FP64 will be automagically determined. You don’t have to determine them. - S000 ~ S763: S-Box constants. Its index such as 000, 212, etc. is 0-based. S0XX means S-Box 0, S1XX means S-Box 1, and so on. S000 is the first element of S-Box 0. According to the document, the input six bits determines the output of S-Box. The first and the last bit of the six bits represent in base 2 a number in the decimal range 0 to 3 (or binary 00 to 11) which is row number. The rest middle four bits represent in base 2 a number in the decimal range 0 to 15 (binary 0000 to 1111) which is column number. It is considered that the DES designers explained the S-box structure unnecessarily too complicated. The above-described S-box indexing way looks two dimensional, but actually is one dimensional. So, in this crate, S-boxes are implemented to be two-dimensional array which is an array of S-boxes. Each S-box is an array of 64 four-bit numbers. The input six-bit number is used as the index of the one-dimensional array of these 64 four-bit numbers. So, the S-box tables have been rearranged to be the one-dimensional array. You can cange S-Box by changing these constants. However, you have know that the change of these constants may hurt the security a lot. And the principle of S-box has been unknown so far.
- EP01 ~ EP48: Expansion permutation constants. They are 1-based. For
example,
EP01 = 28means that the 28th bit of data is moved to the first bit of the data which is MSB at expansion permutation. They expand the 32-bit right-half data from the Feistel structure of the corresponding round into 48 bits in order to perform XOR (exclusive OR) with the corresponding 48-bit round key. When you change these constants, you have to remember that you should included all the bits. You cannot drop any bit. Your dropping any bit will surely kill the whole DES encryption/decryption algorithm. - TP01 ~ TP32: Translation permutation constans. They are 1-based. For
example,
TP01 = 16means that the 16th bit of data is moved to the first bit of the data which is MSB at translation permutation. You can change translation permutation wire by changing these constants. However, when you change these constants, you have to remember that you should included all the bits. You cannot drop any bit. Your dropping any bit will surely kill the whole DES encryption/decryption algorithm.
§Caution
DES is not considered to be secure anymore. So, it is wise not to use DES for serious purpose. Instead, use TDES or AES or any other equivalents. In this crate, NDES which is generalized version of TDES is provided, and AES is also provided.
§Reference
Read more about DES in brief. Watch this video and then this video in series for more (or deeper or full) understanding of DES.
§Quick Start
You have to import (use) the module DES in order to use official DES
as shown in Example 1.
§Example 1
use cryptocol::symmetric::DES;You can instantiate the DES object with u64 key as Example 2.
In this case, you have to take endianness into account.
In little-endianness, 0x_1234567890ABCDEF_u64 is [0xEFu8, 0xCDu8, 0xABu8,
0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8] while the same
0x_1234567890ABCDEF_u64 is [0x12u8, 0x34u8, 0x56u8, 0x78u8, 0x90u8, 0xABu8,
0xCDu8, 0xEF_u64] in big-endianness.
The instantiated object should be mutable.
§Example 2
use cryptocol::symmetric::DES;
let key = 0x_1234567890ABCDEF_u64;
let mut _a_des = DES::new_with_key_u64(key);Also, you can instantiate the DES object with [u8; 8] key as shown in
Example 3. In this case, you don’t have to take endianness into account.
The instantiated object should be mutable.
§Example 3
use cryptocol::symmetric::DES;
let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
let mut _a_des = DES::new_with_key(key);You can instantiate the DES object without key and set a u64 key later as
shown in Example 4 or a [u8; 8] key later as shown in Example 5.
§Example 4
use cryptocol::symmetric::DES;
let mut a_des = DES::new();
let key = 0x_1234567890ABCDEF_u64;
a_des.set_key_u64(key);§Example 5
use cryptocol::symmetric::DES;
let mut a_des = DES::new();
let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
a_des.set_key(key);Now, you can freely use any operation mode. This crate provide ECB (Electronic CodeBook), CBC(Cipher Block Chaining), PCBC (Propagation Cipher Block Chaining), CFB (Cipher FeedBack) OFB (Output FeedBack), and CTR (CounTeR). You can choose the way of padding bits according to either PKCS #7 or ISO 7816-4. So, you can import (use) one of the following traits: ECB_PKCS7, ECB_ISO, CBC_PKCS7, CBC_ISO, PCBC_PKCS7, PCBC_ISO, CFB, OFB, and CTR. The following example 6 shows the case that you choose CBC operation mode and padding bits according to PKCS #7.
§Example 6
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, CBC_PKCS7 };
let mut a_des = DES::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let iv = 0x_FEDCBA0987654321_u64;
println!("IV =\t{}", iv);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(iv, message, &mut cipher);
print!("C =\t");
for c in cipher.clone()
{ print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
{ write!(txt, "{:02X} ", c); }
assert_eq!(txt, "4B B5 ED DC A0 58 7E 6D 6C 3B A2 00 38 C3 D4 29 42 B1 CF 0D E9 FA EA 11 11 6B C8 30 73 39 DD B7 3F 96 9B A3 76 05 34 7E 64 2F D4 CC B2 68 33 64 C5 9E EF 01 A9 4A FD 5B ");
let mut recovered = String::new();
a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
println!("B (16 rounds) =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);
println!();You can modify the DES encryption/decryption algorithm as you want. All the constants are implemented as generic parameters. For instance, you can change S-box, the number of rounds of Feistel network, the number of shift-left in round key generators, etc. The following Example 7 shows the variation of DES which has 128 rounds instead of 16 rounds.
§Example 7
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES_Expanded, CBC_PKCS7 };
let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
let message = "In the beginning God created the heavens and the earth.";
println!("M =\t{}", message);
let iv = 0x_FEDCBA0987654321_u64;
println!("IV =\t{}", iv);
let mut cipher = Vec::<u8>::new();
a_des.encrypt_str_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
print!("C =\t");
for c in cipher.clone()
{ print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
{ write!(txt, "{:02X} ", c); }
assert_eq!(txt, "0B EA 6B BC 68 F9 B0 3E 7D AF DE 71 9C 08 AA 16 42 40 1C C8 DC 40 51 C6 8D D4 E7 D2 0B A4 F2 09 02 02 C2 6E 99 BC 9E 2A F4 11 7E 48 A7 ED 76 70 C6 9D C6 BD A6 9B 58 8B ");
let mut recovered = String::new();
a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
println!("B =\t{}", recovered);
assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
assert_eq!(recovered, message);§Notice for Practical Use
Now, you can freely use any methods with any paddings in any operation modes.
- This crate provides six operation modes: ECB, CBC, PCBC, CFB, OFB, and CTR.
- This crate provides two padding ways: ISO 7816-4 and PKCS #7.
- The operation modes ECB, CBC and PCBC requires padding bytes.
- You can combine three operation modes and two padding ways.
- The operation modes
CFB,OFB, andCTRdoes not require padding bytes. - The traits that implements combination of operation modes and padding
ways are provided such as
ECB_PKCS7,ECB_ISO,CBC_PKCS7,CBC_ISO,PCBC_PKCS7, andPCBC_ISO. - You can find detaild instructions and their helpful examples if you go through those links.
In summary,
Implementations§
Source§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new object DES_Generic.
§Features
- In order to encrypt data, object should be instantiated mutable.
- This method sets the key to be [0_u8, 0, 0, 0, 0, 0, 0, 0].
- Do not use this default key [0_u8, 0, 0, 0, 0, 0, 0, 0] because it is known as one of the weak keys.
§Example 1
use cryptocol::symmetric::DES;
let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
let plaintext = 0x1234567890ABCDEF_u64;
let ciphertext = des.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
let cipher_cipher_text = des.encrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!§For more examples,
click here
Examples found in repository?
50fn des_quick_start_instantiation_without_key()
51{
52 println!("des_quick_start_instantiation_without_key()");
53 use cryptocol::symmetric::DES;
54
55 let mut a_des = DES::new();
56 let key = 0x_1234567890ABCDEF_u64;
57 a_des.set_key_u64(key);
58
59 let mut a_des = DES::new();
60 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
61 a_des.set_key(key);
62 println!("-------------------------------");
63}
64
65fn des_quick_start_encryption_decryption_16_rounds()
66{
67 println!("des_quick_start_encryption_decryption_16_rounds()");
68 use std::io::Write;
69 use std::fmt::Write as _;
70 use cryptocol::symmetric::{ CBC_PKCS7, DES };
71
72 let mut a_des = DES::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
73 let message = "In the beginning God created the heavens and the earth.";
74 println!("M =\t{}", message);
75 let iv = 0x_FEDCBA0987654321_u64;
76 println!("IV =\t{}", iv);
77 let mut cipher = Vec::<u8>::new();
78 a_des.encrypt_str_into_vec(iv, message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "4B B5 ED DC A0 58 7E 6D 6C 3B A2 00 38 C3 D4 29 42 B1 CF 0D E9 FA EA 11 11 6B C8 30 73 39 DD B7 3F 96 9B A3 76 05 34 7E 64 2F D4 CC B2 68 33 64 C5 9E EF 01 A9 4A FD 5B ");
87
88 let mut recovered = String::new();
89 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
90 println!("B (16 rounds) =\t{}", recovered);
91 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
92 assert_eq!(recovered, message);
93 println!("-------------------------------");
94}
95
96fn des_quick_start_encryption_decryption_256_rounds()
97{
98 println!("des_quick_start_encryption_decryption_256_rounds()");
99 use std::io::Write;
100 use std::fmt::Write as _;
101 use cryptocol::symmetric::{ CBC_PKCS7, DES_Expanded };
102
103 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
104 let message = "In the beginning God created the heavens and the earth.";
105 println!("M =\t{}", message);
106 let iv = 0x_FEDCBA0987654321_u64;
107 println!("IV =\t{}", iv);
108 let mut cipher = Vec::<u8>::new();
109 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
110 print!("C =\t");
111 for c in cipher.clone()
112 { print!("{:02X} ", c); }
113 println!();
114 let mut txt = String::new();
115 for c in cipher.clone()
116 { write!(txt, "{:02X} ", c); }
117 assert_eq!(txt, "0B EA 6B BC 68 F9 B0 3E 7D AF DE 71 9C 08 AA 16 42 40 1C C8 DC 40 51 C6 8D D4 E7 D2 0B A4 F2 09 02 02 C2 6E 99 BC 9E 2A F4 11 7E 48 A7 ED 76 70 C6 9D C6 BD A6 9B 58 8B ");
118
119 let mut recovered = String::new();
120 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
121 println!("B =\t{}", recovered);
122 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
123 assert_eq!(recovered, message);
124 println!("-------------------------------");
125}
126
127fn des_basic_operation_main()
128{
129 des_new();
130 des_new_with_key();
131 des_new_with_key_u64();
132 des_encryptor_with_key();
133 des_encryptor_with_key_u64();
134 des_decryptor_with_key();
135 des_decryptor_with_key_u64();
136 des_get_key();
137 des_get_key_u64();
138 des_set_key();
139 des_set_key_u64();
140 des_turn_inverse();
141 des_turn_encryptor();
142 des_turn_decryptor();
143}
144
145fn des_new()
146{
147 println!("des_new()");
148 use cryptocol::symmetric::DES;
149
150 let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
151 let plaintext = 0x1234567890ABCDEF_u64;
152 let ciphertext = des.encrypt_u64(plaintext);
153
154 println!("Plaintext:\t\t{:#018X}", plaintext);
155 println!("Ciphertext:\t\t{:#018X}", ciphertext);
156 assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
157
158 let cipher_cipher_text = des.encrypt_u64(ciphertext);
159 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
160 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
161 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
162
163 #[cfg(test)]
164 des_compile_fail_new();
165 println!("-------------------------------");
166}
167
168#[test]
169fn des_compile_fail_new()
170{
171 use cryptocol::symmetric::DES;
172 let des = DES::new();
173 // It cannot be compiled!
174 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
175}
176
177fn des_new_with_key()
178{
179 println!("des_new_with_key()");
180 use cryptocol::symmetric::DES;
181
182 // Normal case
183 let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
184 let plaintext = 0x1234567890ABCDEF_u64;
185 let ciphertext = des.encrypt_u64(plaintext);
186
187 println!("Plaintext:\t\t{:#018X}", plaintext);
188 println!("Ciphertext:\t\t{:#018X}", ciphertext);
189 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
190
191 let cipher_cipher_text = des.encrypt_u64(ciphertext);
192 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
193 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
194 assert_ne!(cipher_cipher_text, plaintext);
195 println!();
196
197 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
198 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
199 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
200 let mut des1 = DES::new_with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
201 let mut des2 = DES::new_with_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
202
203 let plaintext = 0x1234567890ABCDEF_u64;
204 let ciphertext1 = des1.encrypt_u64(plaintext);
205 let ciphertext2 = des2.encrypt_u64(plaintext);
206
207 println!("Plaintext:\t\t{:#018X}", plaintext);
208 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
209 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
210 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
211 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
212 assert_eq!(ciphertext1, ciphertext2);
213
214 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
215 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
216 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
217 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
218 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
219 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
220 assert_eq!(cipher_cipher_text1, plaintext);
221 assert_eq!(cipher_cipher_text2, plaintext);
222 println!();
223 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
224 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
225
226
227 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
228 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
229 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
230 let mut des1 = DES::new_with_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
231 let mut des2 = DES::new_with_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
232 let plaintext = 0x1234567890ABCDEF_u64;
233 let ciphertext1 = des1.encrypt_u64(plaintext);
234 let ciphertext2 = des2.encrypt_u64(plaintext);
235
236 println!("Plaintext:\t\t{:#018X}", plaintext);
237 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
238 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
239 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
240 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
241 assert_eq!(ciphertext1, ciphertext2);
242
243 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
244 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
245 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
246 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
247 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
248 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
249 assert_eq!(cipher_cipher_text1, plaintext);
250 assert_eq!(cipher_cipher_text2, plaintext);
251 println!();
252 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
253 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
254
255 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
256 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1] is the same key as the key
257 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
258 let mut des1 = DES::new_with_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
259 let mut des2 = DES::new_with_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
260 let plaintext = 0x1234567890ABCDEF_u64;
261 let ciphertext1 = des1.encrypt_u64(plaintext);
262 let ciphertext2 = des2.encrypt_u64(plaintext);
263
264 println!("Plaintext:\t\t{:#018X}", plaintext);
265 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
266 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
267 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
268 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
269 assert_eq!(ciphertext1, ciphertext2);
270
271 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
272 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
273 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
274 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
275 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
276 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
277 assert_eq!(cipher_cipher_text1, plaintext);
278 assert_eq!(cipher_cipher_text2, plaintext);
279 println!();
280 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
281 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
282
283 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
284 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
285 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
286 let mut des1 = DES::new_with_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
287 let mut des2 = DES::new_with_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
288 let plaintext = 0x1234567890ABCDEF_u64;
289 let ciphertext1 = des1.encrypt_u64(plaintext);
290 let ciphertext2 = des2.encrypt_u64(plaintext);
291
292 println!("Plaintext:\t\t{:#018X}", plaintext);
293 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
294 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
295 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
296 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
297 assert_eq!(ciphertext1, ciphertext2);
298
299 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
300 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
301 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
302 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
303 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
304 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
305 assert_eq!(cipher_cipher_text1, plaintext);
306 assert_eq!(cipher_cipher_text2, plaintext);
307 println!();
308 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
309 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
310
311 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
312 let mut des1 = DES::new_with_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
313 let mut des2 = DES::new_with_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
314
315 let plaintext = 0x1234567890ABCDEF_u64;
316 let ciphertext = des1.encrypt_u64(plaintext);
317 println!("Plaintext:\t\t{:#018X}", plaintext);
318 println!("Ciphertext:\t\t{:#018X}", ciphertext);
319 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
320
321 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
322 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
323 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
324 assert_eq!(cipher_cipher_text, plaintext);
325
326 let ciphertext = des2.encrypt_u64(plaintext);
327 println!("Plaintext:\t\t{:#018X}", plaintext);
328 println!("Ciphertext:\t\t{:#018X}", ciphertext);
329 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
330
331 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
332 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
333 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
334 assert_eq!(cipher_cipher_text, plaintext);
335 println!();
336 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
337
338 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
339 let mut des1 = DES::new_with_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
340 let mut des2 = DES::new_with_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
341
342 let plaintext = 0x1234567890ABCDEF_u64;
343 let ciphertext = des1.encrypt_u64(plaintext);
344 println!("Plaintext:\t\t{:#018X}", plaintext);
345 println!("Ciphertext:\t\t{:#018X}", ciphertext);
346 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
347
348 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
349 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
350 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
351 assert_eq!(cipher_cipher_text, plaintext);
352
353 let ciphertext = des2.encrypt_u64(plaintext);
354 println!("Plaintext:\t\t{:#018X}", plaintext);
355 println!("Ciphertext:\t\t{:#018X}", ciphertext);
356 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
357
358 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
359 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
360 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
361 assert_eq!(cipher_cipher_text, plaintext);
362 println!();
363 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
364
365 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
366 let mut des1 = DES::new_with_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
367 let mut des2 = DES::new_with_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
368
369 let plaintext = 0x1234567890ABCDEF_u64;
370 let ciphertext = des1.encrypt_u64(plaintext);
371 println!("Plaintext:\t\t{:#018X}", plaintext);
372 println!("Ciphertext:\t\t{:#018X}", ciphertext);
373 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
374
375 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
376 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
377 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
378 assert_eq!(cipher_cipher_text, plaintext);
379
380 let ciphertext = des2.encrypt_u64(plaintext);
381 println!("Plaintext:\t\t{:#018X}", plaintext);
382 println!("Ciphertext:\t\t{:#018X}", ciphertext);
383 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
384
385 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
386 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
387 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
388 assert_eq!(cipher_cipher_text, plaintext);
389 println!();
390 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
391
392 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
393 let mut des1 = DES::new_with_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
394 let mut des2 = DES::new_with_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
395
396 let plaintext = 0x1234567890ABCDEF_u64;
397 let ciphertext = des1.encrypt_u64(plaintext);
398 println!("Plaintext:\t\t{:#018X}", plaintext);
399 println!("Ciphertext:\t\t{:#018X}", ciphertext);
400 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
401
402 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
403 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
404 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
405 assert_eq!(cipher_cipher_text, plaintext);
406
407 let ciphertext = des2.encrypt_u64(plaintext);
408 println!("Plaintext:\t\t{:#018X}", plaintext);
409 println!("Ciphertext:\t\t{:#018X}", ciphertext);
410 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
411
412 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
413 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
414 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
415 assert_eq!(cipher_cipher_text, plaintext);
416 println!();
417 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
418
419 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
420 let mut des1 = DES::new_with_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
421 let mut des2 = DES::new_with_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
422
423 let plaintext = 0x1234567890ABCDEF_u64;
424 let ciphertext = des1.encrypt_u64(plaintext);
425 println!("Plaintext:\t\t{:#018X}", plaintext);
426 println!("Ciphertext:\t\t{:#018X}", ciphertext);
427 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
428
429 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
430 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
431 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
432 assert_eq!(cipher_cipher_text, plaintext);
433
434 let ciphertext = des2.encrypt_u64(plaintext);
435 println!("Plaintext:\t\t{:#018X}", plaintext);
436 println!("Ciphertext:\t\t{:#018X}", ciphertext);
437 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
438
439 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
440 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
441 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
442 assert_eq!(cipher_cipher_text, plaintext);
443 println!();
444 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
445
446 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
447 let mut des1 = DES::new_with_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
448 let mut des2 = DES::new_with_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
449
450 let plaintext = 0x1234567890ABCDEF_u64;
451 let ciphertext = des1.encrypt_u64(plaintext);
452 println!("Plaintext:\t\t{:#018X}", plaintext);
453 println!("Ciphertext:\t\t{:#018X}", ciphertext);
454 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
455
456 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
457 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
458 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
459 assert_eq!(cipher_cipher_text, plaintext);
460
461 let ciphertext = des2.encrypt_u64(plaintext);
462 println!("Plaintext:\t\t{:#018X}", plaintext);
463 println!("Ciphertext:\t\t{:#018X}", ciphertext);
464 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
465
466 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
467 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
468 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
469 assert_eq!(cipher_cipher_text, plaintext);
470 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
471
472 #[cfg(test)]
473 des_compile_fail_new_with_key();
474 println!("-------------------------------");
475}
476
477#[test]
478fn des_compile_fail_new_with_key()
479{
480 use cryptocol::symmetric::DES;
481 let des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
482 // It cannot be compiled!
483 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
484}
485
486fn des_new_with_key_u64()
487{
488 println!("des_new_with_key_u64");
489 use cryptocol::symmetric::DES;
490
491 // Normal case
492 let mut des = DES::new_with_key_u64(0xEFCDAB9078563412);
493 let plaintext = 0x1234567890ABCDEF_u64;
494 let ciphertext = des.encrypt_u64(plaintext);
495
496 println!("Plaintext:\t\t{:#018X}", plaintext);
497 println!("Ciphertext:\t\t{:#018X}", ciphertext);
498 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
499
500 let cipher_cipher_text = des.encrypt_u64(ciphertext);
501 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
502 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
503 assert_ne!(cipher_cipher_text, plaintext);
504 println!();
505
506 // Weak key case 1 for 0x0000000000000000
507 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
508 let mut des1 = DES::new_with_key_u64(0x0000000000000000);
509 let mut des2 = DES::new_with_key_u64(0x0101010101010101);
510
511 let plaintext = 0x1234567890ABCDEF_u64;
512 let ciphertext1 = des1.encrypt_u64(plaintext);
513 let ciphertext2 = des2.encrypt_u64(plaintext);
514
515 println!("Plaintext:\t\t{:#018X}", plaintext);
516 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
517 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
518 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
519 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
520 assert_eq!(ciphertext1, ciphertext2);
521
522 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
523 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
524 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
525 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
526 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
527 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
528 assert_eq!(cipher_cipher_text1, plaintext);
529 assert_eq!(cipher_cipher_text2, plaintext);
530 println!();
531 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
532
533 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
534 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
535 let mut des1 = DES::new_with_key_u64(0xFFFFFFFFFFFFFFFF);
536 let mut des2 = DES::new_with_key_u64(0xFEFEFEFEFEFEFEFE);
537 let plaintext = 0x1234567890ABCDEF_u64;
538 let ciphertext1 = des1.encrypt_u64(plaintext);
539 let ciphertext2 = des2.encrypt_u64(plaintext);
540
541 println!("Plaintext:\t\t{:#018X}", plaintext);
542 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
543 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
544 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
545 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
546 assert_eq!(ciphertext1, ciphertext2);
547
548 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
549 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
550 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
551 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
552 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
553 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
554 assert_eq!(cipher_cipher_text1, plaintext);
555 assert_eq!(cipher_cipher_text2, plaintext);
556 println!();
557 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
558
559 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
560 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
561 let mut des1 = DES::new_with_key_u64(0xF1F1F1F1E0E0E0E0);
562 let mut des2 = DES::new_with_key_u64(0xF0F0F0F0E1E1E1E1);
563 let plaintext = 0x1234567890ABCDEF_u64;
564 let ciphertext1 = des1.encrypt_u64(plaintext);
565 let ciphertext2 = des2.encrypt_u64(plaintext);
566
567 println!("Plaintext:\t\t{:#018X}", plaintext);
568 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
569 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
570 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
571 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
572 assert_eq!(ciphertext1, ciphertext2);
573
574 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
575 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
576 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
577 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
578 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
579 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
580 assert_eq!(cipher_cipher_text1, plaintext);
581 assert_eq!(cipher_cipher_text2, plaintext);
582 println!();
583 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
584
585 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
586 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
587 let mut des1 = DES::new_with_key_u64(0x0E0E0E0E1F1F1F1F);
588 let mut des2 = DES::new_with_key_u64(0x0F0F0F0F1E1E1E1E);
589 let plaintext = 0x1234567890ABCDEF_u64;
590 let ciphertext1 = des1.encrypt_u64(plaintext);
591 let ciphertext2 = des2.encrypt_u64(plaintext);
592
593 println!("Plaintext:\t\t{:#018X}", plaintext);
594 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
595 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
596 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
597 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
598 assert_eq!(ciphertext1, ciphertext2);
599
600 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
601 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
602 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
603 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
604 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
605 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
606 assert_eq!(cipher_cipher_text1, plaintext);
607 assert_eq!(cipher_cipher_text2, plaintext);
608 println!();
609 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
610
611 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
612 let mut des1 = DES::new_with_key_u64(0x0E010E011F011F01);
613 let mut des2 = DES::new_with_key_u64(0x010E010E011F011F);
614
615 let plaintext = 0x1234567890ABCDEF_u64;
616 let ciphertext = des1.encrypt_u64(plaintext);
617 println!("Plaintext:\t\t{:#018X}", plaintext);
618 println!("Ciphertext:\t\t{:#018X}", ciphertext);
619 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
620
621 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
622 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
623 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
624 assert_eq!(cipher_cipher_text, plaintext);
625
626 let ciphertext = des2.encrypt_u64(plaintext);
627 println!("Plaintext:\t\t{:#018X}", plaintext);
628 println!("Ciphertext:\t\t{:#018X}", ciphertext);
629 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
630
631 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
632 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
633 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
634 assert_eq!(cipher_cipher_text, plaintext);
635 println!();
636 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
637
638 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
639 let mut des1 = DES::new_with_key_u64(0xF101F101E001E001);
640 let mut des2 = DES::new_with_key_u64(0x01F101F101E001E0);
641
642 let plaintext = 0x1234567890ABCDEF_u64;
643 let ciphertext = des1.encrypt_u64(plaintext);
644 println!("Plaintext:\t\t{:#018X}", plaintext);
645 println!("Ciphertext:\t\t{:#018X}", ciphertext);
646 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
647
648 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
649 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
650 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
651 assert_eq!(cipher_cipher_text, plaintext);
652
653 let ciphertext = des2.encrypt_u64(plaintext);
654 println!("Plaintext:\t\t{:#018X}", plaintext);
655 println!("Ciphertext:\t\t{:#018X}", ciphertext);
656 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
657
658 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
659 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
660 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
661 assert_eq!(cipher_cipher_text, plaintext);
662 println!();
663 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
664
665 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
666 let mut des1 = DES::new_with_key_u64(0xFE01FE01FE01FE01);
667 let mut des2 = DES::new_with_key_u64(0x01FE01FE01FE01FE);
668
669 let plaintext = 0x1234567890ABCDEF_u64;
670 let ciphertext = des1.encrypt_u64(plaintext);
671 println!("Plaintext:\t\t{:#018X}", plaintext);
672 println!("Ciphertext:\t\t{:#018X}", ciphertext);
673 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
674
675 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
676 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
677 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
678 assert_eq!(cipher_cipher_text, plaintext);
679
680 let ciphertext = des2.encrypt_u64(plaintext);
681 println!("Plaintext:\t\t{:#018X}", plaintext);
682 println!("Ciphertext:\t\t{:#018X}", ciphertext);
683 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
684
685 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
686 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
687 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
688 assert_eq!(cipher_cipher_text, plaintext);
689 println!();
690 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
691
692 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
693 let mut des1 = DES::new_with_key_u64(0xF10EF10EE01FE01F);
694 let mut des2 = DES::new_with_key_u64(0x0EF10EF11FE01FE0);
695
696 let plaintext = 0x1234567890ABCDEF_u64;
697 let ciphertext = des1.encrypt_u64(plaintext);
698 println!("Plaintext:\t\t{:#018X}", plaintext);
699 println!("Ciphertext:\t\t{:#018X}", ciphertext);
700 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
701
702 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
703 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
704 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
705 assert_eq!(cipher_cipher_text, plaintext);
706
707 let ciphertext = des2.encrypt_u64(plaintext);
708 println!("Plaintext:\t\t{:#018X}", plaintext);
709 println!("Ciphertext:\t\t{:#018X}", ciphertext);
710 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
711
712 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
713 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
714 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
715 assert_eq!(cipher_cipher_text, plaintext);
716 println!();
717 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
718
719 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
720 let mut des1 = DES::new_with_key_u64(0xFE0EFE0EFE1FFE1F);
721 let mut des2 = DES::new_with_key_u64(0x0EFE0EFE1FFE1FFE);
722
723 let plaintext = 0x1234567890ABCDEF_u64;
724 let ciphertext = des1.encrypt_u64(plaintext);
725 println!("Plaintext:\t\t{:#018X}", plaintext);
726 println!("Ciphertext:\t\t{:#018X}", ciphertext);
727 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
728
729 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
730 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
731 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
732 assert_eq!(cipher_cipher_text, plaintext);
733
734 let ciphertext = des2.encrypt_u64(plaintext);
735 println!("Plaintext:\t\t{:#018X}", plaintext);
736 println!("Ciphertext:\t\t{:#018X}", ciphertext);
737 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
738
739 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
740 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
741 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
742 assert_eq!(cipher_cipher_text, plaintext);
743 println!();
744 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
745
746 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
747 let mut des1 = DES::new_with_key_u64(0xFEF1FEF1FEE0FEE0);
748 let mut des2 = DES::new_with_key_u64(0xF1FEF1FEE0FEE0FE);
749
750 let plaintext = 0x1234567890ABCDEF_u64;
751 let ciphertext = des1.encrypt_u64(plaintext);
752 println!("Plaintext:\t\t{:#018X}", plaintext);
753 println!("Ciphertext:\t\t{:#018X}", ciphertext);
754 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
755
756 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
757 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
758 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
759 assert_eq!(cipher_cipher_text, plaintext);
760
761 let ciphertext = des2.encrypt_u64(plaintext);
762 println!("Plaintext:\t\t{:#018X}", plaintext);
763 println!("Ciphertext:\t\t{:#018X}", ciphertext);
764 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
765
766 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
767 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
768 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
769 assert_eq!(cipher_cipher_text, plaintext);
770 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
771 println!("-------------------------------");
772}
773
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}
899
900fn des_decryptor_with_key_u64()
901{
902 println!("des_decryptor_with_key_u64");
903 use cryptocol::symmetric::{ BigCryptor64, DES };
904
905 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
906 [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
907 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
908 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ] );
909 let plaintext = 0x_1234567890ABCDEF_u64;
910 let ciphertext = tdes.encrypt_u64(plaintext);
911
912 println!("Plaintext:\t\t{:#018X}", plaintext);
913 println!("Ciphertext:\t\t{:#018X}", ciphertext);
914 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
915
916 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
917 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
918 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
919 assert_eq!(cipher_cipher_text, plaintext);
920 println!();
921
922
923 // Operators
924 let mut tdes = BigCryptor64::new()
925 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64)
926 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
927 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64);
928 let plaintext = 0x_1234567890ABCDEF_u64;
929 let ciphertext = tdes.encrypt_u64(plaintext);
930
931 println!("Plaintext:\t\t{:#018X}", plaintext);
932 println!("Ciphertext:\t\t{:#018X}", ciphertext);
933 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
934
935 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
936 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
937 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
938 assert_eq!(cipher_cipher_text, plaintext);
939 println!("-------------------------------");
940}
941
942fn des_get_key()
943{
944 println!("des_get_key");
945 use cryptocol::symmetric::DES;
946
947 let mut des = DES::new();
948 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
949 let key = des.get_key();
950 print!("K = ");
951 for k in key
952 { print!("{:#02X} ", k); }
953 assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
954}
955
956fn des_get_key_u64()
957{
958 println!("des_get_key_u64");
959 use cryptocol::symmetric::DES;
960
961 let mut des = DES::new();
962 des.set_key_u64(0xEFCDAB9078563412);
963 let key = des.get_key_u64();
964 println!("Key = {}", key);
965 assert_eq!(key, 0xEFCDAB9078563412_u64);
966}
967
968fn des_set_key()
969{
970 println!("des_set_key");
971 use cryptocol::symmetric::DES;
972
973 // Normal case
974 let mut des = DES::new();
975 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
976 let plaintext = 0x1234567890ABCDEF_u64;
977 let ciphertext = des.encrypt_u64(plaintext);
978
979 println!("Plaintext:\t\t{:#018X}", plaintext);
980 println!("Ciphertext:\t\t{:#018X}", ciphertext);
981 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
982
983 let cipher_cipher_text = des.encrypt_u64(ciphertext);
984 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
985 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
986 assert_ne!(cipher_cipher_text, plaintext);
987 println!();
988
989 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
990 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
991 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
992 let mut des1 = DES::new();
993 let mut des2 = DES::new();
994 des1.set_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
995 des2.set_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
996
997 let plaintext = 0x1234567890ABCDEF_u64;
998 let ciphertext1 = des1.encrypt_u64(plaintext);
999 let ciphertext2 = des2.encrypt_u64(plaintext);
1000
1001 println!("Plaintext:\t\t{:#018X}", plaintext);
1002 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1003 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1004 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1005 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1006 assert_eq!(ciphertext1, ciphertext2);
1007
1008 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1009 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1010 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1011 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1012 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1013 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1014 assert_eq!(cipher_cipher_text1, plaintext);
1015 assert_eq!(cipher_cipher_text2, plaintext);
1016 println!();
1017 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
1018 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
1019
1020
1021 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1022 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
1023 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
1024 let mut des1 = DES::new();
1025 let mut des2 = DES::new();
1026 des1.set_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
1027 des2.set_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
1028 let plaintext = 0x1234567890ABCDEF_u64;
1029 let ciphertext1 = des1.encrypt_u64(plaintext);
1030 let ciphertext2 = des2.encrypt_u64(plaintext);
1031
1032 println!("Plaintext:\t\t{:#018X}", plaintext);
1033 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1034 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1035 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1036 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1037 assert_eq!(ciphertext1, ciphertext2);
1038
1039 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1040 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1041 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1042 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1043 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1044 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1045 assert_eq!(cipher_cipher_text1, plaintext);
1046 assert_eq!(cipher_cipher_text2, plaintext);
1047 println!();
1048 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1049 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
1050
1051 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1052 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0] is the same key as the key
1053 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
1054 let mut des1 = DES::new();
1055 let mut des2 = DES::new();
1056 des1.set_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
1057 des2.set_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
1058 let plaintext = 0x1234567890ABCDEF_u64;
1059 let ciphertext1 = des1.encrypt_u64(plaintext);
1060 let ciphertext2 = des2.encrypt_u64(plaintext);
1061
1062 println!("Plaintext:\t\t{:#018X}", plaintext);
1063 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1064 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1065 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1066 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1067 assert_eq!(ciphertext1, ciphertext2);
1068
1069 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1070 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1071 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1072 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1073 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1074 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1075 assert_eq!(cipher_cipher_text1, plaintext);
1076 assert_eq!(cipher_cipher_text2, plaintext);
1077 println!();
1078 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1079 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
1080
1081 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1082 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
1083 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
1084 let mut des1 = DES::new();
1085 let mut des2 = DES::new();
1086 des1.set_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
1087 des2.set_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
1088 let plaintext = 0x1234567890ABCDEF_u64;
1089 let ciphertext1 = des1.encrypt_u64(plaintext);
1090 let ciphertext2 = des2.encrypt_u64(plaintext);
1091
1092 println!("Plaintext:\t\t{:#018X}", plaintext);
1093 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1094 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1095 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1096 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1097 assert_eq!(ciphertext1, ciphertext2);
1098
1099 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1100 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1101 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1102 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1103 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1104 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1105 assert_eq!(cipher_cipher_text1, plaintext);
1106 assert_eq!(cipher_cipher_text2, plaintext);
1107 println!();
1108 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1109 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
1110
1111 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
1112 let mut des1 = DES::new();
1113 let mut des2 = DES::new();
1114 des1.set_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
1115 des2.set_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
1116
1117 let plaintext = 0x1234567890ABCDEF_u64;
1118 let ciphertext = des1.encrypt_u64(plaintext);
1119 println!("Plaintext:\t\t{:#018X}", plaintext);
1120 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1121 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1122
1123 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1124 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1125 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1126 assert_eq!(cipher_cipher_text, plaintext);
1127
1128 let ciphertext = des2.encrypt_u64(plaintext);
1129 println!("Plaintext:\t\t{:#018X}", plaintext);
1130 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1131 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1132
1133 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1134 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1135 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1136 assert_eq!(cipher_cipher_text, plaintext);
1137 println!();
1138 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]
1139 // and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
1140
1141 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
1142 let mut des1 = DES::new();
1143 let mut des2 = DES::new();
1144 des1.set_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
1145 des2.set_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
1146
1147 let plaintext = 0x1234567890ABCDEF_u64;
1148 let ciphertext = des1.encrypt_u64(plaintext);
1149 println!("Plaintext:\t\t{:#018X}", plaintext);
1150 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1151 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1152
1153 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1154 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1155 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1156 assert_eq!(cipher_cipher_text, plaintext);
1157
1158 let ciphertext = des2.encrypt_u64(plaintext);
1159 println!("Plaintext:\t\t{:#018X}", plaintext);
1160 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1161 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1162
1163 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1164 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1165 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1166 assert_eq!(cipher_cipher_text, plaintext);
1167 println!();
1168 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]
1169 // and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
1170
1171 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
1172 let mut des1 = DES::new();
1173 let mut des2 = DES::new();
1174 des1.set_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
1175 des2.set_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
1176
1177 let plaintext = 0x1234567890ABCDEF_u64;
1178 let ciphertext = des1.encrypt_u64(plaintext);
1179 println!("Plaintext:\t\t{:#018X}", plaintext);
1180 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1181 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1182
1183 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1184 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1185 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1186 assert_eq!(cipher_cipher_text, plaintext);
1187
1188 let ciphertext = des2.encrypt_u64(plaintext);
1189 println!("Plaintext:\t\t{:#018X}", plaintext);
1190 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1191 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1192
1193 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1194 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1195 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1196 assert_eq!(cipher_cipher_text, plaintext);
1197 println!();
1198 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]
1199 // and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
1200
1201 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
1202 let mut des1 = DES::new();
1203 let mut des2 = DES::new();
1204 des1.set_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
1205 des2.set_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
1206
1207 let plaintext = 0x1234567890ABCDEF_u64;
1208 let ciphertext = des1.encrypt_u64(plaintext);
1209 println!("Plaintext:\t\t{:#018X}", plaintext);
1210 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1211 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1212
1213 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1214 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1215 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1216 assert_eq!(cipher_cipher_text, plaintext);
1217
1218 let ciphertext = des2.encrypt_u64(plaintext);
1219 println!("Plaintext:\t\t{:#018X}", plaintext);
1220 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1221 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1222
1223 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1224 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1225 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1226 assert_eq!(cipher_cipher_text, plaintext);
1227 println!();
1228 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]
1229 // and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
1230
1231 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
1232 let mut des1 = DES::new();
1233 let mut des2 = DES::new();
1234 des1.set_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
1235 des2.set_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
1236
1237 let plaintext = 0x1234567890ABCDEF_u64;
1238 let ciphertext = des1.encrypt_u64(plaintext);
1239 println!("Plaintext:\t\t{:#018X}", plaintext);
1240 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1241 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1242
1243 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1244 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1245 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1246 assert_eq!(cipher_cipher_text, plaintext);
1247
1248 let ciphertext = des2.encrypt_u64(plaintext);
1249 println!("Plaintext:\t\t{:#018X}", plaintext);
1250 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1251 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1252
1253 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1254 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1255 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1256 assert_eq!(cipher_cipher_text, plaintext);
1257 println!();
1258 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]
1259 // and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
1260
1261 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
1262 let mut des1 = DES::new();
1263 let mut des2 = DES::new();
1264 des1.set_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
1265 des2.set_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
1266
1267 let plaintext = 0x1234567890ABCDEF_u64;
1268 let ciphertext = des1.encrypt_u64(plaintext);
1269 println!("Plaintext:\t\t{:#018X}", plaintext);
1270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1271 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1272
1273 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1274 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1275 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1276 assert_eq!(cipher_cipher_text, plaintext);
1277
1278 let ciphertext = des2.encrypt_u64(plaintext);
1279 println!("Plaintext:\t\t{:#018X}", plaintext);
1280 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1281 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1282
1283 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1284 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1285 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1286 assert_eq!(cipher_cipher_text, plaintext);
1287 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]
1288 // and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
1289 println!("-------------------------------");
1290}
1291
1292fn des_set_key_u64()
1293{
1294 println!("des_set_key_u64");
1295 use cryptocol::symmetric::DES;
1296
1297 // Normal case
1298 let mut des = DES::new();
1299 des.set_key_u64(0xEFCDAB9078563412);
1300 let plaintext = 0x1234567890ABCDEF_u64;
1301 let ciphertext = des.encrypt_u64(plaintext);
1302
1303 println!("Plaintext:\t\t{:#018X}", plaintext);
1304 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1305 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
1306
1307 let cipher_cipher_text = des.encrypt_u64(ciphertext);
1308 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1309 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
1310 assert_ne!(cipher_cipher_text, plaintext);
1311 println!();
1312
1313 // Weak key case 1 for 0x0000000000000000
1314 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
1315 let mut des1 = DES::new();
1316 let mut des2 = DES::new();
1317 des1.set_key_u64(0x0000000000000000);
1318 des2.set_key_u64(0x0101010101010101);
1319
1320 let plaintext = 0x1234567890ABCDEF_u64;
1321 let ciphertext1 = des1.encrypt_u64(plaintext);
1322 let ciphertext2 = des2.encrypt_u64(plaintext);
1323
1324 println!("Plaintext:\t\t{:#018X}", plaintext);
1325 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1326 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1327 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1328 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1329 assert_eq!(ciphertext1, ciphertext2);
1330
1331 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1332 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1333 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1334 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1335 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1336 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1337 assert_eq!(cipher_cipher_text1, plaintext);
1338 assert_eq!(cipher_cipher_text2, plaintext);
1339 println!();
1340 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
1341
1342 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
1343 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
1344 let mut des1 = DES::new();
1345 let mut des2 = DES::new();
1346 des1.set_key_u64(0xFFFFFFFFFFFFFFFF);
1347 des2.set_key_u64(0xFEFEFEFEFEFEFEFE);
1348 let plaintext = 0x1234567890ABCDEF_u64;
1349 let ciphertext1 = des1.encrypt_u64(plaintext);
1350 let ciphertext2 = des2.encrypt_u64(plaintext);
1351
1352 println!("Plaintext:\t\t{:#018X}", plaintext);
1353 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1354 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1355 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1356 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1357 assert_eq!(ciphertext1, ciphertext2);
1358
1359 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1360 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1361 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1362 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1363 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1364 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1365 assert_eq!(cipher_cipher_text1, plaintext);
1366 assert_eq!(cipher_cipher_text2, plaintext);
1367 println!();
1368 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
1369
1370 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
1371 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
1372 let mut des1 = DES::new();
1373 let mut des2 = DES::new();
1374 des1.set_key_u64(0xF1F1F1F1E0E0E0E0);
1375 des2.set_key_u64(0xF0F0F0F0E1E1E1E1);
1376 let plaintext = 0x1234567890ABCDEF_u64;
1377 let ciphertext1 = des1.encrypt_u64(plaintext);
1378 let ciphertext2 = des2.encrypt_u64(plaintext);
1379
1380 println!("Plaintext:\t\t{:#018X}", plaintext);
1381 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1382 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1383 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1384 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1385 assert_eq!(ciphertext1, ciphertext2);
1386
1387 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1388 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1389 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1390 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1391 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1392 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1393 assert_eq!(cipher_cipher_text1, plaintext);
1394 assert_eq!(cipher_cipher_text2, plaintext);
1395 println!();
1396 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
1397
1398 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
1399 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
1400 let mut des1 = DES::new();
1401 let mut des2 = DES::new();
1402 des1.set_key_u64(0x0E0E0E0E1F1F1F1F);
1403 des2.set_key_u64(0x0F0F0F0F1E1E1E1E);
1404 let plaintext = 0x1234567890ABCDEF_u64;
1405 let ciphertext1 = des1.encrypt_u64(plaintext);
1406 let ciphertext2 = des2.encrypt_u64(plaintext);
1407
1408 println!("Plaintext:\t\t{:#018X}", plaintext);
1409 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1410 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1411 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1412 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1413 assert_eq!(ciphertext1, ciphertext2);
1414
1415 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1416 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1417 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1418 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1419 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1420 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1421 assert_eq!(cipher_cipher_text1, plaintext);
1422 assert_eq!(cipher_cipher_text2, plaintext);
1423 println!();
1424 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
1425
1426 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
1427 let mut des1 = DES::new();
1428 let mut des2 = DES::new();
1429 des1.set_key_u64(0x0E010E011F011F01);
1430 des2.set_key_u64(0x010E010E011F011F);
1431
1432 let plaintext = 0x1234567890ABCDEF_u64;
1433 let ciphertext = des1.encrypt_u64(plaintext);
1434 println!("Plaintext:\t\t{:#018X}", plaintext);
1435 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1436 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1437
1438 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1439 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1440 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1441 assert_eq!(cipher_cipher_text, plaintext);
1442
1443 let ciphertext = des2.encrypt_u64(plaintext);
1444 println!("Plaintext:\t\t{:#018X}", plaintext);
1445 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1446 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1447
1448 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1449 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1450 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1451 assert_eq!(cipher_cipher_text, plaintext);
1452 println!();
1453 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
1454
1455 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
1456 let mut des1 = DES::new();
1457 let mut des2 = DES::new();
1458 des1.set_key_u64(0xF101F101E001E001);
1459 des2.set_key_u64(0x01F101F101E001E0);
1460
1461 let plaintext = 0x1234567890ABCDEF_u64;
1462 let ciphertext = des1.encrypt_u64(plaintext);
1463 println!("Plaintext:\t\t{:#018X}", plaintext);
1464 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1465 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1466
1467 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1468 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1469 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1470 assert_eq!(cipher_cipher_text, plaintext);
1471
1472 let ciphertext = des2.encrypt_u64(plaintext);
1473 println!("Plaintext:\t\t{:#018X}", plaintext);
1474 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1475 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1476
1477 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1478 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1479 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1480 assert_eq!(cipher_cipher_text, plaintext);
1481 println!();
1482 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
1483
1484 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
1485 let mut des1 = DES::new();
1486 let mut des2 = DES::new();
1487 des1.set_key_u64(0xFE01FE01FE01FE01);
1488 des2.set_key_u64(0x01FE01FE01FE01FE);
1489
1490 let plaintext = 0x1234567890ABCDEF_u64;
1491 let ciphertext = des1.encrypt_u64(plaintext);
1492 println!("Plaintext:\t\t{:#018X}", plaintext);
1493 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1494 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1495
1496 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1497 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1498 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1499 assert_eq!(cipher_cipher_text, plaintext);
1500
1501 let ciphertext = des2.encrypt_u64(plaintext);
1502 println!("Plaintext:\t\t{:#018X}", plaintext);
1503 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1504 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1505
1506 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1507 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1508 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1509 assert_eq!(cipher_cipher_text, plaintext);
1510 println!();
1511 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
1512
1513 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
1514 let mut des1 = DES::new();
1515 let mut des2 = DES::new();
1516 des1.set_key_u64(0xF10EF10EE01FE01F);
1517 des2.set_key_u64(0x0EF10EF11FE01FE0);
1518
1519 let plaintext = 0x1234567890ABCDEF_u64;
1520 let ciphertext = des1.encrypt_u64(plaintext);
1521 println!("Plaintext:\t\t{:#018X}", plaintext);
1522 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1523 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1524
1525 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1526 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1527 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1528 assert_eq!(cipher_cipher_text, plaintext);
1529
1530 let ciphertext = des2.encrypt_u64(plaintext);
1531 println!("Plaintext:\t\t{:#018X}", plaintext);
1532 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1533 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1534
1535 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1536 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1537 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1538 assert_eq!(cipher_cipher_text, plaintext);
1539 println!();
1540 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
1541
1542 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
1543 let mut des1 = DES::new();
1544 let mut des2 = DES::new();
1545 des1.set_key_u64(0xFE0EFE0EFE1FFE1F);
1546 des2.set_key_u64(0x0EFE0EFE1FFE1FFE);
1547
1548 let plaintext = 0x1234567890ABCDEF_u64;
1549 let ciphertext = des1.encrypt_u64(plaintext);
1550 println!("Plaintext:\t\t{:#018X}", plaintext);
1551 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1552 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1553
1554 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1555 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1556 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1557 assert_eq!(cipher_cipher_text, plaintext);
1558
1559 let ciphertext = des2.encrypt_u64(plaintext);
1560 println!("Plaintext:\t\t{:#018X}", plaintext);
1561 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1562 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1563
1564 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1565 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1566 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1567 assert_eq!(cipher_cipher_text, plaintext);
1568 println!();
1569 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
1570
1571 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
1572 let mut des1 = DES::new();
1573 let mut des2 = DES::new();
1574 des1.set_key_u64(0xFEF1FEF1FEE0FEE0);
1575 des2.set_key_u64(0xF1FEF1FEE0FEE0FE);
1576
1577 let plaintext = 0x1234567890ABCDEF_u64;
1578 let ciphertext = des1.encrypt_u64(plaintext);
1579 println!("Plaintext:\t\t{:#018X}", plaintext);
1580 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1581 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1582
1583 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1584 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1585 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1586 assert_eq!(cipher_cipher_text, plaintext);
1587
1588 let ciphertext = des2.encrypt_u64(plaintext);
1589 println!("Plaintext:\t\t{:#018X}", plaintext);
1590 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1591 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1592
1593 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1594 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1595 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1596 assert_eq!(cipher_cipher_text, plaintext);
1597 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
1598 println!("-------------------------------");
1599}More examples
247fn random_new_with()
248{
249 println!("random_new_with");
250 use cryptocol::random::{ AnyGen, RandGen };
251 use cryptocol::define_utypes_with;
252 define_utypes_with!(u64);
253
254 // Example for BIG_KECCAK_1024
255 use cryptocol::hash::BIG_KECCAK_1024;
256 let mut rand = RandGen::new_with(BIG_KECCAK_1024::new(), BIG_KECCAK_1024::new());
257 let num: U512 = rand.random_prime_with_msb_set_using_miller_rabin_biguint(5);
258 println!("Random number = {}", num);
259
260 // Example for SHA3_512
261 use cryptocol::hash::SHA3_512;
262 let mut any = AnyGen::new_with(SHA3_512::new(), SHA3_512::new());
263 let num: U256 = any.random_prime_using_miller_rabin_biguint(5);
264 println!("Any number = {}", num);
265
266 // Example for SHA2_512
267 use cryptocol::hash::SHA2_512;
268 let mut any = AnyGen::new_with(SHA2_512::new(), SHA2_512::new());
269 let num: U1024 = any.random_with_msb_set_biguint();
270 println!("Any number = {}", num);
271
272 // Example for SHAKE_256
273 use cryptocol::hash::SHAKE_256;
274 let mut rand = RandGen::new_with(SHAKE_256::new(), SHAKE_256::new());
275 let num: U768 = rand.random_odd_biguint();
276 println!("Random number = {}", num);
277
278 // Example for SHAKE_128
279 use cryptocol::hash::SHAKE_128;
280 let mut any = AnyGen::new_with(SHAKE_128::new(), SHAKE_128::new());
281 let num: U512 = any.random_biguint();
282 println!("Any number = {}", num);
283
284 // Example for SHA3_256
285 use cryptocol::hash::SHA3_256;
286 let mut any = AnyGen::new_with(SHA3_256::new(), SHA3_256::new());
287 let num: U384 = any.random_biguint();
288 println!("Any number = {}", num);
289
290 // Example for SHA2_256
291 use cryptocol::hash::SHA2_256;
292 let mut any = AnyGen::new_with(SHA2_256::new(), SHA2_256::new());
293 println!("Any number = {}", any.random_u128());
294
295 // Example for SHA1 and SHA0
296 use cryptocol::hash::{ SHA1, SHA0 };
297 let mut any = AnyGen::new_with(SHA1::new(), SHA0::new());
298 println!("Any number = {}", any.random_u64());
299
300 // Example for MD5 and MD4
301 use cryptocol::hash::{ MD5, MD4 };
302 let mut any = AnyGen::new_with(MD5::new(), MD4::new());
303 println!("Any number = {}", any.random_u32());
304
305 // Example for AES_128
306 use cryptocol::symmetric::AES_128;
307 let mut any = RandGen::new_with(AES_128::new(), AES_128::new());
308 println!("Random number = {}", any.random_u16());
309
310 // Example for DES
311 use cryptocol::symmetric::DES;
312 let mut any = AnyGen::new_with(DES::new(), DES::new());
313 println!("Any number = {}", any.random_u8());
314 println!("-------------------------------");
315}Sourcepub fn new_with_key(key: [u8; 8]) -> Self
pub fn new_with_key(key: [u8; 8]) -> Self
Constructs a new object DES_Generic.
§Arguments
- The argument
keyis the array of u8 that has 8 elements. - Remember that inverted parity bits do not affect the 56-bit real key. So, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00], [0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01], etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
This method sets the key to be the given argument key.
§Example 1 for normal case
use cryptocol::symmetric::DES;
let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
let plaintext = 0x1234567890ABCDEF_u64;
let ciphertext = des.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
let cipher_cipher_text = des.encrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
assert_ne!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
37fn des_quick_start_instantiation_with_key()
38{
39 println!("des_quick_start_instantiation_with_key()");
40 use cryptocol::symmetric::DES;
41
42 let key = 0x_1234567890ABCDEF_u64;
43 let mut _a_des = DES::new_with_key_u64(key);
44
45 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
46 let mut _a_des = DES::new_with_key(key);
47 println!("-------------------------------");
48}
49
50fn des_quick_start_instantiation_without_key()
51{
52 println!("des_quick_start_instantiation_without_key()");
53 use cryptocol::symmetric::DES;
54
55 let mut a_des = DES::new();
56 let key = 0x_1234567890ABCDEF_u64;
57 a_des.set_key_u64(key);
58
59 let mut a_des = DES::new();
60 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
61 a_des.set_key(key);
62 println!("-------------------------------");
63}
64
65fn des_quick_start_encryption_decryption_16_rounds()
66{
67 println!("des_quick_start_encryption_decryption_16_rounds()");
68 use std::io::Write;
69 use std::fmt::Write as _;
70 use cryptocol::symmetric::{ CBC_PKCS7, DES };
71
72 let mut a_des = DES::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
73 let message = "In the beginning God created the heavens and the earth.";
74 println!("M =\t{}", message);
75 let iv = 0x_FEDCBA0987654321_u64;
76 println!("IV =\t{}", iv);
77 let mut cipher = Vec::<u8>::new();
78 a_des.encrypt_str_into_vec(iv, message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "4B B5 ED DC A0 58 7E 6D 6C 3B A2 00 38 C3 D4 29 42 B1 CF 0D E9 FA EA 11 11 6B C8 30 73 39 DD B7 3F 96 9B A3 76 05 34 7E 64 2F D4 CC B2 68 33 64 C5 9E EF 01 A9 4A FD 5B ");
87
88 let mut recovered = String::new();
89 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
90 println!("B (16 rounds) =\t{}", recovered);
91 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
92 assert_eq!(recovered, message);
93 println!("-------------------------------");
94}
95
96fn des_quick_start_encryption_decryption_256_rounds()
97{
98 println!("des_quick_start_encryption_decryption_256_rounds()");
99 use std::io::Write;
100 use std::fmt::Write as _;
101 use cryptocol::symmetric::{ CBC_PKCS7, DES_Expanded };
102
103 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
104 let message = "In the beginning God created the heavens and the earth.";
105 println!("M =\t{}", message);
106 let iv = 0x_FEDCBA0987654321_u64;
107 println!("IV =\t{}", iv);
108 let mut cipher = Vec::<u8>::new();
109 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
110 print!("C =\t");
111 for c in cipher.clone()
112 { print!("{:02X} ", c); }
113 println!();
114 let mut txt = String::new();
115 for c in cipher.clone()
116 { write!(txt, "{:02X} ", c); }
117 assert_eq!(txt, "0B EA 6B BC 68 F9 B0 3E 7D AF DE 71 9C 08 AA 16 42 40 1C C8 DC 40 51 C6 8D D4 E7 D2 0B A4 F2 09 02 02 C2 6E 99 BC 9E 2A F4 11 7E 48 A7 ED 76 70 C6 9D C6 BD A6 9B 58 8B ");
118
119 let mut recovered = String::new();
120 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
121 println!("B =\t{}", recovered);
122 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
123 assert_eq!(recovered, message);
124 println!("-------------------------------");
125}
126
127fn des_basic_operation_main()
128{
129 des_new();
130 des_new_with_key();
131 des_new_with_key_u64();
132 des_encryptor_with_key();
133 des_encryptor_with_key_u64();
134 des_decryptor_with_key();
135 des_decryptor_with_key_u64();
136 des_get_key();
137 des_get_key_u64();
138 des_set_key();
139 des_set_key_u64();
140 des_turn_inverse();
141 des_turn_encryptor();
142 des_turn_decryptor();
143}
144
145fn des_new()
146{
147 println!("des_new()");
148 use cryptocol::symmetric::DES;
149
150 let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
151 let plaintext = 0x1234567890ABCDEF_u64;
152 let ciphertext = des.encrypt_u64(plaintext);
153
154 println!("Plaintext:\t\t{:#018X}", plaintext);
155 println!("Ciphertext:\t\t{:#018X}", ciphertext);
156 assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
157
158 let cipher_cipher_text = des.encrypt_u64(ciphertext);
159 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
160 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
161 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
162
163 #[cfg(test)]
164 des_compile_fail_new();
165 println!("-------------------------------");
166}
167
168#[test]
169fn des_compile_fail_new()
170{
171 use cryptocol::symmetric::DES;
172 let des = DES::new();
173 // It cannot be compiled!
174 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
175}
176
177fn des_new_with_key()
178{
179 println!("des_new_with_key()");
180 use cryptocol::symmetric::DES;
181
182 // Normal case
183 let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
184 let plaintext = 0x1234567890ABCDEF_u64;
185 let ciphertext = des.encrypt_u64(plaintext);
186
187 println!("Plaintext:\t\t{:#018X}", plaintext);
188 println!("Ciphertext:\t\t{:#018X}", ciphertext);
189 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
190
191 let cipher_cipher_text = des.encrypt_u64(ciphertext);
192 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
193 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
194 assert_ne!(cipher_cipher_text, plaintext);
195 println!();
196
197 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
198 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
199 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
200 let mut des1 = DES::new_with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
201 let mut des2 = DES::new_with_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
202
203 let plaintext = 0x1234567890ABCDEF_u64;
204 let ciphertext1 = des1.encrypt_u64(plaintext);
205 let ciphertext2 = des2.encrypt_u64(plaintext);
206
207 println!("Plaintext:\t\t{:#018X}", plaintext);
208 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
209 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
210 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
211 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
212 assert_eq!(ciphertext1, ciphertext2);
213
214 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
215 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
216 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
217 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
218 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
219 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
220 assert_eq!(cipher_cipher_text1, plaintext);
221 assert_eq!(cipher_cipher_text2, plaintext);
222 println!();
223 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
224 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
225
226
227 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
228 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
229 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
230 let mut des1 = DES::new_with_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
231 let mut des2 = DES::new_with_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
232 let plaintext = 0x1234567890ABCDEF_u64;
233 let ciphertext1 = des1.encrypt_u64(plaintext);
234 let ciphertext2 = des2.encrypt_u64(plaintext);
235
236 println!("Plaintext:\t\t{:#018X}", plaintext);
237 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
238 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
239 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
240 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
241 assert_eq!(ciphertext1, ciphertext2);
242
243 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
244 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
245 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
246 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
247 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
248 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
249 assert_eq!(cipher_cipher_text1, plaintext);
250 assert_eq!(cipher_cipher_text2, plaintext);
251 println!();
252 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
253 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
254
255 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
256 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1] is the same key as the key
257 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
258 let mut des1 = DES::new_with_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
259 let mut des2 = DES::new_with_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
260 let plaintext = 0x1234567890ABCDEF_u64;
261 let ciphertext1 = des1.encrypt_u64(plaintext);
262 let ciphertext2 = des2.encrypt_u64(plaintext);
263
264 println!("Plaintext:\t\t{:#018X}", plaintext);
265 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
266 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
267 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
268 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
269 assert_eq!(ciphertext1, ciphertext2);
270
271 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
272 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
273 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
274 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
275 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
276 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
277 assert_eq!(cipher_cipher_text1, plaintext);
278 assert_eq!(cipher_cipher_text2, plaintext);
279 println!();
280 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
281 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
282
283 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
284 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
285 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
286 let mut des1 = DES::new_with_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
287 let mut des2 = DES::new_with_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
288 let plaintext = 0x1234567890ABCDEF_u64;
289 let ciphertext1 = des1.encrypt_u64(plaintext);
290 let ciphertext2 = des2.encrypt_u64(plaintext);
291
292 println!("Plaintext:\t\t{:#018X}", plaintext);
293 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
294 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
295 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
296 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
297 assert_eq!(ciphertext1, ciphertext2);
298
299 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
300 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
301 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
302 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
303 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
304 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
305 assert_eq!(cipher_cipher_text1, plaintext);
306 assert_eq!(cipher_cipher_text2, plaintext);
307 println!();
308 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
309 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
310
311 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
312 let mut des1 = DES::new_with_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
313 let mut des2 = DES::new_with_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
314
315 let plaintext = 0x1234567890ABCDEF_u64;
316 let ciphertext = des1.encrypt_u64(plaintext);
317 println!("Plaintext:\t\t{:#018X}", plaintext);
318 println!("Ciphertext:\t\t{:#018X}", ciphertext);
319 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
320
321 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
322 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
323 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
324 assert_eq!(cipher_cipher_text, plaintext);
325
326 let ciphertext = des2.encrypt_u64(plaintext);
327 println!("Plaintext:\t\t{:#018X}", plaintext);
328 println!("Ciphertext:\t\t{:#018X}", ciphertext);
329 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
330
331 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
332 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
333 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
334 assert_eq!(cipher_cipher_text, plaintext);
335 println!();
336 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
337
338 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
339 let mut des1 = DES::new_with_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
340 let mut des2 = DES::new_with_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
341
342 let plaintext = 0x1234567890ABCDEF_u64;
343 let ciphertext = des1.encrypt_u64(plaintext);
344 println!("Plaintext:\t\t{:#018X}", plaintext);
345 println!("Ciphertext:\t\t{:#018X}", ciphertext);
346 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
347
348 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
349 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
350 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
351 assert_eq!(cipher_cipher_text, plaintext);
352
353 let ciphertext = des2.encrypt_u64(plaintext);
354 println!("Plaintext:\t\t{:#018X}", plaintext);
355 println!("Ciphertext:\t\t{:#018X}", ciphertext);
356 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
357
358 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
359 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
360 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
361 assert_eq!(cipher_cipher_text, plaintext);
362 println!();
363 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
364
365 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
366 let mut des1 = DES::new_with_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
367 let mut des2 = DES::new_with_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
368
369 let plaintext = 0x1234567890ABCDEF_u64;
370 let ciphertext = des1.encrypt_u64(plaintext);
371 println!("Plaintext:\t\t{:#018X}", plaintext);
372 println!("Ciphertext:\t\t{:#018X}", ciphertext);
373 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
374
375 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
376 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
377 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
378 assert_eq!(cipher_cipher_text, plaintext);
379
380 let ciphertext = des2.encrypt_u64(plaintext);
381 println!("Plaintext:\t\t{:#018X}", plaintext);
382 println!("Ciphertext:\t\t{:#018X}", ciphertext);
383 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
384
385 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
386 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
387 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
388 assert_eq!(cipher_cipher_text, plaintext);
389 println!();
390 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
391
392 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
393 let mut des1 = DES::new_with_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
394 let mut des2 = DES::new_with_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
395
396 let plaintext = 0x1234567890ABCDEF_u64;
397 let ciphertext = des1.encrypt_u64(plaintext);
398 println!("Plaintext:\t\t{:#018X}", plaintext);
399 println!("Ciphertext:\t\t{:#018X}", ciphertext);
400 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
401
402 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
403 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
404 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
405 assert_eq!(cipher_cipher_text, plaintext);
406
407 let ciphertext = des2.encrypt_u64(plaintext);
408 println!("Plaintext:\t\t{:#018X}", plaintext);
409 println!("Ciphertext:\t\t{:#018X}", ciphertext);
410 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
411
412 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
413 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
414 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
415 assert_eq!(cipher_cipher_text, plaintext);
416 println!();
417 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
418
419 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
420 let mut des1 = DES::new_with_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
421 let mut des2 = DES::new_with_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
422
423 let plaintext = 0x1234567890ABCDEF_u64;
424 let ciphertext = des1.encrypt_u64(plaintext);
425 println!("Plaintext:\t\t{:#018X}", plaintext);
426 println!("Ciphertext:\t\t{:#018X}", ciphertext);
427 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
428
429 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
430 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
431 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
432 assert_eq!(cipher_cipher_text, plaintext);
433
434 let ciphertext = des2.encrypt_u64(plaintext);
435 println!("Plaintext:\t\t{:#018X}", plaintext);
436 println!("Ciphertext:\t\t{:#018X}", ciphertext);
437 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
438
439 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
440 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
441 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
442 assert_eq!(cipher_cipher_text, plaintext);
443 println!();
444 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
445
446 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
447 let mut des1 = DES::new_with_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
448 let mut des2 = DES::new_with_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
449
450 let plaintext = 0x1234567890ABCDEF_u64;
451 let ciphertext = des1.encrypt_u64(plaintext);
452 println!("Plaintext:\t\t{:#018X}", plaintext);
453 println!("Ciphertext:\t\t{:#018X}", ciphertext);
454 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
455
456 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
457 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
458 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
459 assert_eq!(cipher_cipher_text, plaintext);
460
461 let ciphertext = des2.encrypt_u64(plaintext);
462 println!("Plaintext:\t\t{:#018X}", plaintext);
463 println!("Ciphertext:\t\t{:#018X}", ciphertext);
464 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
465
466 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
467 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
468 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
469 assert_eq!(cipher_cipher_text, plaintext);
470 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
471
472 #[cfg(test)]
473 des_compile_fail_new_with_key();
474 println!("-------------------------------");
475}More examples
53fn bigcryptor64_instantiation_with_keys()
54{
55 println!("bigcryptor64_instantiation_with_keys()");
56 use cryptocol::symmetric::{ BigCryptor64, DES };
57 let mut _tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
58 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
59 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
60 println!("-------------------------------");
61}
62
63fn bigcryptor64_set_keys_u64_later()
64{
65 println!("bigcryptor64_instantiation_with_keys_u64()");
66 use cryptocol::symmetric::{ BigCryptor64, DES };
67 let mut tdes = BigCryptor64::new();
68 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
69 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
70 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
71 tdes.push_small_cryptor(des1);
72 tdes.push_small_cryptor(des2);
73 tdes.push_small_cryptor(des3);
74 println!("-------------------------------");
75}
76
77fn bigcryptor64_set_keys_later()
78{
79 println!("bigcryptor64_instantiation_with_keys()");
80 use cryptocol::symmetric::{ BigCryptor64, DES };
81 let mut tdes = BigCryptor64::new();
82 let des1 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
83 let des2 = DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]);
84 let des3 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
85 tdes.push_small_cryptor(des1);
86 tdes.push_small_cryptor(des2);
87 tdes.push_small_cryptor(des3);
88 println!("-------------------------------");
89}
90
91fn bigcryptor64_cbc_pkcs7()
92{
93 println!("bigcryptor64_cbc_pkcs7()");
94 use std::fmt::Write as _;
95 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
96 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
97 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
98 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
99
100 let iv = 0x_FEDCBA0987654321_u64;
101 println!("IV = {:#018X}", iv);
102 let message = "In the beginning God created the heavens and the earth.";
103 println!("M =\t{}", message);
104 let mut cipher = Vec::<u8>::new();
105 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
106 print!("C =\t");
107 for c in cipher.clone()
108 { print!("{:02X} ", c); }
109 println!();
110 let mut txt = String::new();
111 for c in cipher.clone()
112 { write!(txt, "{:02X} ", c); }
113 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
114
115 let mut recovered = String::new();
116 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
117 println!("B =\t{}", recovered);
118 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
119 assert_eq!(recovered, message);
120 println!("-------------------------------");
121}
122
123fn bigcryptor64_basic_operation_main()
124{
125 bigcryptor64_new();
126 bigcryptor64_new_with_small_cryptor_array();
127 bigcryptor64_new_with_small_cryptor_vec();
128 bigcryptor64_push_small_cryptor();
129 bigcryptor64_push_small_cryptor_array();
130 bigcryptor64_push_small_cryptor_vec();
131 bigcryptor64_turn_inverse();
132 bigcryptor64_turn_encryptor();
133 bigcryptor64_turn_decryptor();
134 bigcryptor64_encrypt_u64();
135 bigcryptor64_decrypt_u64();
136 bigcryptor64_encrypt_array_u64();
137 bigcryptor64_decrypt_array_u64();
138 bigcryptor64_is_successful();
139 bigcryptor64_is_failed();
140}
141
142fn bigcryptor64_new()
143{
144 println!("bigcryptor64_new()");
145 use cryptocol::symmetric::{ BigCryptor64, DES };
146
147 // Case 1
148 let mut tdes = BigCryptor64::new();
149 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
150 tdes.push_small_cryptor(DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]));
151 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
152
153 // Case 2
154 let mut _tdes = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
155 + DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
156 + DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
157 println!("-------------------------------");
158}
159
160fn bigcryptor64_new_with_small_cryptor_array()
161{
162 println!("bigcryptor64_new_with_small_cryptor_array()");
163 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
164
165 // Case 1
166 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
167 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
168 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
169 let mut _tdes = BigCryptor64::new_with_small_cryptor_array(cryptors);
170 println!("-------------------------------");
171}
172
173fn bigcryptor64_new_with_small_cryptor_vec()
174{
175 println!("bigcryptor64_new_with_small_cryptor_vec()");
176 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
177
178 // Case 1
179 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
180 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
181 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
182 let mut _tdes = BigCryptor64::new_with_small_cryptor_vec(cryptors);
183 println!("-------------------------------");
184}
185
186fn bigcryptor64_push_small_cryptor()
187{
188 println!("bigcryptor64_new_with_small_cryptor_vec()");
189 use cryptocol::symmetric::{ BigCryptor64, DES };
190
191 // Case 1
192 let mut tdes = BigCryptor64::new();
193 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
195 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
196 tdes.push_small_cryptor(des1);
197 tdes.push_small_cryptor(des2);
198 tdes.push_small_cryptor(des3);
199 println!("-------------------------------");
200}
201
202fn bigcryptor64_push_small_cryptor_array()
203{
204 println!("bigcryptor64_push_small_cryptor_array()");
205 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
206
207 // Case 1
208 let mut tdes = BigCryptor64::new();
209 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
210 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
211 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
212 tdes.push_small_cryptor_array(cryptors);
213 println!("-------------------------------");
214}
215
216fn bigcryptor64_push_small_cryptor_vec()
217{
218 println!("bigcryptor64_push_small_cryptor_vec()");
219 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
220
221 // Case 1
222 let mut tdes = BigCryptor64::new();
223 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
224 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
225 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
226 tdes.push_small_cryptor_vec(cryptors);
227 println!("-------------------------------");
228}
229
230fn bigcryptor64_turn_inverse()
231{
232 println!("bigcryptor64_turn_inverse");
233 use cryptocol::symmetric::{ BigCryptor64, DES, Rijndael_64_64, SmallCryptor };
234 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
235 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
236 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
237 let des = DES::new_with_key([0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
238 let rijndael = Rijndael_64_64::new_with_key(&[0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE]);
239 tdes.turn_inverse();
240 let mut bigcryptor = des + rijndael + tdes;
241
242 let plaintext = 0x_1234567890ABCDEF_u64;
243 println!("Plaintext:\t\t{:#018X}", plaintext);
244 let ciphertext = bigcryptor.encrypt_u64(plaintext);
245 println!("Ciphertext:\t\t{:#018X}", ciphertext);
246 assert_eq!(ciphertext, 0x_0036D446DF6D218F_u64);
247
248 let recovered_text = bigcryptor.decrypt_u64(ciphertext);
249 println!("Recovered text:\t{:#018X}", recovered_text);
250 assert_eq!(recovered_text, 0x1234567890ABCDEF_u64);
251 assert_eq!(recovered_text, plaintext);
252 println!("-------------------------------");
253}
254
255fn bigcryptor64_turn_encryptor()
256{
257 println!("bigcryptor64_turn_encryptor");
258 use cryptocol::symmetric::{ BigCryptor64, DES, Rijndael_64_64, SmallCryptor };
259 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
260 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
261 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
262 let des = DES::new_with_key([0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
263 let rijndael = Rijndael_64_64::new_with_key(&[0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE]);
264 tdes.turn_encryptor();
265 let mut bigcryptor = des + rijndael + tdes;
266
267 let plaintext = 0x_1234567890ABCDEF_u64;
268 println!("Plaintext:\t\t{:#018X}", plaintext);
269 let ciphertext = bigcryptor.encrypt_u64(plaintext);
270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
271 assert_eq!(ciphertext, 0x_911ED9892E52BC7C_u64);
272
273 let recovered_text = bigcryptor.decrypt_u64(ciphertext);
274 println!("Recovered text:\t{:#018X}", recovered_text);
275 assert_eq!(recovered_text, 0x1234567890ABCDEF_u64);
276 assert_eq!(recovered_text, plaintext);
277 println!("-------------------------------");
278}
279
280fn bigcryptor64_turn_decryptor()
281{
282 println!("bigcryptor64_turn_decryptor");
283 use cryptocol::symmetric::{ BigCryptor64, DES, Rijndael_64_64, SmallCryptor };
284 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
285 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
286 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
287 let des = DES::new_with_key([0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
288 let rijndael = Rijndael_64_64::new_with_key(&[0x21, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE]);
289 tdes.turn_decryptor();
290 let mut bigcryptor = des + rijndael + tdes;
291
292 let plaintext = 0x_1234567890ABCDEF_u64;
293 println!("Plaintext:\t\t{:#018X}", plaintext);
294 let ciphertext = bigcryptor.encrypt_u64(plaintext);
295 println!("Ciphertext:\t\t{:#018X}", ciphertext);
296 assert_eq!(ciphertext, 0x_0036D446DF6D218F_u64);
297
298 let recovered_text = bigcryptor.decrypt_u64(ciphertext);
299 println!("Recovered text:\t{:#018X}", recovered_text);
300 assert_eq!(recovered_text, 0x1234567890ABCDEF_u64);
301 assert_eq!(recovered_text, plaintext);
302 println!("-------------------------------");
303}
304
305fn bigcryptor64_encrypt_u64()
306{
307 println!("bigcryptor64_encrypt_u64()");
308 use cryptocol::symmetric::{ BigCryptor64, DES };
309
310 // Case 1
311 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
312 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
313 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
314 let message = 0x1234567890ABCDEF_u64;
315 println!("M = {:#018X}", message);
316 let cipher = tdes.encrypt_u64(message);
317 println!("C = {:#018X}", cipher);
318 assert_eq!(cipher, 0x_CA61814E7AE964BA_u64);
319 println!("-------------------------------");
320}
321
322fn bigcryptor64_decrypt_u64()
323{
324 println!("bigcryptor64_decrypt_u64()");
325 use cryptocol::symmetric::{ BigCryptor64, DES };
326
327 // Case 1
328 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
329 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
330 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
331 let message = 0x1234567890ABCDEF_u64;
332 println!("M = {:#018X}", message);
333 let cipher = tdes.encrypt_u64(message);
334 println!("C = {:#018X}", cipher);
335 assert_eq!(cipher, 0x_CA61814E7AE964BA_u64);
336
337 let recovered = tdes.decrypt_u64(cipher);
338 println!("B = {:#018X}", recovered);
339 assert_eq!(recovered, 0x1234567890ABCDEF_u64);
340 assert_eq!(recovered, message);
341 println!("-------------------------------");
342}
343
344fn bigcryptor64_encrypt_array_u64()
345{
346 println!("bigcryptor64_encrypt_array_u64()");
347 use cryptocol::symmetric::{ BigCryptor64, DES };
348
349 // Case 1
350 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
351 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
352 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
353 let message = [0x1234567890ABCDEF_u64, 0x1122334455667788, 0x9900AABBCCDDEEFF];
354 print!("M = ");
355 for msg in message.clone()
356 { print!("{:#018X} ", msg); }
357 println!();
358
359 let mut cipher = [0_u64; 3];
360 tdes.encrypt_array_u64(&message, &mut cipher);
361 print!("C = ");
362 for c in cipher.clone()
363 { print!("{:#018X} ", c); }
364 println!();
365 assert_eq!(cipher[0], 0x_CA61814E7AE964BA_u64);
366 assert_eq!(cipher[1], 0x_073450DF82262B1B_u64);
367 assert_eq!(cipher[2], 0x_51712805A458A102_u64);
368 println!("-------------------------------");
369}
370
371fn bigcryptor64_decrypt_array_u64()
372{
373 println!("bigcryptor64_decrypt_array_u64()");
374 use cryptocol::symmetric::{ BigCryptor64, DES };
375
376 // Case 1
377 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
378 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
379 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
380 let message = [0x1234567890ABCDEF_u64, 0x1122334455667788, 0x9900AABBCCDDEEFF];
381 print!("M = ");
382 for msg in message.clone()
383 { print!("{:#018X} ", msg); }
384 println!();
385
386 let mut cipher = [0_u64; 3];
387 tdes.encrypt_array_u64(&message, &mut cipher);
388 print!("C = ");
389 for c in cipher.clone()
390 { print!("{:#018X} ", c); }
391 println!();
392 assert_eq!(cipher[0], 0x_CA61814E7AE964BA_u64);
393 assert_eq!(cipher[1], 0x_073450DF82262B1B_u64);
394 assert_eq!(cipher[2], 0x_51712805A458A102_u64);
395
396 let mut recovered = [0_u64; 3];
397 tdes.decrypt_array_u64(&cipher, &mut recovered);
398 print!("B = ");
399 for r in recovered.clone()
400 { print!("{:#018X} ", r); }
401 println!();
402 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
403 assert_eq!(recovered[1], 0x_1122334455667788_u64);
404 assert_eq!(recovered[2], 0x_9900AABBCCDDEEFF_u64);
405 assert_eq!(recovered[0], message[0]);
406 assert_eq!(recovered[1], message[1]);
407 assert_eq!(recovered[2], message[2]);
408 println!("-------------------------------");
409}
410
411fn bigcryptor64_is_successful()
412{
413 println!("bigcryptor64_is_successful");
414 use std::io::Write;
415 use std::fmt::Write as _;
416 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
417
418 // Successful case for encryption
419 let iv = 0x_FEDCBA0987654321_u64;
420 println!("IV = {}", iv);
421 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
422 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
423 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
424
425 let message = "";
426 println!("M =\t{}", message);
427 let mut cipher = [0_u8; 8];
428 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
429 println!("The length of ciphertext = {}", len);
430 assert_eq!(len, 8);
431 let success = tdes.is_successful();
432 assert_eq!(success, true);
433 print!("C =\t");
434 for c in cipher.clone()
435 { print!("{:02X} ", c); }
436 println!();
437 let mut txt = String::new();
438 for c in cipher.clone()
439 { write!(txt, "{:02X} ", c); }
440 assert_eq!(txt, "17 C8 15 48 EE 85 42 43 ");
441 println!();
442
443 // Successful case for decryption
444 let iv = 0x_FEDCBA0987654321_u64;
445 println!("IV = {}", iv);
446 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
447 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
448 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
449
450 let cipher = [0x17_u8, 0xC8, 0x15, 0x48, 0xEE, 0x85, 0x42, 0x43];
451 print!("C =\t");
452 for c in cipher.clone()
453 { print!("{:02X} ", c); }
454 println!();
455 let mut recovered = [0u8; 8];
456 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
457 println!("The length of plaintext = {}", len);
458 assert_eq!(len, 0);
459 let success = tdes.is_successful();
460 assert_eq!(success, true);
461 print!("Ba =\t");
462 for b in recovered.clone()
463 { print!("{:02X} ", b); }
464 println!();
465 let mut txt = String::new();
466 for c in recovered.clone()
467 { write!(txt, "{:02X} ", c); }
468 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
469
470 let mut converted = String::new();
471 unsafe { converted.as_mut_vec() }.write(&recovered);
472 unsafe { converted.as_mut_vec() }.truncate(len as usize);
473 println!("Bb =\t{}", converted);
474 assert_eq!(converted, "");
475 assert_eq!(converted, message);
476 println!();
477
478
479 // Failure case for encryption
480 let iv = 0x_FEDCBA0987654321_u64;
481 println!("IV = {}", iv);
482 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
483 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
484 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
485
486 let message = "";
487 println!("M =\t{}", message);
488 let mut cipher = [0_u8; 4];
489 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
490 println!("The length of ciphertext = {}", len);
491 assert_eq!(len, 0);
492 let success = tdes.is_successful();
493 assert_eq!(success, false);
494 let mut txt = String::new();
495 for c in cipher.clone()
496 { write!(txt, "{:02X} ", c); }
497 assert_eq!(txt, "00 00 00 00 ");
498 println!();
499
500 // Failure case for decryption
501 let iv = 0x_FEDCBA0987654321_u64;
502 println!("IV = {}", iv);
503 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
504 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
505 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
506
507 let cipher = [0x17_u8, 0xC8, 0x15, 0x48];
508 print!("C =\t");
509 for c in cipher.clone()
510 { print!("{:02X} ", c); }
511 println!();
512 let mut recovered = [0u8; 8];
513 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
514 println!("The length of plaintext = {}", len);
515 assert_eq!(len, 0);
516 let success = tdes.is_successful();
517 assert_eq!(success, false);
518 println!("-------------------------------");
519}
520
521fn bigcryptor64_is_failed()
522{
523 println!("bigcryptor64_is_failed");
524 use std::io::Write;
525 use std::fmt::Write as _;
526 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
527
528 // Successful case for encryption
529 let iv = 0x_FEDCBA0987654321_u64;
530 println!("IV = {}", iv);
531 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
532 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
533 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
534
535 let message = "";
536 println!("M =\t{}", message);
537 let mut cipher = [0_u8; 8];
538 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
539 println!("The length of ciphertext = {}", len);
540 assert_eq!(len, 8);
541 let failure = tdes.is_failed();
542 assert_eq!(failure, false);
543 print!("C =\t");
544 for c in cipher.clone()
545 { print!("{:02X} ", c); }
546 println!();
547 let mut txt = String::new();
548 for c in cipher.clone()
549 { write!(txt, "{:02X} ", c); }
550 assert_eq!(txt, "17 C8 15 48 EE 85 42 43 ");
551 println!();
552
553 // Successful case for decryption
554 let iv = 0x_FEDCBA0987654321_u64;
555 println!("IV = {}", iv);
556 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
557 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
558 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
559
560 let cipher = [0x17_u8, 0xC8, 0x15, 0x48, 0xEE, 0x85, 0x42, 0x43];
561 print!("C =\t");
562 for c in cipher.clone()
563 { print!("{:02X} ", c); }
564 println!();
565 let mut recovered = [0u8; 8];
566 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
567 println!("The length of plaintext = {}", len);
568 assert_eq!(len, 0);
569 let failure = tdes.is_failed();
570 assert_eq!(failure, false);
571 print!("Ba =\t");
572 for b in recovered.clone()
573 { print!("{:02X} ", b); }
574 println!();
575 let mut txt = String::new();
576 for c in recovered.clone()
577 { write!(txt, "{:02X} ", c); }
578 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
579
580 let mut converted = String::new();
581 unsafe { converted.as_mut_vec() }.write(&recovered);
582 unsafe { converted.as_mut_vec() }.truncate(len as usize);
583 println!("Bb =\t{}", converted);
584 assert_eq!(converted, "");
585 assert_eq!(converted, message);
586 println!();
587
588
589 // Failure case for encryption
590 let iv = 0x_FEDCBA0987654321_u64;
591 println!("IV = {}", iv);
592 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
593 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
594 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
595
596 let message = "";
597 println!("M =\t{}", message);
598 let mut cipher = [0_u8; 4];
599 let len = tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
600 println!("The length of ciphertext = {}", len);
601 assert_eq!(len, 0);
602 let failure = tdes.is_failed();
603 assert_eq!(failure, true);
604 let mut txt = String::new();
605 for c in cipher.clone()
606 { write!(txt, "{:02X} ", c); }
607 assert_eq!(txt, "00 00 00 00 ");
608 println!();
609
610 // Failure case for decryption
611 let iv = 0x_FEDCBA0987654321_u64;
612 println!("IV = {}", iv);
613 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
614 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
615 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
616
617 let cipher = [0x17_u8, 0xC8, 0x15, 0x48];
618 print!("C =\t");
619 for c in cipher.clone()
620 { print!("{:02X} ", c); }
621 println!();
622
623 let mut recovered = [0u8; 8];
624 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
625 println!("The length of plaintext = {}", len);
626 assert_eq!(len, 0);
627 let failure = tdes.is_failed();
628 assert_eq!(failure, true);
629 println!("-------------------------------");
630}Sourcepub fn new_with_key_u64(key: u64) -> Self
pub fn new_with_key_u64(key: u64) -> Self
Constructs a new object DES_Generic.
§Arguments
- The argument
keyis ofu64. - It should be in the same endianness of machine. For example,
if the intended key is [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD,
0xEF], the key in
u64for this argument is 0x_1234567890ABCDEF_u64 for big-endian machine, and the key inu64for this argument is 0x_EFCDAB9078563412_u64 for little-endian machine. - Remember that inverted parity bits do not affect the 56-bit real key. So, 0x_0000_0000_0000_0000_u4, 0x_0101_0101_0101_0101_u64, 0x_0000_0000_0000_0001_u64, 0x_0000_0000_0000_0100_u64, 0x_0100_0010_0000_0001_u64, etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
This method sets the key to be the given argument key.
§Example 1 for normal case
use cryptocol::symmetric::DES;
let mut des = DES::new_with_key_u64(0xEFCDAB9078563412);
let plaintext = 0x1234567890ABCDEF_u64;
let ciphertext = des.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
let cipher_cipher_text = des.encrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
assert_ne!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
37fn des_quick_start_instantiation_with_key()
38{
39 println!("des_quick_start_instantiation_with_key()");
40 use cryptocol::symmetric::DES;
41
42 let key = 0x_1234567890ABCDEF_u64;
43 let mut _a_des = DES::new_with_key_u64(key);
44
45 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
46 let mut _a_des = DES::new_with_key(key);
47 println!("-------------------------------");
48}
49
50fn des_quick_start_instantiation_without_key()
51{
52 println!("des_quick_start_instantiation_without_key()");
53 use cryptocol::symmetric::DES;
54
55 let mut a_des = DES::new();
56 let key = 0x_1234567890ABCDEF_u64;
57 a_des.set_key_u64(key);
58
59 let mut a_des = DES::new();
60 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
61 a_des.set_key(key);
62 println!("-------------------------------");
63}
64
65fn des_quick_start_encryption_decryption_16_rounds()
66{
67 println!("des_quick_start_encryption_decryption_16_rounds()");
68 use std::io::Write;
69 use std::fmt::Write as _;
70 use cryptocol::symmetric::{ CBC_PKCS7, DES };
71
72 let mut a_des = DES::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
73 let message = "In the beginning God created the heavens and the earth.";
74 println!("M =\t{}", message);
75 let iv = 0x_FEDCBA0987654321_u64;
76 println!("IV =\t{}", iv);
77 let mut cipher = Vec::<u8>::new();
78 a_des.encrypt_str_into_vec(iv, message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "4B B5 ED DC A0 58 7E 6D 6C 3B A2 00 38 C3 D4 29 42 B1 CF 0D E9 FA EA 11 11 6B C8 30 73 39 DD B7 3F 96 9B A3 76 05 34 7E 64 2F D4 CC B2 68 33 64 C5 9E EF 01 A9 4A FD 5B ");
87
88 let mut recovered = String::new();
89 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
90 println!("B (16 rounds) =\t{}", recovered);
91 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
92 assert_eq!(recovered, message);
93 println!("-------------------------------");
94}
95
96fn des_quick_start_encryption_decryption_256_rounds()
97{
98 println!("des_quick_start_encryption_decryption_256_rounds()");
99 use std::io::Write;
100 use std::fmt::Write as _;
101 use cryptocol::symmetric::{ CBC_PKCS7, DES_Expanded };
102
103 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
104 let message = "In the beginning God created the heavens and the earth.";
105 println!("M =\t{}", message);
106 let iv = 0x_FEDCBA0987654321_u64;
107 println!("IV =\t{}", iv);
108 let mut cipher = Vec::<u8>::new();
109 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
110 print!("C =\t");
111 for c in cipher.clone()
112 { print!("{:02X} ", c); }
113 println!();
114 let mut txt = String::new();
115 for c in cipher.clone()
116 { write!(txt, "{:02X} ", c); }
117 assert_eq!(txt, "0B EA 6B BC 68 F9 B0 3E 7D AF DE 71 9C 08 AA 16 42 40 1C C8 DC 40 51 C6 8D D4 E7 D2 0B A4 F2 09 02 02 C2 6E 99 BC 9E 2A F4 11 7E 48 A7 ED 76 70 C6 9D C6 BD A6 9B 58 8B ");
118
119 let mut recovered = String::new();
120 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
121 println!("B =\t{}", recovered);
122 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
123 assert_eq!(recovered, message);
124 println!("-------------------------------");
125}
126
127fn des_basic_operation_main()
128{
129 des_new();
130 des_new_with_key();
131 des_new_with_key_u64();
132 des_encryptor_with_key();
133 des_encryptor_with_key_u64();
134 des_decryptor_with_key();
135 des_decryptor_with_key_u64();
136 des_get_key();
137 des_get_key_u64();
138 des_set_key();
139 des_set_key_u64();
140 des_turn_inverse();
141 des_turn_encryptor();
142 des_turn_decryptor();
143}
144
145fn des_new()
146{
147 println!("des_new()");
148 use cryptocol::symmetric::DES;
149
150 let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
151 let plaintext = 0x1234567890ABCDEF_u64;
152 let ciphertext = des.encrypt_u64(plaintext);
153
154 println!("Plaintext:\t\t{:#018X}", plaintext);
155 println!("Ciphertext:\t\t{:#018X}", ciphertext);
156 assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
157
158 let cipher_cipher_text = des.encrypt_u64(ciphertext);
159 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
160 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
161 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
162
163 #[cfg(test)]
164 des_compile_fail_new();
165 println!("-------------------------------");
166}
167
168#[test]
169fn des_compile_fail_new()
170{
171 use cryptocol::symmetric::DES;
172 let des = DES::new();
173 // It cannot be compiled!
174 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
175}
176
177fn des_new_with_key()
178{
179 println!("des_new_with_key()");
180 use cryptocol::symmetric::DES;
181
182 // Normal case
183 let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
184 let plaintext = 0x1234567890ABCDEF_u64;
185 let ciphertext = des.encrypt_u64(plaintext);
186
187 println!("Plaintext:\t\t{:#018X}", plaintext);
188 println!("Ciphertext:\t\t{:#018X}", ciphertext);
189 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
190
191 let cipher_cipher_text = des.encrypt_u64(ciphertext);
192 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
193 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
194 assert_ne!(cipher_cipher_text, plaintext);
195 println!();
196
197 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
198 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
199 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
200 let mut des1 = DES::new_with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
201 let mut des2 = DES::new_with_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
202
203 let plaintext = 0x1234567890ABCDEF_u64;
204 let ciphertext1 = des1.encrypt_u64(plaintext);
205 let ciphertext2 = des2.encrypt_u64(plaintext);
206
207 println!("Plaintext:\t\t{:#018X}", plaintext);
208 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
209 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
210 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
211 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
212 assert_eq!(ciphertext1, ciphertext2);
213
214 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
215 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
216 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
217 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
218 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
219 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
220 assert_eq!(cipher_cipher_text1, plaintext);
221 assert_eq!(cipher_cipher_text2, plaintext);
222 println!();
223 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
224 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
225
226
227 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
228 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
229 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
230 let mut des1 = DES::new_with_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
231 let mut des2 = DES::new_with_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
232 let plaintext = 0x1234567890ABCDEF_u64;
233 let ciphertext1 = des1.encrypt_u64(plaintext);
234 let ciphertext2 = des2.encrypt_u64(plaintext);
235
236 println!("Plaintext:\t\t{:#018X}", plaintext);
237 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
238 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
239 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
240 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
241 assert_eq!(ciphertext1, ciphertext2);
242
243 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
244 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
245 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
246 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
247 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
248 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
249 assert_eq!(cipher_cipher_text1, plaintext);
250 assert_eq!(cipher_cipher_text2, plaintext);
251 println!();
252 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
253 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
254
255 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
256 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1] is the same key as the key
257 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
258 let mut des1 = DES::new_with_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
259 let mut des2 = DES::new_with_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
260 let plaintext = 0x1234567890ABCDEF_u64;
261 let ciphertext1 = des1.encrypt_u64(plaintext);
262 let ciphertext2 = des2.encrypt_u64(plaintext);
263
264 println!("Plaintext:\t\t{:#018X}", plaintext);
265 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
266 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
267 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
268 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
269 assert_eq!(ciphertext1, ciphertext2);
270
271 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
272 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
273 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
274 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
275 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
276 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
277 assert_eq!(cipher_cipher_text1, plaintext);
278 assert_eq!(cipher_cipher_text2, plaintext);
279 println!();
280 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
281 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
282
283 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
284 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
285 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
286 let mut des1 = DES::new_with_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
287 let mut des2 = DES::new_with_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
288 let plaintext = 0x1234567890ABCDEF_u64;
289 let ciphertext1 = des1.encrypt_u64(plaintext);
290 let ciphertext2 = des2.encrypt_u64(plaintext);
291
292 println!("Plaintext:\t\t{:#018X}", plaintext);
293 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
294 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
295 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
296 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
297 assert_eq!(ciphertext1, ciphertext2);
298
299 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
300 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
301 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
302 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
303 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
304 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
305 assert_eq!(cipher_cipher_text1, plaintext);
306 assert_eq!(cipher_cipher_text2, plaintext);
307 println!();
308 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
309 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
310
311 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
312 let mut des1 = DES::new_with_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
313 let mut des2 = DES::new_with_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
314
315 let plaintext = 0x1234567890ABCDEF_u64;
316 let ciphertext = des1.encrypt_u64(plaintext);
317 println!("Plaintext:\t\t{:#018X}", plaintext);
318 println!("Ciphertext:\t\t{:#018X}", ciphertext);
319 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
320
321 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
322 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
323 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
324 assert_eq!(cipher_cipher_text, plaintext);
325
326 let ciphertext = des2.encrypt_u64(plaintext);
327 println!("Plaintext:\t\t{:#018X}", plaintext);
328 println!("Ciphertext:\t\t{:#018X}", ciphertext);
329 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
330
331 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
332 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
333 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
334 assert_eq!(cipher_cipher_text, plaintext);
335 println!();
336 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
337
338 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
339 let mut des1 = DES::new_with_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
340 let mut des2 = DES::new_with_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
341
342 let plaintext = 0x1234567890ABCDEF_u64;
343 let ciphertext = des1.encrypt_u64(plaintext);
344 println!("Plaintext:\t\t{:#018X}", plaintext);
345 println!("Ciphertext:\t\t{:#018X}", ciphertext);
346 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
347
348 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
349 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
350 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
351 assert_eq!(cipher_cipher_text, plaintext);
352
353 let ciphertext = des2.encrypt_u64(plaintext);
354 println!("Plaintext:\t\t{:#018X}", plaintext);
355 println!("Ciphertext:\t\t{:#018X}", ciphertext);
356 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
357
358 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
359 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
360 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
361 assert_eq!(cipher_cipher_text, plaintext);
362 println!();
363 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
364
365 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
366 let mut des1 = DES::new_with_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
367 let mut des2 = DES::new_with_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
368
369 let plaintext = 0x1234567890ABCDEF_u64;
370 let ciphertext = des1.encrypt_u64(plaintext);
371 println!("Plaintext:\t\t{:#018X}", plaintext);
372 println!("Ciphertext:\t\t{:#018X}", ciphertext);
373 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
374
375 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
376 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
377 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
378 assert_eq!(cipher_cipher_text, plaintext);
379
380 let ciphertext = des2.encrypt_u64(plaintext);
381 println!("Plaintext:\t\t{:#018X}", plaintext);
382 println!("Ciphertext:\t\t{:#018X}", ciphertext);
383 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
384
385 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
386 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
387 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
388 assert_eq!(cipher_cipher_text, plaintext);
389 println!();
390 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
391
392 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
393 let mut des1 = DES::new_with_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
394 let mut des2 = DES::new_with_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
395
396 let plaintext = 0x1234567890ABCDEF_u64;
397 let ciphertext = des1.encrypt_u64(plaintext);
398 println!("Plaintext:\t\t{:#018X}", plaintext);
399 println!("Ciphertext:\t\t{:#018X}", ciphertext);
400 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
401
402 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
403 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
404 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
405 assert_eq!(cipher_cipher_text, plaintext);
406
407 let ciphertext = des2.encrypt_u64(plaintext);
408 println!("Plaintext:\t\t{:#018X}", plaintext);
409 println!("Ciphertext:\t\t{:#018X}", ciphertext);
410 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
411
412 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
413 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
414 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
415 assert_eq!(cipher_cipher_text, plaintext);
416 println!();
417 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
418
419 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
420 let mut des1 = DES::new_with_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
421 let mut des2 = DES::new_with_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
422
423 let plaintext = 0x1234567890ABCDEF_u64;
424 let ciphertext = des1.encrypt_u64(plaintext);
425 println!("Plaintext:\t\t{:#018X}", plaintext);
426 println!("Ciphertext:\t\t{:#018X}", ciphertext);
427 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
428
429 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
430 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
431 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
432 assert_eq!(cipher_cipher_text, plaintext);
433
434 let ciphertext = des2.encrypt_u64(plaintext);
435 println!("Plaintext:\t\t{:#018X}", plaintext);
436 println!("Ciphertext:\t\t{:#018X}", ciphertext);
437 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
438
439 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
440 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
441 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
442 assert_eq!(cipher_cipher_text, plaintext);
443 println!();
444 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
445
446 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
447 let mut des1 = DES::new_with_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
448 let mut des2 = DES::new_with_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
449
450 let plaintext = 0x1234567890ABCDEF_u64;
451 let ciphertext = des1.encrypt_u64(plaintext);
452 println!("Plaintext:\t\t{:#018X}", plaintext);
453 println!("Ciphertext:\t\t{:#018X}", ciphertext);
454 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
455
456 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
457 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
458 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
459 assert_eq!(cipher_cipher_text, plaintext);
460
461 let ciphertext = des2.encrypt_u64(plaintext);
462 println!("Plaintext:\t\t{:#018X}", plaintext);
463 println!("Ciphertext:\t\t{:#018X}", ciphertext);
464 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
465
466 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
467 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
468 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
469 assert_eq!(cipher_cipher_text, plaintext);
470 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
471
472 #[cfg(test)]
473 des_compile_fail_new_with_key();
474 println!("-------------------------------");
475}
476
477#[test]
478fn des_compile_fail_new_with_key()
479{
480 use cryptocol::symmetric::DES;
481 let des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
482 // It cannot be compiled!
483 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
484}
485
486fn des_new_with_key_u64()
487{
488 println!("des_new_with_key_u64");
489 use cryptocol::symmetric::DES;
490
491 // Normal case
492 let mut des = DES::new_with_key_u64(0xEFCDAB9078563412);
493 let plaintext = 0x1234567890ABCDEF_u64;
494 let ciphertext = des.encrypt_u64(plaintext);
495
496 println!("Plaintext:\t\t{:#018X}", plaintext);
497 println!("Ciphertext:\t\t{:#018X}", ciphertext);
498 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
499
500 let cipher_cipher_text = des.encrypt_u64(ciphertext);
501 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
502 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
503 assert_ne!(cipher_cipher_text, plaintext);
504 println!();
505
506 // Weak key case 1 for 0x0000000000000000
507 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
508 let mut des1 = DES::new_with_key_u64(0x0000000000000000);
509 let mut des2 = DES::new_with_key_u64(0x0101010101010101);
510
511 let plaintext = 0x1234567890ABCDEF_u64;
512 let ciphertext1 = des1.encrypt_u64(plaintext);
513 let ciphertext2 = des2.encrypt_u64(plaintext);
514
515 println!("Plaintext:\t\t{:#018X}", plaintext);
516 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
517 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
518 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
519 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
520 assert_eq!(ciphertext1, ciphertext2);
521
522 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
523 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
524 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
525 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
526 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
527 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
528 assert_eq!(cipher_cipher_text1, plaintext);
529 assert_eq!(cipher_cipher_text2, plaintext);
530 println!();
531 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
532
533 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
534 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
535 let mut des1 = DES::new_with_key_u64(0xFFFFFFFFFFFFFFFF);
536 let mut des2 = DES::new_with_key_u64(0xFEFEFEFEFEFEFEFE);
537 let plaintext = 0x1234567890ABCDEF_u64;
538 let ciphertext1 = des1.encrypt_u64(plaintext);
539 let ciphertext2 = des2.encrypt_u64(plaintext);
540
541 println!("Plaintext:\t\t{:#018X}", plaintext);
542 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
543 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
544 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
545 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
546 assert_eq!(ciphertext1, ciphertext2);
547
548 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
549 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
550 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
551 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
552 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
553 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
554 assert_eq!(cipher_cipher_text1, plaintext);
555 assert_eq!(cipher_cipher_text2, plaintext);
556 println!();
557 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
558
559 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
560 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
561 let mut des1 = DES::new_with_key_u64(0xF1F1F1F1E0E0E0E0);
562 let mut des2 = DES::new_with_key_u64(0xF0F0F0F0E1E1E1E1);
563 let plaintext = 0x1234567890ABCDEF_u64;
564 let ciphertext1 = des1.encrypt_u64(plaintext);
565 let ciphertext2 = des2.encrypt_u64(plaintext);
566
567 println!("Plaintext:\t\t{:#018X}", plaintext);
568 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
569 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
570 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
571 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
572 assert_eq!(ciphertext1, ciphertext2);
573
574 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
575 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
576 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
577 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
578 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
579 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
580 assert_eq!(cipher_cipher_text1, plaintext);
581 assert_eq!(cipher_cipher_text2, plaintext);
582 println!();
583 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
584
585 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
586 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
587 let mut des1 = DES::new_with_key_u64(0x0E0E0E0E1F1F1F1F);
588 let mut des2 = DES::new_with_key_u64(0x0F0F0F0F1E1E1E1E);
589 let plaintext = 0x1234567890ABCDEF_u64;
590 let ciphertext1 = des1.encrypt_u64(plaintext);
591 let ciphertext2 = des2.encrypt_u64(plaintext);
592
593 println!("Plaintext:\t\t{:#018X}", plaintext);
594 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
595 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
596 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
597 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
598 assert_eq!(ciphertext1, ciphertext2);
599
600 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
601 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
602 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
603 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
604 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
605 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
606 assert_eq!(cipher_cipher_text1, plaintext);
607 assert_eq!(cipher_cipher_text2, plaintext);
608 println!();
609 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
610
611 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
612 let mut des1 = DES::new_with_key_u64(0x0E010E011F011F01);
613 let mut des2 = DES::new_with_key_u64(0x010E010E011F011F);
614
615 let plaintext = 0x1234567890ABCDEF_u64;
616 let ciphertext = des1.encrypt_u64(plaintext);
617 println!("Plaintext:\t\t{:#018X}", plaintext);
618 println!("Ciphertext:\t\t{:#018X}", ciphertext);
619 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
620
621 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
622 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
623 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
624 assert_eq!(cipher_cipher_text, plaintext);
625
626 let ciphertext = des2.encrypt_u64(plaintext);
627 println!("Plaintext:\t\t{:#018X}", plaintext);
628 println!("Ciphertext:\t\t{:#018X}", ciphertext);
629 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
630
631 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
632 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
633 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
634 assert_eq!(cipher_cipher_text, plaintext);
635 println!();
636 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
637
638 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
639 let mut des1 = DES::new_with_key_u64(0xF101F101E001E001);
640 let mut des2 = DES::new_with_key_u64(0x01F101F101E001E0);
641
642 let plaintext = 0x1234567890ABCDEF_u64;
643 let ciphertext = des1.encrypt_u64(plaintext);
644 println!("Plaintext:\t\t{:#018X}", plaintext);
645 println!("Ciphertext:\t\t{:#018X}", ciphertext);
646 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
647
648 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
649 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
650 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
651 assert_eq!(cipher_cipher_text, plaintext);
652
653 let ciphertext = des2.encrypt_u64(plaintext);
654 println!("Plaintext:\t\t{:#018X}", plaintext);
655 println!("Ciphertext:\t\t{:#018X}", ciphertext);
656 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
657
658 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
659 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
660 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
661 assert_eq!(cipher_cipher_text, plaintext);
662 println!();
663 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
664
665 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
666 let mut des1 = DES::new_with_key_u64(0xFE01FE01FE01FE01);
667 let mut des2 = DES::new_with_key_u64(0x01FE01FE01FE01FE);
668
669 let plaintext = 0x1234567890ABCDEF_u64;
670 let ciphertext = des1.encrypt_u64(plaintext);
671 println!("Plaintext:\t\t{:#018X}", plaintext);
672 println!("Ciphertext:\t\t{:#018X}", ciphertext);
673 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
674
675 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
676 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
677 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
678 assert_eq!(cipher_cipher_text, plaintext);
679
680 let ciphertext = des2.encrypt_u64(plaintext);
681 println!("Plaintext:\t\t{:#018X}", plaintext);
682 println!("Ciphertext:\t\t{:#018X}", ciphertext);
683 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
684
685 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
686 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
687 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
688 assert_eq!(cipher_cipher_text, plaintext);
689 println!();
690 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
691
692 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
693 let mut des1 = DES::new_with_key_u64(0xF10EF10EE01FE01F);
694 let mut des2 = DES::new_with_key_u64(0x0EF10EF11FE01FE0);
695
696 let plaintext = 0x1234567890ABCDEF_u64;
697 let ciphertext = des1.encrypt_u64(plaintext);
698 println!("Plaintext:\t\t{:#018X}", plaintext);
699 println!("Ciphertext:\t\t{:#018X}", ciphertext);
700 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
701
702 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
703 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
704 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
705 assert_eq!(cipher_cipher_text, plaintext);
706
707 let ciphertext = des2.encrypt_u64(plaintext);
708 println!("Plaintext:\t\t{:#018X}", plaintext);
709 println!("Ciphertext:\t\t{:#018X}", ciphertext);
710 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
711
712 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
713 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
714 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
715 assert_eq!(cipher_cipher_text, plaintext);
716 println!();
717 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
718
719 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
720 let mut des1 = DES::new_with_key_u64(0xFE0EFE0EFE1FFE1F);
721 let mut des2 = DES::new_with_key_u64(0x0EFE0EFE1FFE1FFE);
722
723 let plaintext = 0x1234567890ABCDEF_u64;
724 let ciphertext = des1.encrypt_u64(plaintext);
725 println!("Plaintext:\t\t{:#018X}", plaintext);
726 println!("Ciphertext:\t\t{:#018X}", ciphertext);
727 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
728
729 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
730 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
731 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
732 assert_eq!(cipher_cipher_text, plaintext);
733
734 let ciphertext = des2.encrypt_u64(plaintext);
735 println!("Plaintext:\t\t{:#018X}", plaintext);
736 println!("Ciphertext:\t\t{:#018X}", ciphertext);
737 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
738
739 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
740 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
741 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
742 assert_eq!(cipher_cipher_text, plaintext);
743 println!();
744 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
745
746 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
747 let mut des1 = DES::new_with_key_u64(0xFEF1FEF1FEE0FEE0);
748 let mut des2 = DES::new_with_key_u64(0xF1FEF1FEE0FEE0FE);
749
750 let plaintext = 0x1234567890ABCDEF_u64;
751 let ciphertext = des1.encrypt_u64(plaintext);
752 println!("Plaintext:\t\t{:#018X}", plaintext);
753 println!("Ciphertext:\t\t{:#018X}", ciphertext);
754 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
755
756 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
757 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
758 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
759 assert_eq!(cipher_cipher_text, plaintext);
760
761 let ciphertext = des2.encrypt_u64(plaintext);
762 println!("Plaintext:\t\t{:#018X}", plaintext);
763 println!("Ciphertext:\t\t{:#018X}", ciphertext);
764 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
765
766 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
767 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
768 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
769 assert_eq!(cipher_cipher_text, plaintext);
770 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
771 println!("-------------------------------");
772}
773
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}
899
900fn des_decryptor_with_key_u64()
901{
902 println!("des_decryptor_with_key_u64");
903 use cryptocol::symmetric::{ BigCryptor64, DES };
904
905 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
906 [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
907 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
908 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ] );
909 let plaintext = 0x_1234567890ABCDEF_u64;
910 let ciphertext = tdes.encrypt_u64(plaintext);
911
912 println!("Plaintext:\t\t{:#018X}", plaintext);
913 println!("Ciphertext:\t\t{:#018X}", ciphertext);
914 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
915
916 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
917 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
918 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
919 assert_eq!(cipher_cipher_text, plaintext);
920 println!();
921
922
923 // Operators
924 let mut tdes = BigCryptor64::new()
925 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64)
926 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
927 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64);
928 let plaintext = 0x_1234567890ABCDEF_u64;
929 let ciphertext = tdes.encrypt_u64(plaintext);
930
931 println!("Plaintext:\t\t{:#018X}", plaintext);
932 println!("Ciphertext:\t\t{:#018X}", ciphertext);
933 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
934
935 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
936 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
937 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
938 assert_eq!(cipher_cipher_text, plaintext);
939 println!("-------------------------------");
940}
941
942fn des_get_key()
943{
944 println!("des_get_key");
945 use cryptocol::symmetric::DES;
946
947 let mut des = DES::new();
948 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
949 let key = des.get_key();
950 print!("K = ");
951 for k in key
952 { print!("{:#02X} ", k); }
953 assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
954}
955
956fn des_get_key_u64()
957{
958 println!("des_get_key_u64");
959 use cryptocol::symmetric::DES;
960
961 let mut des = DES::new();
962 des.set_key_u64(0xEFCDAB9078563412);
963 let key = des.get_key_u64();
964 println!("Key = {}", key);
965 assert_eq!(key, 0xEFCDAB9078563412_u64);
966}
967
968fn des_set_key()
969{
970 println!("des_set_key");
971 use cryptocol::symmetric::DES;
972
973 // Normal case
974 let mut des = DES::new();
975 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
976 let plaintext = 0x1234567890ABCDEF_u64;
977 let ciphertext = des.encrypt_u64(plaintext);
978
979 println!("Plaintext:\t\t{:#018X}", plaintext);
980 println!("Ciphertext:\t\t{:#018X}", ciphertext);
981 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
982
983 let cipher_cipher_text = des.encrypt_u64(ciphertext);
984 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
985 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
986 assert_ne!(cipher_cipher_text, plaintext);
987 println!();
988
989 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
990 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
991 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
992 let mut des1 = DES::new();
993 let mut des2 = DES::new();
994 des1.set_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
995 des2.set_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
996
997 let plaintext = 0x1234567890ABCDEF_u64;
998 let ciphertext1 = des1.encrypt_u64(plaintext);
999 let ciphertext2 = des2.encrypt_u64(plaintext);
1000
1001 println!("Plaintext:\t\t{:#018X}", plaintext);
1002 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1003 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1004 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1005 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1006 assert_eq!(ciphertext1, ciphertext2);
1007
1008 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1009 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1010 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1011 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1012 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1013 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1014 assert_eq!(cipher_cipher_text1, plaintext);
1015 assert_eq!(cipher_cipher_text2, plaintext);
1016 println!();
1017 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
1018 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
1019
1020
1021 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1022 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
1023 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
1024 let mut des1 = DES::new();
1025 let mut des2 = DES::new();
1026 des1.set_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
1027 des2.set_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
1028 let plaintext = 0x1234567890ABCDEF_u64;
1029 let ciphertext1 = des1.encrypt_u64(plaintext);
1030 let ciphertext2 = des2.encrypt_u64(plaintext);
1031
1032 println!("Plaintext:\t\t{:#018X}", plaintext);
1033 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1034 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1035 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1036 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1037 assert_eq!(ciphertext1, ciphertext2);
1038
1039 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1040 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1041 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1042 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1043 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1044 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1045 assert_eq!(cipher_cipher_text1, plaintext);
1046 assert_eq!(cipher_cipher_text2, plaintext);
1047 println!();
1048 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1049 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
1050
1051 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1052 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0] is the same key as the key
1053 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
1054 let mut des1 = DES::new();
1055 let mut des2 = DES::new();
1056 des1.set_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
1057 des2.set_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
1058 let plaintext = 0x1234567890ABCDEF_u64;
1059 let ciphertext1 = des1.encrypt_u64(plaintext);
1060 let ciphertext2 = des2.encrypt_u64(plaintext);
1061
1062 println!("Plaintext:\t\t{:#018X}", plaintext);
1063 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1064 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1065 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1066 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1067 assert_eq!(ciphertext1, ciphertext2);
1068
1069 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1070 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1071 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1072 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1073 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1074 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1075 assert_eq!(cipher_cipher_text1, plaintext);
1076 assert_eq!(cipher_cipher_text2, plaintext);
1077 println!();
1078 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1079 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
1080
1081 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1082 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
1083 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
1084 let mut des1 = DES::new();
1085 let mut des2 = DES::new();
1086 des1.set_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
1087 des2.set_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
1088 let plaintext = 0x1234567890ABCDEF_u64;
1089 let ciphertext1 = des1.encrypt_u64(plaintext);
1090 let ciphertext2 = des2.encrypt_u64(plaintext);
1091
1092 println!("Plaintext:\t\t{:#018X}", plaintext);
1093 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1094 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1095 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1096 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1097 assert_eq!(ciphertext1, ciphertext2);
1098
1099 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1100 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1101 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1102 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1103 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1104 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1105 assert_eq!(cipher_cipher_text1, plaintext);
1106 assert_eq!(cipher_cipher_text2, plaintext);
1107 println!();
1108 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1109 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
1110
1111 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
1112 let mut des1 = DES::new();
1113 let mut des2 = DES::new();
1114 des1.set_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
1115 des2.set_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
1116
1117 let plaintext = 0x1234567890ABCDEF_u64;
1118 let ciphertext = des1.encrypt_u64(plaintext);
1119 println!("Plaintext:\t\t{:#018X}", plaintext);
1120 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1121 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1122
1123 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1124 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1125 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1126 assert_eq!(cipher_cipher_text, plaintext);
1127
1128 let ciphertext = des2.encrypt_u64(plaintext);
1129 println!("Plaintext:\t\t{:#018X}", plaintext);
1130 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1131 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1132
1133 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1134 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1135 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1136 assert_eq!(cipher_cipher_text, plaintext);
1137 println!();
1138 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]
1139 // and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
1140
1141 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
1142 let mut des1 = DES::new();
1143 let mut des2 = DES::new();
1144 des1.set_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
1145 des2.set_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
1146
1147 let plaintext = 0x1234567890ABCDEF_u64;
1148 let ciphertext = des1.encrypt_u64(plaintext);
1149 println!("Plaintext:\t\t{:#018X}", plaintext);
1150 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1151 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1152
1153 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1154 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1155 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1156 assert_eq!(cipher_cipher_text, plaintext);
1157
1158 let ciphertext = des2.encrypt_u64(plaintext);
1159 println!("Plaintext:\t\t{:#018X}", plaintext);
1160 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1161 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1162
1163 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1164 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1165 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1166 assert_eq!(cipher_cipher_text, plaintext);
1167 println!();
1168 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]
1169 // and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
1170
1171 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
1172 let mut des1 = DES::new();
1173 let mut des2 = DES::new();
1174 des1.set_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
1175 des2.set_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
1176
1177 let plaintext = 0x1234567890ABCDEF_u64;
1178 let ciphertext = des1.encrypt_u64(plaintext);
1179 println!("Plaintext:\t\t{:#018X}", plaintext);
1180 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1181 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1182
1183 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1184 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1185 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1186 assert_eq!(cipher_cipher_text, plaintext);
1187
1188 let ciphertext = des2.encrypt_u64(plaintext);
1189 println!("Plaintext:\t\t{:#018X}", plaintext);
1190 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1191 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1192
1193 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1194 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1195 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1196 assert_eq!(cipher_cipher_text, plaintext);
1197 println!();
1198 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]
1199 // and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
1200
1201 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
1202 let mut des1 = DES::new();
1203 let mut des2 = DES::new();
1204 des1.set_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
1205 des2.set_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
1206
1207 let plaintext = 0x1234567890ABCDEF_u64;
1208 let ciphertext = des1.encrypt_u64(plaintext);
1209 println!("Plaintext:\t\t{:#018X}", plaintext);
1210 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1211 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1212
1213 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1214 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1215 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1216 assert_eq!(cipher_cipher_text, plaintext);
1217
1218 let ciphertext = des2.encrypt_u64(plaintext);
1219 println!("Plaintext:\t\t{:#018X}", plaintext);
1220 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1221 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1222
1223 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1224 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1225 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1226 assert_eq!(cipher_cipher_text, plaintext);
1227 println!();
1228 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]
1229 // and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
1230
1231 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
1232 let mut des1 = DES::new();
1233 let mut des2 = DES::new();
1234 des1.set_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
1235 des2.set_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
1236
1237 let plaintext = 0x1234567890ABCDEF_u64;
1238 let ciphertext = des1.encrypt_u64(plaintext);
1239 println!("Plaintext:\t\t{:#018X}", plaintext);
1240 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1241 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1242
1243 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1244 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1245 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1246 assert_eq!(cipher_cipher_text, plaintext);
1247
1248 let ciphertext = des2.encrypt_u64(plaintext);
1249 println!("Plaintext:\t\t{:#018X}", plaintext);
1250 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1251 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1252
1253 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1254 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1255 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1256 assert_eq!(cipher_cipher_text, plaintext);
1257 println!();
1258 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]
1259 // and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
1260
1261 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
1262 let mut des1 = DES::new();
1263 let mut des2 = DES::new();
1264 des1.set_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
1265 des2.set_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
1266
1267 let plaintext = 0x1234567890ABCDEF_u64;
1268 let ciphertext = des1.encrypt_u64(plaintext);
1269 println!("Plaintext:\t\t{:#018X}", plaintext);
1270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1271 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1272
1273 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1274 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1275 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1276 assert_eq!(cipher_cipher_text, plaintext);
1277
1278 let ciphertext = des2.encrypt_u64(plaintext);
1279 println!("Plaintext:\t\t{:#018X}", plaintext);
1280 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1281 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1282
1283 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1284 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1285 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1286 assert_eq!(cipher_cipher_text, plaintext);
1287 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]
1288 // and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
1289 println!("-------------------------------");
1290}
1291
1292fn des_set_key_u64()
1293{
1294 println!("des_set_key_u64");
1295 use cryptocol::symmetric::DES;
1296
1297 // Normal case
1298 let mut des = DES::new();
1299 des.set_key_u64(0xEFCDAB9078563412);
1300 let plaintext = 0x1234567890ABCDEF_u64;
1301 let ciphertext = des.encrypt_u64(plaintext);
1302
1303 println!("Plaintext:\t\t{:#018X}", plaintext);
1304 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1305 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
1306
1307 let cipher_cipher_text = des.encrypt_u64(ciphertext);
1308 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1309 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
1310 assert_ne!(cipher_cipher_text, plaintext);
1311 println!();
1312
1313 // Weak key case 1 for 0x0000000000000000
1314 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
1315 let mut des1 = DES::new();
1316 let mut des2 = DES::new();
1317 des1.set_key_u64(0x0000000000000000);
1318 des2.set_key_u64(0x0101010101010101);
1319
1320 let plaintext = 0x1234567890ABCDEF_u64;
1321 let ciphertext1 = des1.encrypt_u64(plaintext);
1322 let ciphertext2 = des2.encrypt_u64(plaintext);
1323
1324 println!("Plaintext:\t\t{:#018X}", plaintext);
1325 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1326 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1327 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1328 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1329 assert_eq!(ciphertext1, ciphertext2);
1330
1331 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1332 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1333 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1334 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1335 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1336 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1337 assert_eq!(cipher_cipher_text1, plaintext);
1338 assert_eq!(cipher_cipher_text2, plaintext);
1339 println!();
1340 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
1341
1342 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
1343 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
1344 let mut des1 = DES::new();
1345 let mut des2 = DES::new();
1346 des1.set_key_u64(0xFFFFFFFFFFFFFFFF);
1347 des2.set_key_u64(0xFEFEFEFEFEFEFEFE);
1348 let plaintext = 0x1234567890ABCDEF_u64;
1349 let ciphertext1 = des1.encrypt_u64(plaintext);
1350 let ciphertext2 = des2.encrypt_u64(plaintext);
1351
1352 println!("Plaintext:\t\t{:#018X}", plaintext);
1353 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1354 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1355 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1356 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1357 assert_eq!(ciphertext1, ciphertext2);
1358
1359 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1360 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1361 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1362 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1363 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1364 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1365 assert_eq!(cipher_cipher_text1, plaintext);
1366 assert_eq!(cipher_cipher_text2, plaintext);
1367 println!();
1368 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
1369
1370 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
1371 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
1372 let mut des1 = DES::new();
1373 let mut des2 = DES::new();
1374 des1.set_key_u64(0xF1F1F1F1E0E0E0E0);
1375 des2.set_key_u64(0xF0F0F0F0E1E1E1E1);
1376 let plaintext = 0x1234567890ABCDEF_u64;
1377 let ciphertext1 = des1.encrypt_u64(plaintext);
1378 let ciphertext2 = des2.encrypt_u64(plaintext);
1379
1380 println!("Plaintext:\t\t{:#018X}", plaintext);
1381 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1382 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1383 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1384 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1385 assert_eq!(ciphertext1, ciphertext2);
1386
1387 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1388 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1389 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1390 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1391 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1392 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1393 assert_eq!(cipher_cipher_text1, plaintext);
1394 assert_eq!(cipher_cipher_text2, plaintext);
1395 println!();
1396 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
1397
1398 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
1399 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
1400 let mut des1 = DES::new();
1401 let mut des2 = DES::new();
1402 des1.set_key_u64(0x0E0E0E0E1F1F1F1F);
1403 des2.set_key_u64(0x0F0F0F0F1E1E1E1E);
1404 let plaintext = 0x1234567890ABCDEF_u64;
1405 let ciphertext1 = des1.encrypt_u64(plaintext);
1406 let ciphertext2 = des2.encrypt_u64(plaintext);
1407
1408 println!("Plaintext:\t\t{:#018X}", plaintext);
1409 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1410 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1411 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1412 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1413 assert_eq!(ciphertext1, ciphertext2);
1414
1415 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1416 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1417 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1418 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1419 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1420 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1421 assert_eq!(cipher_cipher_text1, plaintext);
1422 assert_eq!(cipher_cipher_text2, plaintext);
1423 println!();
1424 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
1425
1426 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
1427 let mut des1 = DES::new();
1428 let mut des2 = DES::new();
1429 des1.set_key_u64(0x0E010E011F011F01);
1430 des2.set_key_u64(0x010E010E011F011F);
1431
1432 let plaintext = 0x1234567890ABCDEF_u64;
1433 let ciphertext = des1.encrypt_u64(plaintext);
1434 println!("Plaintext:\t\t{:#018X}", plaintext);
1435 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1436 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1437
1438 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1439 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1440 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1441 assert_eq!(cipher_cipher_text, plaintext);
1442
1443 let ciphertext = des2.encrypt_u64(plaintext);
1444 println!("Plaintext:\t\t{:#018X}", plaintext);
1445 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1446 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1447
1448 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1449 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1450 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1451 assert_eq!(cipher_cipher_text, plaintext);
1452 println!();
1453 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
1454
1455 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
1456 let mut des1 = DES::new();
1457 let mut des2 = DES::new();
1458 des1.set_key_u64(0xF101F101E001E001);
1459 des2.set_key_u64(0x01F101F101E001E0);
1460
1461 let plaintext = 0x1234567890ABCDEF_u64;
1462 let ciphertext = des1.encrypt_u64(plaintext);
1463 println!("Plaintext:\t\t{:#018X}", plaintext);
1464 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1465 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1466
1467 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1468 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1469 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1470 assert_eq!(cipher_cipher_text, plaintext);
1471
1472 let ciphertext = des2.encrypt_u64(plaintext);
1473 println!("Plaintext:\t\t{:#018X}", plaintext);
1474 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1475 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1476
1477 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1478 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1479 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1480 assert_eq!(cipher_cipher_text, plaintext);
1481 println!();
1482 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
1483
1484 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
1485 let mut des1 = DES::new();
1486 let mut des2 = DES::new();
1487 des1.set_key_u64(0xFE01FE01FE01FE01);
1488 des2.set_key_u64(0x01FE01FE01FE01FE);
1489
1490 let plaintext = 0x1234567890ABCDEF_u64;
1491 let ciphertext = des1.encrypt_u64(plaintext);
1492 println!("Plaintext:\t\t{:#018X}", plaintext);
1493 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1494 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1495
1496 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1497 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1498 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1499 assert_eq!(cipher_cipher_text, plaintext);
1500
1501 let ciphertext = des2.encrypt_u64(plaintext);
1502 println!("Plaintext:\t\t{:#018X}", plaintext);
1503 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1504 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1505
1506 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1507 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1508 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1509 assert_eq!(cipher_cipher_text, plaintext);
1510 println!();
1511 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
1512
1513 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
1514 let mut des1 = DES::new();
1515 let mut des2 = DES::new();
1516 des1.set_key_u64(0xF10EF10EE01FE01F);
1517 des2.set_key_u64(0x0EF10EF11FE01FE0);
1518
1519 let plaintext = 0x1234567890ABCDEF_u64;
1520 let ciphertext = des1.encrypt_u64(plaintext);
1521 println!("Plaintext:\t\t{:#018X}", plaintext);
1522 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1523 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1524
1525 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1526 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1527 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1528 assert_eq!(cipher_cipher_text, plaintext);
1529
1530 let ciphertext = des2.encrypt_u64(plaintext);
1531 println!("Plaintext:\t\t{:#018X}", plaintext);
1532 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1533 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1534
1535 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1536 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1537 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1538 assert_eq!(cipher_cipher_text, plaintext);
1539 println!();
1540 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
1541
1542 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
1543 let mut des1 = DES::new();
1544 let mut des2 = DES::new();
1545 des1.set_key_u64(0xFE0EFE0EFE1FFE1F);
1546 des2.set_key_u64(0x0EFE0EFE1FFE1FFE);
1547
1548 let plaintext = 0x1234567890ABCDEF_u64;
1549 let ciphertext = des1.encrypt_u64(plaintext);
1550 println!("Plaintext:\t\t{:#018X}", plaintext);
1551 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1552 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1553
1554 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1555 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1556 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1557 assert_eq!(cipher_cipher_text, plaintext);
1558
1559 let ciphertext = des2.encrypt_u64(plaintext);
1560 println!("Plaintext:\t\t{:#018X}", plaintext);
1561 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1562 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1563
1564 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1565 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1566 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1567 assert_eq!(cipher_cipher_text, plaintext);
1568 println!();
1569 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
1570
1571 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
1572 let mut des1 = DES::new();
1573 let mut des2 = DES::new();
1574 des1.set_key_u64(0xFEF1FEF1FEE0FEE0);
1575 des2.set_key_u64(0xF1FEF1FEE0FEE0FE);
1576
1577 let plaintext = 0x1234567890ABCDEF_u64;
1578 let ciphertext = des1.encrypt_u64(plaintext);
1579 println!("Plaintext:\t\t{:#018X}", plaintext);
1580 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1581 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1582
1583 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1584 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1585 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1586 assert_eq!(cipher_cipher_text, plaintext);
1587
1588 let ciphertext = des2.encrypt_u64(plaintext);
1589 println!("Plaintext:\t\t{:#018X}", plaintext);
1590 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1591 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1592
1593 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1594 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1595 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1596 assert_eq!(cipher_cipher_text, plaintext);
1597 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
1598 println!("-------------------------------");
1599}
1600
1601fn des_turn_inverse()
1602{
1603 println!("des_turn_inverse");
1604 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1605
1606 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1607 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1608 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1609 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1610 keys[1].turn_inverse();
1611
1612 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1613 let plaintext = 0x_1234567890ABCDEF_u64;
1614 let ciphertext = tdes.encrypt_u64(plaintext);
1615
1616 println!("Plaintext:\t\t{:#018X}", plaintext);
1617 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1618 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1619
1620 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1621 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1622 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1623 assert_eq!(cipher_cipher_text, plaintext);
1624 println!();
1625
1626
1627 // Operators
1628 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1629 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1630 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1631 des2.turn_inverse();
1632
1633 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1634 let plaintext = 0x_1234567890ABCDEF_u64;
1635 let ciphertext = tdes.encrypt_u64(plaintext);
1636
1637 println!("Plaintext:\t\t{:#018X}", plaintext);
1638 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1639 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1640
1641 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1642 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1643 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1644 assert_eq!(cipher_cipher_text, plaintext);
1645 println!("-------------------------------");
1646}
1647
1648fn des_turn_encryptor()
1649{
1650 println!("des_turn_encryptor");
1651 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1652
1653 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1654 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1655 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1656 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1657 keys[0].turn_encryptor();
1658
1659 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1660 let plaintext = 0x_1234567890ABCDEF_u64;
1661 let ciphertext = tdes.encrypt_u64(plaintext);
1662
1663 println!("Plaintext:\t\t{:#018X}", plaintext);
1664 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1665 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1666
1667 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1668 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1669 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1670 assert_eq!(cipher_cipher_text, plaintext);
1671 println!();
1672
1673
1674 // Operators
1675 let mut des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1676 let des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1677 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1678 des1.turn_encryptor();
1679
1680 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1681 let plaintext = 0x_1234567890ABCDEF_u64;
1682 let ciphertext = tdes.encrypt_u64(plaintext);
1683
1684 println!("Plaintext:\t\t{:#018X}", plaintext);
1685 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1686 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1687
1688 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1689 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1690 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1691 assert_eq!(cipher_cipher_text, plaintext);
1692 println!("-------------------------------");
1693}
1694
1695fn des_turn_decryptor()
1696{
1697 println!("des_turn_decryptor");
1698 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1699
1700 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1701 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1702 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1703 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1704 keys[1].turn_decryptor();
1705
1706 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1707 let plaintext = 0x_1234567890ABCDEF_u64;
1708 let ciphertext = tdes.encrypt_u64(plaintext);
1709
1710 println!("Plaintext:\t\t{:#018X}", plaintext);
1711 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1712 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1713
1714 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1715 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1716 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1717 assert_eq!(cipher_cipher_text, plaintext);
1718 println!();
1719
1720
1721 // Operators
1722 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1723 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1724 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1725 des2.turn_decryptor();
1726
1727 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1728 let plaintext = 0x_1234567890ABCDEF_u64;
1729 let ciphertext = tdes.encrypt_u64(plaintext);
1730
1731 println!("Plaintext:\t\t{:#018X}", plaintext);
1732 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1733 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1734
1735 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1736 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1737 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1738 assert_eq!(cipher_cipher_text, plaintext);
1739 println!("-------------------------------");
1740}
1741
1742fn des_encrypt_decrypt_u64_array_u64_main()
1743{
1744 des_encrypt_u64();
1745 des_decrypt_u64();
1746 // des__encrypt();
1747 // des__decrypt();
1748 des_encrypt_array_u64();
1749 des_decrypt_array_u64();
1750 des_is_successful();
1751 des_is_failed();
1752 // des_set_successful();
1753 // des_set_failed();
1754 des_has_weak_key();
1755}
1756
1757fn des_encrypt_u64()
1758{
1759 println!("des_encrypt_u64");
1760 use cryptocol::symmetric::{ DES, DES_Expanded };
1761
1762 // Normal case
1763 let key = 0x_1234567890ABCDEF_u64;
1764 println!("K =\t{:#018X}", key);
1765
1766 let message = 0x_1234567890ABCDEF_u64;
1767 println!("M_u64 =\t{:#018X}", message);
1768
1769 let mut a_des = DES::new_with_key_u64(key);
1770 let cipher = a_des.encrypt_u64(message);
1771 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1772 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1773 println!();
1774
1775 // Expanded case for 128 rounds
1776 let key = 0x_1234567890ABCDEF_u64;
1777 println!("K =\t{:#018X}", key);
1778
1779 let message = 0x_1234567890ABCDEF_u64;
1780 println!("M_u64 =\t{:#018X}", message);
1781
1782 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1783 let cipher = b_des.encrypt_u64(message);
1784 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1785 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1786 println!();
1787
1788 // Expanded case for 0 rounds which means that key is meaningless
1789 let key1 = 0x_1234567890ABCDEF_u64;
1790 let key2 = 0_u64;
1791 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1792 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1793 println!("K1 =\t{:#016x}", key1);
1794
1795 let message = 0x_1234567890ABCDEF_u64;
1796 println!("M_u64 =\t{:#018X}", message);
1797
1798 let cipher1 = c_des.encrypt_u64(message);
1799 let cipher2 = d_des.encrypt_u64(message);
1800 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1801 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1802
1803 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1804 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1805 assert_eq!(cipher1, cipher2);
1806 println!("-------------------------------");
1807}
1808
1809fn des_decrypt_u64()
1810{
1811 println!("des_decrypt_u64");
1812 use cryptocol::symmetric::{ DES, DES_Expanded };
1813
1814 // Normal case
1815 let key = 0x_1234567890ABCDEF_u64;
1816 println!("K =\t{:#018X}", key);
1817
1818 let message = 0x_1234567890ABCDEF_u64;
1819 println!("M_u64 =\t{:#018X}", message);
1820
1821 let mut a_des = DES::new_with_key_u64(key);
1822 let cipher = a_des.encrypt_u64(message);
1823 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1824 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1825
1826 let recovered = a_des.decrypt_u64(cipher);
1827 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1828 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1829 assert_eq!(recovered, message);
1830 println!();
1831
1832 // Expanded case for 128 rounds
1833 let key = 0x_1234567890ABCDEF_u64;
1834 println!("K =\t{:#018X}", key);
1835
1836 let message = 0x_1234567890ABCDEF_u64;
1837 println!("M_u64 =\t{:#018X}", message);
1838
1839 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1840 let cipher = b_des.encrypt_u64(message);
1841 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1842 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1843
1844 let recovered = b_des.decrypt_u64(cipher);
1845 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1846 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1847 assert_eq!(recovered, message);
1848 println!();
1849
1850 // Expanded case for 0 rounds which means that key is meaningless
1851 let key1 = 0x_1234567890ABCDEF_u64;
1852 let key2 = 0_u64;
1853 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1854 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1855 println!("K =\t{:#018X}", key);
1856
1857 let message = 0x_1234567890ABCDEF_u64;
1858 println!("M_u64 =\t{:#018X}", message);
1859
1860 let cipher1 = c_des.encrypt_u64(message);
1861 let cipher2 = d_des.encrypt_u64(message);
1862 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1863 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1864
1865 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1866 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1867 assert_eq!(cipher1, cipher2);
1868
1869 let recovered1 = c_des.decrypt_u64(cipher1);
1870 let recovered2 = d_des.decrypt_u64(cipher2);
1871 println!("B1_u64 (0 rounds) =\t{:#018X}", recovered1);
1872 println!("B2_u64 (0 rounds) =\t{:#018X}", recovered2);
1873 assert_eq!(recovered1, 0x_1234567890ABCDEF_u64);
1874 assert_eq!(recovered1, message);
1875 assert_eq!(recovered2, 0x_1234567890ABCDEF_u64);
1876 assert_eq!(recovered2, message);
1877 assert_eq!(recovered1, recovered2);
1878 println!("-------------------------------");
1879}
1880
1881/*
1882fn des__encrypt()
1883{
1884 println!("des__encrypt");
1885 use cryptocol::symmetric::{ DES, DES_Expanded };
1886
1887 // Normal case
1888 let key = 0x_1234567890ABCDEF_u64;
1889 println!("K =\t{:#018X}", key);
1890
1891 let message = 0x_1234567890ABCDEF_u64;
1892 println!("M_u64 =\t{:#018X}", message);
1893
1894 let mut a_des = DES::new_with_key_u64(key);
1895 let cipher = a_des._encrypt(message);
1896 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1897 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1898 println!();
1899
1900 // Expanded case for 128 rounds
1901 let key = 0x_1234567890ABCDEF_u64;
1902 println!("K =\t{:#018X}", key);
1903
1904 let message = 0x_1234567890ABCDEF_u64;
1905 println!("M_u64 =\t{:#018X}", message);
1906
1907 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1908 let cipher = b_des._encrypt(message);
1909 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1910 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1911 println!();
1912
1913 // Expanded case for 0 rounds which means that key is meaningless
1914 let key1 = 0x_1234567890ABCDEF_u64;
1915 let key2 = 0_u64;
1916 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1917 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1918 println!("K1 =\t{:#016x}", key1);
1919
1920 let message = 0x_1234567890ABCDEF_u64;
1921 println!("M_u64 =\t{:#018X}", message);
1922
1923 let cipher1 = c_des._encrypt(message);
1924 let cipher2 = d_des._encrypt(message);
1925 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1926 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1927
1928 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1929 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1930 assert_eq!(cipher1, cipher2);
1931 println!("-------------------------------");
1932}
1933
1934fn des__decrypt()
1935{
1936 println!("des__decrypt");
1937 use cryptocol::symmetric::{ DES, DES_Expanded };
1938
1939 // Normal case
1940 let key = 0x_1234567890ABCDEF_u64;
1941 println!("K =\t{:#018X}", key);
1942
1943 let message = 0x_1234567890ABCDEF_u64;
1944 println!("M_u64 =\t{:#018X}", message);
1945
1946 let mut a_des = DES::new_with_key_u64(key);
1947 let cipher = a_des._encrypt(message);
1948 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1949 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1950
1951 let recovered = a_des._decrypt(cipher);
1952 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1953 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1954 assert_eq!(recovered, message);
1955 println!();
1956
1957 // Expanded case for 128 rounds
1958 let key = 0x_1234567890ABCDEF_u64;
1959 println!("K =\t{:#018X}", key);
1960
1961 let message = 0x_1234567890ABCDEF_u64;
1962 println!("M_u64 =\t{:#018X}", message);
1963
1964 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1965 let cipher = b_des._encrypt(message);
1966 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1967 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1968
1969 let recovered = b_des._decrypt(cipher);
1970 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1971 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1972 assert_eq!(recovered, message);
1973 println!();
1974
1975 // Expanded case for 0 rounds which means that key is meaningless
1976 let key1 = 0x_1234567890ABCDEF_u64;
1977 let key2 = 0_u64;
1978 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1979 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1980 println!("K =\t{:#018X}", key);
1981
1982 let message = 0x_1234567890ABCDEF_u64;
1983 println!("M_u64 =\t{:#018X}", message);
1984
1985 let cipher1 = c_des._encrypt(message);
1986 let cipher2 = d_des._encrypt(message);
1987 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1988 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1989
1990 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1991 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1992 assert_eq!(cipher1, cipher2);
1993
1994 let recovered1 = c_des._decrypt(cipher1);
1995 let recovered2 = d_des._decrypt(cipher2);
1996 println!("B1_u64 (0 rounds) =\t{:#018X}", recovered1);
1997 println!("B2_u64 (0 rounds) =\t{:#018X}", recovered2);
1998 assert_eq!(recovered1, 0x_1234567890ABCDEF_u64);
1999 assert_eq!(recovered1, message);
2000 assert_eq!(recovered2, 0x_1234567890ABCDEF_u64);
2001 assert_eq!(recovered2, message);
2002 assert_eq!(recovered1, recovered2);
2003 println!("-------------------------------");
2004}
2005*/
2006fn des_encrypt_array_u64()
2007{
2008 println!("des_encrypt_array_u64");
2009 use cryptocol::symmetric::{ DES, DES_Expanded };
2010
2011 // Normal case
2012 let key = 0x_1234567890ABCDEF_u64;
2013 println!("K =\t{:#018X}", key);
2014
2015 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2016 print!("M =\t");
2017 for m in message
2018 { print!("{:#018X} ", m); }
2019 println!();
2020 let mut a_des = DES::new_with_key_u64(key);
2021
2022 let mut cipher = [0; 3];
2023 a_des.encrypt_array_u64(&message, &mut cipher);
2024 print!("C (16 rounds) =\t");
2025 for c in cipher
2026 { print!("{:#018X} ", c); }
2027 println!();
2028 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2029 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2030 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2031 println!();
2032
2033 // Expanded case for 128 rounds
2034 let key = 0x_1234567890ABCDEF_u64;
2035 println!("K =\t{:#018X}", key);
2036
2037 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2038 print!("M =\t");
2039 for m in message
2040 { print!("{:#018X} ", m); }
2041 println!();
2042 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2043
2044 let mut cipher = [0; 3];
2045 b_des.encrypt_array_u64(&message, &mut cipher);
2046 print!("C (128 rounds) =\t");
2047 for c in cipher
2048 { print!("{:#018X} ", c); }
2049 println!();
2050 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2051 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2052 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2053 println!();
2054
2055
2056 // Expanded case for 0 rounds which means that key is meaningless
2057 let key1 = 0x_1234567890ABCDEF_u64;
2058 let key2 = 0_u64;
2059 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2060 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2061 println!("K =\t{:#018X}", key);
2062
2063 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2064 print!("M =\t");
2065 for m in message
2066 { print!("{:#018X} ", m); }
2067 println!();
2068
2069 let mut cipher1 = [0; 3];
2070 let mut cipher2 = [0; 3];
2071 c_des.encrypt_array_u64(&message, &mut cipher1);
2072 d_des.encrypt_array_u64(&message, &mut cipher2);
2073 print!("C (0 rounds) =\t");
2074 for c in cipher1
2075 { print!("{:#018X} ", c); }
2076 println!();
2077 print!("D (0 rounds) =\t");
2078 for c in cipher2
2079 { print!("{:#018X} ", c); }
2080 println!();
2081 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2082 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2083 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2084 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2085 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2086 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2087 assert_eq!(cipher1[0], cipher2[0]);
2088 assert_eq!(cipher1[1], cipher2[1]);
2089 assert_eq!(cipher1[2], cipher2[2]);
2090 println!("-------------------------------");
2091}
2092
2093fn des_decrypt_array_u64()
2094{
2095 println!("des_decrypt_array_u64");
2096 use cryptocol::symmetric::{ DES, DES_Expanded };
2097
2098 // Normal case
2099 let key = 0x_1234567890ABCDEF_u64;
2100 println!("K =\t{:#018X}", key);
2101
2102 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2103 print!("M =\t");
2104 for m in message
2105 { print!("{:#018X} ", m); }
2106 println!();
2107 let mut a_des = DES::new_with_key_u64(key);
2108
2109 let mut cipher = [0; 3];
2110 a_des.encrypt_array_u64(&message, &mut cipher);
2111 print!("C (16 rounds) =\t");
2112 for c in cipher
2113 { print!("{:#018X} ", c); }
2114 println!();
2115 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2116 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2117 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2118
2119 let mut recovered = [0; 3];
2120 a_des.decrypt_array_u64(&cipher, &mut recovered);
2121 print!("B (16 rounds) =\t");
2122 for r in recovered
2123 { print!("{:#018X} ", r); }
2124 println!();
2125 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2126 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2127 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2128 println!();
2129
2130 // Expanded case for 128 rounds
2131 let key = 0x_1234567890ABCDEF_u64;
2132 println!("K =\t{:#018X}", key);
2133
2134 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2135 print!("M =\t");
2136 for m in message
2137 { print!("{:#018X} ", m); }
2138 println!();
2139 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2140
2141 let mut cipher = [0; 3];
2142 b_des.encrypt_array_u64(&message, &mut cipher);
2143 print!("C (128 rounds) =\t");
2144 for c in cipher
2145 { print!("{:#018X} ", c); }
2146 println!();
2147 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2148 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2149 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2150
2151 let mut recovered = [0; 3];
2152 b_des.decrypt_array_u64(&cipher, &mut recovered);
2153 print!("B (128 rounds) =\t");
2154 for r in recovered
2155 { print!("{:#018X} ", r); }
2156 println!();
2157 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2158 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2159 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2160
2161 // Expanded case for 0 rounds which means that key is meaningless
2162 let key1 = 0x_1234567890ABCDEF_u64;
2163 let key2 = 0_u64;
2164 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2165 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2166 println!("K =\t{:#018X}", key);
2167
2168 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2169 print!("M =\t");
2170 for m in message
2171 { print!("{:#018X} ", m); }
2172 println!();
2173
2174 let mut cipher1 = [0; 3];
2175 let mut cipher2 = [0; 3];
2176 c_des.encrypt_array_u64(&message, &mut cipher1);
2177 d_des.encrypt_array_u64(&message, &mut cipher2);
2178 print!("C (0 rounds) =\t");
2179 for c in cipher1
2180 { print!("{:#018X} ", c); }
2181 println!();
2182 print!("D (0 rounds) =\t");
2183 for c in cipher2
2184 { print!("{:#018X} ", c); }
2185 println!();
2186 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2187 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2188 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2189 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2190 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2191 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2192 assert_eq!(cipher1[0], cipher2[0]);
2193 assert_eq!(cipher1[1], cipher2[1]);
2194 assert_eq!(cipher1[2], cipher2[2]);
2195
2196 let mut recovered1 = [0; 3];
2197 let mut recovered2 = [0; 3];
2198 c_des.decrypt_array_u64(&cipher1, &mut recovered1);
2199 d_des.decrypt_array_u64(&cipher2, &mut recovered2);
2200 print!("B1 (0 rounds) =\t");
2201 for r in recovered1
2202 { print!("{:#018X} ", r); }
2203 println!();
2204 print!("B2 (0 rounds) =\t");
2205 for r in recovered2
2206 { print!("{:#018X} ", r); }
2207 println!();
2208 assert_eq!(recovered1[0], 0x_1234567890ABCDEF_u64);
2209 assert_eq!(recovered1[1], 0x_EFCDAB9078563412_u64);
2210 assert_eq!(recovered1[2], 0x_FEDCBA0987654321_u64);
2211 assert_eq!(recovered2[0], 0x_1234567890ABCDEF_u64);
2212 assert_eq!(recovered2[1], 0x_EFCDAB9078563412_u64);
2213 assert_eq!(recovered2[2], 0x_FEDCBA0987654321_u64);
2214 assert_eq!(recovered1[0], recovered2[0]);
2215 assert_eq!(recovered1[1], recovered2[1]);
2216 assert_eq!(recovered1[2], recovered2[2]);
2217 println!("-------------------------------");
2218}
2219
2220fn des_is_successful()
2221{
2222 println!("des_is_successful");
2223 use std::io::Write;
2224 use std::fmt::Write as _;
2225 use cryptocol::symmetric::DES;
2226
2227 {
2228 use cryptocol::symmetric::ECB_PKCS7;
2229
2230 // Successful case for the message of 0 bytes
2231 let key = 0x_1234567890ABCDEF_u64;
2232 println!("K =\t{:#018X}", key);
2233 let mut a_des = DES::new_with_key_u64(key);
2234 let message = "";
2235 println!("M =\t{}", message);
2236 let mut cipher = [0_u8; 8];
2237 let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
2238 println!("The length of ciphertext = {}", len);
2239 assert_eq!(len, 8);
2240 let success = a_des.is_successful();
2241 assert_eq!(success, true);
2242 print!("C =\t");
2243 for c in cipher.clone()
2244 { print!("{:02X} ", c); }
2245 println!();
2246 let mut txt = String::new();
2247 for c in cipher.clone()
2248 { write!(txt, "{:02X} ", c); }
2249 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2250 println!();
2251
2252 // Successful case for the original message of 0 bytes
2253 let key = 0x_1234567890ABCDEF_u64;
2254 println!("K =\t{:#018X}", key);
2255 let mut a_des = DES::new_with_key_u64(key);
2256
2257 let cipher = [0x41u8, 0x7F, 0x89, 0x79, 0x08, 0xCD, 0xA1, 0x4C];
2258 print!("C =\t");
2259 for c in cipher.clone()
2260 { print!("{:02X} ", c); }
2261 println!();
2262 let mut recovered = [0u8; 8];
2263 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
2264 println!("The length of plaintext = {}", len);
2265 assert_eq!(len, 0);
2266 let success = a_des.is_successful();
2267 assert_eq!(success, true);
2268 print!("Ba =\t");
2269 for b in recovered.clone()
2270 { print!("{:02X} ", b); }
2271 println!();
2272 let mut txt = String::new();
2273 for c in recovered.clone()
2274 { write!(txt, "{:02X} ", c); }
2275 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2276
2277 let mut converted = String::new();
2278 unsafe { converted.as_mut_vec() }.write(&recovered);
2279 unsafe { converted.as_mut_vec() }.truncate(len as usize);
2280 println!("Bb =\t{}", converted);
2281 assert_eq!(converted, "");
2282 assert_eq!(converted, message);
2283 println!();
2284 }
2285
2286 {
2287 use cryptocol::symmetric::CBC_ISO;
2288
2289 // Failure case for the message of 0 bytes
2290 let iv = 0x_FEDCBA0987654321_u64;
2291 println!("IV = {}", iv);
2292 let key = 0x_1234567890ABCDEF_u64;
2293 println!("K =\t{:#018X}", key);
2294 let mut a_des = DES::new_with_key_u64(key);
2295 let message = "";
2296 println!("M =\t{}", message);
2297 let mut cipher = [0_u8; 4];
2298 let len = a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
2299 println!("The length of ciphertext = {}", len);
2300 assert_eq!(len, 0);
2301 let success = a_des.is_successful();
2302 assert_eq!(success, false);
2303 print!("C =\t");
2304 for c in cipher.clone()
2305 { print!("{:02X} ", c); }
2306 println!();
2307 let mut txt = String::new();
2308 for c in cipher.clone()
2309 { write!(txt, "{:02X} ", c); }
2310 assert_eq!(txt, "00 00 00 00 ");
2311 println!();
2312
2313 // Failed case for decryption
2314 let iv = 0x_FEDCBA0987654321_u64;
2315 println!("IV = {}", iv);
2316 let key = 0x_1234567890ABCDEF_u64;
2317 println!("K =\t{:#018X}", key);
2318 let mut a_des = DES::new_with_key_u64(key);
2319
2320 let cipher = [0u8; 4];
2321 print!("C =\t");
2322 for c in cipher.clone()
2323 { print!("{:02X} ", c); }
2324 println!();
2325 let mut recovered = [0u8; 8];
2326 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
2327 println!("The length of plaintext = {}", len);
2328 assert_eq!(len, 0);
2329 let success = a_des.is_successful();
2330 assert_eq!(success, false);
2331 }
2332 println!("-------------------------------");
2333}
2334
2335fn des_is_failed()
2336{
2337 println!("des_is_failed");
2338 use std::io::Write;
2339 use std::fmt::Write as _;
2340 use cryptocol::symmetric::DES;
2341
2342 {
2343 use cryptocol::symmetric::ECB_PKCS7;
2344
2345 // Successful case for the message of 0 bytes
2346 let key = 0x_1234567890ABCDEF_u64;
2347 println!("K =\t{:#018X}", key);
2348 let mut a_des = DES::new_with_key_u64(key);
2349 let message = "";
2350 println!("M =\t{}", message);
2351 let mut cipher = [0_u8; 8];
2352 let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
2353 println!("The length of ciphertext = {}", len);
2354 assert_eq!(len, 8);
2355 let failure = a_des.is_failed();
2356 assert_eq!(failure, false);
2357 print!("C =\t");
2358 for c in cipher.clone()
2359 { print!("{:02X} ", c); }
2360 println!();
2361 let mut txt = String::new();
2362 for c in cipher.clone()
2363 { write!(txt, "{:02X} ", c); }
2364 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2365 println!();
2366
2367 // Successful case for the original message of 0 bytes
2368 let key = 0x_1234567890ABCDEF_u64;
2369 println!("K =\t{:#018X}", key);
2370 let mut a_des = DES::new_with_key_u64(key);
2371
2372 let cipher = [0x41u8, 0x7F, 0x89, 0x79, 0x08, 0xCD, 0xA1, 0x4C];
2373 print!("C =\t");
2374 for c in cipher.clone()
2375 { print!("{:02X} ", c); }
2376 println!();
2377 let mut recovered = [0u8; 8];
2378 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
2379 println!("The length of plaintext = {}", len);
2380 assert_eq!(len, 0);
2381 let failure = a_des.is_failed();
2382 assert_eq!(failure, false);
2383 print!("Ba =\t");
2384 for b in recovered.clone()
2385 { print!("{:02X} ", b); }
2386 println!();
2387 let mut txt = String::new();
2388 for c in recovered.clone()
2389 { write!(txt, "{:02X} ", c); }
2390 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2391
2392 let mut converted = String::new();
2393 unsafe { converted.as_mut_vec() }.write(&recovered);
2394 unsafe { converted.as_mut_vec() }.truncate(len as usize);
2395 println!("Bb =\t{}", converted);
2396 assert_eq!(converted, "");
2397 assert_eq!(converted, message);
2398 println!();
2399 }
2400
2401 {
2402 use cryptocol::symmetric::CBC_ISO;
2403
2404 // Failure case for the message of 0 bytes
2405 let iv = 0x_FEDCBA0987654321_u64;
2406 println!("IV = {}", iv);
2407 let key = 0x_1234567890ABCDEF_u64;
2408 println!("K =\t{:#018X}", key);
2409 let mut a_des = DES::new_with_key_u64(key);
2410 let message = "";
2411 println!("M =\t{}", message);
2412 let mut cipher = [0_u8; 4];
2413 let len = a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
2414 println!("The length of ciphertext = {}", len);
2415 assert_eq!(len, 0);
2416 let failure = a_des.is_failed();
2417 assert_eq!(failure, true);
2418 print!("C =\t");
2419 for c in cipher.clone()
2420 { print!("{:02X} ", c); }
2421 println!();
2422 let mut txt = String::new();
2423 for c in cipher.clone()
2424 { write!(txt, "{:02X} ", c); }
2425 assert_eq!(txt, "00 00 00 00 ");
2426 println!();
2427
2428 // Failed case for decryption
2429 let iv = 0x_FEDCBA0987654321_u64;
2430 println!("IV = {}", iv);
2431 let key = 0x_1234567890ABCDEF_u64;
2432 println!("K =\t{:#018X}", key);
2433 let mut a_des = DES::new_with_key_u64(key);
2434
2435 let cipher = [0u8; 4];
2436 print!("C =\t");
2437 for c in cipher.clone()
2438 { print!("{:02X} ", c); }
2439 println!();
2440 let mut recovered = [0u8; 8];
2441 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
2442 println!("The length of plaintext = {}", len);
2443 assert_eq!(len, 0);
2444 let failure = a_des.is_failed();
2445 assert_eq!(failure, true);
2446 }
2447 println!("-------------------------------");
2448}
2449
2450// fn des_set_successful()
2451// {
2452// println!("des_set_successful");
2453// use cryptocol::symmetric::DES;
2454// let mut a_des = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
2455// assert_eq!(a_des.is_successful(), false);
2456
2457// a_des.set_successful();
2458// assert_eq!(a_des.is_successful(), true);
2459// println!("-------------------------------");
2460// }
2461
2462// fn des_set_failed()
2463// {
2464// println!("des_set_failed");
2465// use cryptocol::symmetric::DES;
2466// let mut a_des = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
2467// a_des.encrypt_u64(0x1234567890ABCDEF_u64);
2468// assert_eq!(a_des.is_failed(), false);
2469
2470// a_des.set_failed();
2471// assert_eq!(a_des.is_failed(), true);
2472// println!("-------------------------------");
2473// }
2474
2475fn des_has_weak_key()
2476{
2477 println!("des_has_weak_key");
2478 use cryptocol::symmetric::DES;
2479
2480 let key = 0x_1234567890ABCDEF_u64;
2481 let mut a_des = DES::new_with_key_u64(key);
2482 let weak_key = a_des.has_weak_key();
2483 println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
2484 assert_eq!(weak_key, false);
2485
2486 let key = 0x_0000000000000000_u64;
2487 a_des.set_key_u64(key);
2488 let weak_key = a_des.has_weak_key();
2489 println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
2490 assert_eq!(weak_key, true);
2491 println!("-------------------------------");
2492}More examples
54fn des_encrypt_with_padding_iso_ecb()
55{
56 println!("des_encrypt_with_padding_iso_ecb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
60
61 // Normal case
62 let key = 0x_1234567890ABCDEF_u64;
63 println!("K =\t{:#016X}", key);
64 let mut a_des = DES::new_with_key_u64(key);
65
66 let message = "In the beginning God created the heavens and the earth.";
67 println!("M =\t{}", message);
68 let mut cipher = [0_u8; 56];
69 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
70 print!("C (16 rounds) =\t");
71 for c in cipher.clone()
72 { print!("{:02X} ", c); }
73 println!();
74 let mut txt = String::new();
75 for c in cipher.clone()
76 { write!(txt, "{:02X} ", c); }
77 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
78 println!();
79
80 // Expanded case for 128 rounds
81 let key = 0x_1234567890ABCDEF_u64;
82 println!("K =\t{:#016X}", key);
83 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
84
85 let message = "In the beginning God created the heavens and the earth.";
86 println!("M =\t{}", message);
87 let mut cipher = [0_u8; 56];
88 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
89 print!("C (128 rounds) =\t");
90 for c in cipher.clone()
91 { print!("{:02X} ", c); }
92 println!();
93 let mut txt = String::new();
94 for c in cipher.clone()
95 { write!(txt, "{:02X} ", c); }
96 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
97 println!();
98
99 // Expanded case for 0 rounds which means that key is meaningless
100 let key1 = 0x_1234567890ABCDEF_u64;
101 let key2 = 0_u64;
102 println!("K =\t{:#016X}", key);
103 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
104 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
105
106 let message = "In the beginning God created the heavens and the earth.";
107 println!("M =\t{}", message);
108 let mut cipher1 = [0_u8; 56];
109 let mut cipher2 = [0_u8; 56];
110 c_des.encrypt(message.as_ptr(), message.len() as u64, cipher1.as_mut_ptr());
111 d_des.encrypt(message.as_ptr(), message.len() as u64, cipher2.as_mut_ptr());
112 print!("C (0 rounds) =\t");
113 for c in cipher1.clone()
114 { print!("{:02X} ", c); }
115 println!();
116 let mut txt = String::new();
117 for c in cipher1.clone()
118 { write!(txt, "{:02X} ", c); }
119 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
120 print!("D (0 rounds) =\t");
121 for c in cipher2.clone()
122 { print!("{:02X} ", c); }
123 println!();
124 let mut txt = String::new();
125 for c in cipher2.clone()
126 { write!(txt, "{:02X} ", c); }
127 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
128 println!();
129
130 // Normal case for the message of 0 bytes
131 let key = 0x_1234567890ABCDEF_u64;
132 println!("K =\t{:#016X}", key);
133 let mut a_des = DES::new_with_key_u64(key);
134
135 let message = "";
136 println!("M =\t{}", message);
137 let mut cipher = [0_u8; 8];
138 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
139 print!("C =\t");
140 for c in cipher.clone()
141 { print!("{:02X} ", c); }
142 println!();
143 let mut txt = String::new();
144 for c in cipher.clone()
145 { write!(txt, "{:02X} ", c); }
146 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
147 println!();
148
149 // Normal case for the message shorter than 8 bytes
150 let key = 0x_1234567890ABCDEF_u64;
151 println!("K =\t{:#016X}", key);
152 let mut a_des = DES::new_with_key_u64(key);
153
154 let message = "7 bytes";
155 println!("M =\t{}", message);
156 let mut cipher = [0_u8; 8];
157 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
158 print!("C =\t");
159 for c in cipher.clone()
160 { print!("{:02X} ", c); }
161 println!();
162 let mut txt = String::new();
163 for c in cipher.clone()
164 { write!(txt, "{:02X} ", c); }
165 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
166 println!();
167
168 // Normal case for the message of 8 bytes
169 let key = 0x_1234567890ABCDEF_u64;
170 println!("K =\t{:#016X}", key);
171 let mut a_des = DES::new_with_key_u64(key);
172
173 let message = "I am OK.";
174 println!("M =\t{}", message);
175 let mut cipher = [0_u8; 16];
176 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
177 print!("C =\t");
178 for c in cipher.clone()
179 { print!("{:02X} ", c); }
180 println!();
181 let mut txt = String::new();
182 for c in cipher.clone()
183 { write!(txt, "{:02X} ", c); }
184 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
185 println!();
186
187 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
188 let key = 0x_1234567890ABCDEF_u64;
189 println!("K =\t{:#016X}", key);
190 let mut a_des = DES::new_with_key_u64(key);
191
192 let message = "PARK Youngho";
193 println!("M =\t{}", message);
194 let mut cipher = [0_u8; 16];
195 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
196 print!("C =\t");
197 for c in cipher.clone()
198 { print!("{:02X} ", c); }
199 println!();
200 let mut txt = String::new();
201 for c in cipher.clone()
202 { write!(txt, "{:02X} ", c); }
203 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
204 println!();
205
206
207 // Normal case for the message of 16 bytes
208 let key = 0x_1234567890ABCDEF_u64;
209 println!("K =\t{:#016X}", key);
210 let mut a_des = DES::new_with_key_u64(key);
211
212 let message = "고맙습니다.";
213 println!("M =\t{}", message);
214 let mut cipher = [0_u8; 24];
215 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
216 print!("C =\t");
217 for c in cipher.clone()
218 { print!("{:02X} ", c); }
219 println!();
220 let mut txt = String::new();
221 for c in cipher.clone()
222 { write!(txt, "{:02X} ", c); }
223 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
224 println!("-------------------------------");
225}
226
227fn des_encrypt_with_padding_iso_ecb_into_vec()
228{
229 println!("des_encrypt_with_padding_iso_ecb_into_vec()");
230 use std::io::Write;
231 use std::fmt::Write as _;
232 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
233
234 // Normal case
235 let key = 0x_1234567890ABCDEF_u64;
236 println!("K =\t{:#016X}", key);
237 let mut a_des = DES::new_with_key_u64(key);
238
239 let message = "In the beginning God created the heavens and the earth.";
240 println!("M =\t{}", message);
241 let mut cipher = Vec::<u8>::new();
242 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
243 print!("C (16 rounds) =\t");
244 for c in cipher.clone()
245 { print!("{:02X} ", c); }
246 println!();
247 let mut txt = String::new();
248 for c in cipher.clone()
249 { write!(txt, "{:02X} ", c); }
250 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
251 println!();
252
253 // Expanded case for 128 rounds
254 let key = 0x_1234567890ABCDEF_u64;
255 println!("K =\t{:#016X}", key);
256 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
257
258 let message = "In the beginning God created the heavens and the earth.";
259 println!("M =\t{}", message);
260 let mut cipher = Vec::<u8>::new();
261 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
262 print!("C (128 rounds) =\t");
263 for c in cipher.clone()
264 { print!("{:02X} ", c); }
265 println!();
266 let mut txt = String::new();
267 for c in cipher.clone()
268 { write!(txt, "{:02X} ", c); }
269 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
270 println!();
271
272 // Expanded case for 0 rounds which means that key is meaningless
273 let key1 = 0x_1234567890ABCDEF_u64;
274 let key2 = 0_u64;
275 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
276 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
277 println!("K =\t{:#016X}", key);
278
279 let message = "In the beginning God created the heavens and the earth.";
280 println!("M =\t{}", message);
281 let mut cipher1 = Vec::<u8>::new();
282 let mut cipher2 = Vec::<u8>::new();
283 c_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher1);
284 d_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher2);
285 print!("C (0 rounds) =\t");
286 for c in cipher1.clone()
287 { print!("{:02X} ", c); }
288 println!();
289 let mut txt = String::new();
290 for c in cipher1.clone()
291 { write!(txt, "{:02X} ", c); }
292 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
293 print!("D (0 rounds) =\t");
294 for c in cipher2.clone()
295 { print!("{:02X} ", c); }
296 println!();
297 let mut txt = String::new();
298 for c in cipher2.clone()
299 { write!(txt, "{:02X} ", c); }
300 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
301 println!();
302
303 // Normal case for the message of 0 bytes
304 let key = 0x_1234567890ABCDEF_u64;
305 println!("K =\t{:#016X}", key);
306 let mut a_des = DES::new_with_key_u64(key);
307
308 let message = "";
309 println!("M =\t{}", message);
310 let mut cipher = Vec::<u8>::new();
311 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
312 print!("C =\t");
313 for c in cipher.clone()
314 { print!("{:02X} ", c); }
315 println!();
316 let mut txt = String::new();
317 for c in cipher.clone()
318 { write!(txt, "{:02X} ", c); }
319 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
320 println!();
321
322 // Normal case for the message shorter than 8 bytes
323 let key = 0x_1234567890ABCDEF_u64;
324 println!("K =\t{:#016X}", key);
325 let mut a_des = DES::new_with_key_u64(key);
326
327 let message = "7 bytes";
328 println!("M =\t{}", message);
329 let mut cipher = Vec::<u8>::new();
330 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
331 print!("C =\t");
332 for c in cipher.clone()
333 { print!("{:02X} ", c); }
334 println!();
335 let mut txt = String::new();
336 for c in cipher.clone()
337 { write!(txt, "{:02X} ", c); }
338 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
339 println!();
340
341 // Normal case for the message of 8 bytes
342 let key = 0x_1234567890ABCDEF_u64;
343 println!("K =\t{:#016X}", key);
344 let mut a_des = DES::new_with_key_u64(key);
345
346 let message = "I am OK.";
347 println!("M =\t{}", message);
348 let mut cipher = Vec::<u8>::new();
349 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
350 print!("C =\t");
351 for c in cipher.clone()
352 { print!("{:02X} ", c); }
353 println!();
354 let mut txt = String::new();
355 for c in cipher.clone()
356 { write!(txt, "{:02X} ", c); }
357 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
358 println!();
359
360 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
361 let key = 0x_1234567890ABCDEF_u64;
362 println!("K =\t{:#016X}", key);
363 let mut a_des = DES::new_with_key_u64(key);
364
365 let message = "PARK Youngho";
366 println!("M =\t{}", message);
367 let mut cipher = Vec::<u8>::new();
368 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
369 print!("C =\t");
370 for c in cipher.clone()
371 { print!("{:02X} ", c); }
372 println!();
373 let mut txt = String::new();
374 for c in cipher.clone()
375 { write!(txt, "{:02X} ", c); }
376 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
377 println!();
378
379 // Normal case for the message of 16 bytes
380 let key = 0x_1234567890ABCDEF_u64;
381 println!("K =\t{:#016X}", key);
382 let mut a_des = DES::new_with_key_u64(key);
383
384 let message = "고맙습니다.";
385 println!("M =\t{}", message);
386 let mut cipher = Vec::<u8>::new();
387 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
388 print!("C =\t");
389 for c in cipher.clone()
390 { print!("{:02X} ", c); }
391 println!();
392 let mut txt = String::new();
393 for c in cipher.clone()
394 { write!(txt, "{:02X} ", c); }
395 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
396 println!("-------------------------------");
397}
398
399fn des_encrypt_with_padding_iso_ecb_into_array()
400{
401 println!("des_encrypt_with_padding_iso_ecb_into_array()");
402 use std::io::Write;
403 use std::fmt::Write as _;
404 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
405
406 // Normal case
407 let key = 0x_1234567890ABCDEF_u64;
408 println!("K =\t{:#016X}", key);
409 let mut a_des = DES::new_with_key_u64(key);
410
411 let message = "In the beginning God created the heavens and the earth.";
412 println!("M =\t{}", message);
413 let mut cipher = [0_u8; 56];
414 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
415 print!("C (16 rounds) =\t");
416 for c in cipher.clone()
417 { print!("{:02X} ", c); }
418 println!();
419 let mut txt = String::new();
420 for c in cipher.clone()
421 { write!(txt, "{:02X} ", c); }
422 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
423 println!();
424
425 // Expanded case for 128 rounds
426 let key = 0x_1234567890ABCDEF_u64;
427 println!("K =\t{:#016X}", key);
428 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
429
430 let message = "In the beginning God created the heavens and the earth.";
431 println!("M =\t{}", message);
432 let mut cipher = [0_u8; 56];
433 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
434 print!("C (128 rounds) =\t");
435 for c in cipher.clone()
436 { print!("{:02X} ", c); }
437 println!();
438 let mut txt = String::new();
439 for c in cipher.clone()
440 { write!(txt, "{:02X} ", c); }
441 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
442 println!();
443
444 // Expanded case for 0 rounds which means that key is meaningless
445 let key1 = 0x_1234567890ABCDEF_u64;
446 let key2 = 0_u64;
447 println!("K =\t{:#016X}", key);
448 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
449 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
450
451 let message = "In the beginning God created the heavens and the earth.";
452 println!("M =\t{}", message);
453 let mut cipher1 = [0_u8; 56];
454 let mut cipher2 = [0_u8; 56];
455 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
456 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
457 print!("C (0 rounds) =\t");
458 for c in cipher1.clone()
459 { print!("{:02X} ", c); }
460 println!();
461 let mut txt = String::new();
462 for c in cipher1.clone()
463 { write!(txt, "{:02X} ", c); }
464 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
465 print!("D (0 rounds) =\t");
466 for c in cipher2.clone()
467 { print!("{:02X} ", c); }
468 println!();
469 let mut txt = String::new();
470 for c in cipher2.clone()
471 { write!(txt, "{:02X} ", c); }
472 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
473 println!();
474
475 // Normal case for the message of 0 bytes
476 let key = 0x_1234567890ABCDEF_u64;
477 println!("K =\t{:#016X}", key);
478 let mut a_des = DES::new_with_key_u64(key);
479
480 let message = "";
481 println!("M =\t{}", message);
482 let mut cipher = [0_u8; 8];
483 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
484 print!("C =\t");
485 for c in cipher.clone()
486 { print!("{:02X} ", c); }
487 println!();
488 let mut txt = String::new();
489 for c in cipher.clone()
490 { write!(txt, "{:02X} ", c); }
491 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
492 println!();
493
494 // Normal case for the message shorter than 8 bytes
495 let key = 0x_1234567890ABCDEF_u64;
496 println!("K =\t{:#016X}", key);
497 let mut a_des = DES::new_with_key_u64(key);
498
499 let message = "7 bytes";
500 println!("M =\t{}", message);
501 let mut cipher = [0_u8; 8];
502 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
503 print!("C =\t");
504 for c in cipher.clone()
505 { print!("{:02X} ", c); }
506 println!();
507 let mut txt = String::new();
508 for c in cipher.clone()
509 { write!(txt, "{:02X} ", c); }
510 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
511 println!();
512
513 // Normal case for the message of 8 bytes
514 let key = 0x_1234567890ABCDEF_u64;
515 println!("K =\t{:#016X}", key);
516 let mut a_des = DES::new_with_key_u64(key);
517
518 let message = "I am OK.";
519 println!("M =\t{}", message);
520 let mut cipher = [0_u8; 16];
521 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
522 print!("C =\t");
523 for c in cipher.clone()
524 { print!("{:02X} ", c); }
525 println!();
526 let mut txt = String::new();
527 for c in cipher.clone()
528 { write!(txt, "{:02X} ", c); }
529 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
530 println!();
531
532 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
533 let key = 0x_1234567890ABCDEF_u64;
534 println!("K =\t{:#016X}", key);
535 let mut a_des = DES::new_with_key_u64(key);
536
537 let message = "PARK Youngho";
538 println!("M =\t{}", message);
539 let mut cipher = [0_u8; 16];
540 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
541 print!("C =\t");
542 for c in cipher.clone()
543 { print!("{:02X} ", c); }
544 println!();
545 let mut txt = String::new();
546 for c in cipher.clone()
547 { write!(txt, "{:02X} ", c); }
548 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
549 println!();
550
551
552 // Normal case for the message of 16 bytes
553 let key = 0x_1234567890ABCDEF_u64;
554 println!("K =\t{:#016X}", key);
555 let mut a_des = DES::new_with_key_u64(key);
556
557 let message = "고맙습니다.";
558 println!("M =\t{}", message);
559 let mut cipher = [0_u8; 24];
560 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
561 print!("C =\t");
562 for c in cipher.clone()
563 { print!("{:02X} ", c); }
564 println!();
565 let mut txt = String::new();
566 for c in cipher.clone()
567 { write!(txt, "{:02X} ", c); }
568 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
569 println!("-------------------------------");
570}
571
572fn des_encrypt_str_with_padding_iso_ecb()
573{
574 println!("des_encrypt_str_with_padding_iso_ecb()");
575 use std::io::Write;
576 use std::fmt::Write as _;
577 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
578
579 // Normal case
580 let key = 0x_1234567890ABCDEF_u64;
581 println!("K =\t{:#016X}", key);
582 let mut a_des = DES::new_with_key_u64(key);
583
584 let message = "In the beginning God created the heavens and the earth.";
585 println!("M =\t{}", message);
586 let mut cipher = [0_u8; 56];
587 a_des.encrypt_str(&message, cipher.as_mut_ptr());
588 print!("C (16 rounds) =\t");
589 for c in cipher.clone()
590 { print!("{:02X} ", c); }
591 println!();
592 let mut txt = String::new();
593 for c in cipher.clone()
594 { write!(txt, "{:02X} ", c); }
595 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
596 println!();
597
598 // Expanded case for 128 rounds
599 let key = 0x_1234567890ABCDEF_u64;
600 println!("K =\t{:#016X}", key);
601 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
602
603 let message = "In the beginning God created the heavens and the earth.";
604 println!("M =\t{}", message);
605 let mut cipher = [0_u8; 56];
606 a_des.encrypt_str(&message, cipher.as_mut_ptr());
607 print!("C (128 rounds) =\t");
608 for c in cipher.clone()
609 { print!("{:02X} ", c); }
610 println!();
611 let mut txt = String::new();
612 for c in cipher.clone()
613 { write!(txt, "{:02X} ", c); }
614 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
615 println!();
616
617 // Expanded case for 0 rounds which means that key is meaningless
618 let key1 = 0x_1234567890ABCDEF_u64;
619 let key2 = 0_u64;
620 println!("K =\t{:#016X}", key);
621 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
622 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
623
624 let message = "In the beginning God created the heavens and the earth.";
625 println!("M =\t{}", message);
626 let mut cipher1 = [0_u8; 56];
627 let mut cipher2 = [0_u8; 56];
628 c_des.encrypt_str(&message, cipher1.as_mut_ptr());
629 d_des.encrypt_str(&message, cipher2.as_mut_ptr());
630 print!("C (0 rounds) =\t");
631 for c in cipher1.clone()
632 { print!("{:02X} ", c); }
633 println!();
634 let mut txt = String::new();
635 for c in cipher1.clone()
636 { write!(txt, "{:02X} ", c); }
637 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
638 print!("D (0 rounds) =\t");
639 for c in cipher2.clone()
640 { print!("{:02X} ", c); }
641 println!();
642 let mut txt = String::new();
643 for c in cipher2.clone()
644 { write!(txt, "{:02X} ", c); }
645 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
646 println!();
647
648 // Normal case for the message of 0 bytes
649 let key = 0x_1234567890ABCDEF_u64;
650 println!("K =\t{:#016X}", key);
651 let mut a_des = DES::new_with_key_u64(key);
652
653 let message = "";
654 println!("M =\t{}", message);
655 let mut cipher = [0_u8; 8];
656 a_des.encrypt_str(&message, cipher.as_mut_ptr());
657 print!("C =\t");
658 for c in cipher.clone()
659 { print!("{:02X} ", c); }
660 println!();
661 let mut txt = String::new();
662 for c in cipher.clone()
663 { write!(txt, "{:02X} ", c); }
664 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
665 println!();
666
667 // Normal case for the message shorter than 8 bytes
668 let key = 0x_1234567890ABCDEF_u64;
669 println!("K =\t{:#016X}", key);
670 let mut a_des = DES::new_with_key_u64(key);
671
672 let message = "7 bytes";
673 println!("M =\t{}", message);
674 let mut cipher = [0_u8; 8];
675 a_des.encrypt_str(&message, cipher.as_mut_ptr());
676 print!("C =\t");
677 for c in cipher.clone()
678 { print!("{:02X} ", c); }
679 println!();
680 let mut txt = String::new();
681 for c in cipher.clone()
682 { write!(txt, "{:02X} ", c); }
683 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
684 println!();
685
686 // Normal case for the message of 8 bytes
687 let key = 0x_1234567890ABCDEF_u64;
688 println!("K =\t{:#016X}", key);
689 let mut a_des = DES::new_with_key_u64(key);
690
691 let message = "I am OK.";
692 println!("M =\t{}", message);
693 let mut cipher = [0_u8; 16];
694 a_des.encrypt_str(&message, cipher.as_mut_ptr());
695 print!("C =\t");
696 for c in cipher.clone()
697 { print!("{:02X} ", c); }
698 println!();
699 let mut txt = String::new();
700 for c in cipher.clone()
701 { write!(txt, "{:02X} ", c); }
702 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
703 println!();
704
705 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
706 let key = 0x_1234567890ABCDEF_u64;
707 println!("K =\t{:#016X}", key);
708 let mut a_des = DES::new_with_key_u64(key);
709
710 let message = "PARK Youngho";
711 println!("M =\t{}", message);
712 let mut cipher = [0_u8; 16];
713 a_des.encrypt_str(&message, cipher.as_mut_ptr());
714 print!("C =\t");
715 for c in cipher.clone()
716 { print!("{:02X} ", c); }
717 println!();
718 let mut txt = String::new();
719 for c in cipher.clone()
720 { write!(txt, "{:02X} ", c); }
721 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
722 println!();
723
724
725 // Normal case for the message of 16 bytes
726 let key = 0x_1234567890ABCDEF_u64;
727 println!("K =\t{:#016X}", key);
728 let mut a_des = DES::new_with_key_u64(key);
729
730 let message = "고맙습니다.";
731 println!("M =\t{}", message);
732 let mut cipher = [0_u8; 24];
733 a_des.encrypt_str(&message, cipher.as_mut_ptr());
734 print!("C =\t");
735 for c in cipher.clone()
736 { print!("{:02X} ", c); }
737 println!();
738 let mut txt = String::new();
739 for c in cipher.clone()
740 { write!(txt, "{:02X} ", c); }
741 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
742 println!("-------------------------------");
743}
744
745fn des_encrypt_str_with_padding_iso_ecb_into_vec()
746{
747 println!("des_encrypt_str_with_padding_iso_ecb_into_vec()");
748 use std::io::Write;
749 use std::fmt::Write as _;
750 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
751
752 // Normal case
753 let key = 0x_1234567890ABCDEF_u64;
754 println!("K =\t{:#016X}", key);
755 let mut a_des = DES::new_with_key_u64(key);
756
757 let message = "In the beginning God created the heavens and the earth.";
758 println!("M =\t{}", message);
759 let mut cipher = Vec::<u8>::new();
760 a_des.encrypt_str_into_vec(&message, &mut cipher);
761 print!("C (16 rounds) =\t");
762 for c in cipher.clone()
763 { print!("{:02X} ", c); }
764 println!();
765 let mut txt = String::new();
766 for c in cipher.clone()
767 { write!(txt, "{:02X} ", c); }
768 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
769 println!();
770
771 // Expanded case for 128 rounds
772 let key = 0x_1234567890ABCDEF_u64;
773 println!("K =\t{:#016X}", key);
774 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
775
776 let message = "In the beginning God created the heavens and the earth.";
777 println!("M =\t{}", message);
778 let mut cipher = Vec::<u8>::new();
779 a_des.encrypt_str_into_vec(&message, &mut cipher);
780 print!("C (128 rounds) =\t");
781 for c in cipher.clone()
782 { print!("{:02X} ", c); }
783 println!();
784 let mut txt = String::new();
785 for c in cipher.clone()
786 { write!(txt, "{:02X} ", c); }
787 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
788 println!();
789
790 // Expanded case for 0 rounds which means that key is meaningless
791 let key1 = 0x_1234567890ABCDEF_u64;
792 let key2 = 0_u64;
793 println!("K =\t{:#016X}", key);
794 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
795 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
796
797 let message = "In the beginning God created the heavens and the earth.";
798 println!("M =\t{}", message);
799 let mut cipher1 = Vec::<u8>::new();
800 let mut cipher2 = Vec::<u8>::new();
801 c_des.encrypt_str_into_vec(&message, &mut cipher1);
802 d_des.encrypt_str_into_vec(&message, &mut cipher2);
803 print!("C (0 rounds) =\t");
804 for c in cipher1.clone()
805 { print!("{:02X} ", c); }
806 println!();
807 let mut txt = String::new();
808 for c in cipher1.clone()
809 { write!(txt, "{:02X} ", c); }
810 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
811 print!("D (0 rounds) =\t");
812 for c in cipher2.clone()
813 { print!("{:02X} ", c); }
814 println!();
815 let mut txt = String::new();
816 for c in cipher2.clone()
817 { write!(txt, "{:02X} ", c); }
818 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
819 println!();
820
821 // Normal case for the message of 0 bytes
822 let key = 0x_1234567890ABCDEF_u64;
823 println!("K =\t{:#016X}", key);
824 let mut a_des = DES::new_with_key_u64(key);
825
826 let message = "";
827 println!("M =\t{}", message);
828 let mut cipher = Vec::<u8>::new();
829 a_des.encrypt_str_into_vec(&message, &mut cipher);
830 print!("C =\t");
831 for c in cipher.clone()
832 { print!("{:02X} ", c); }
833 println!();
834 let mut txt = String::new();
835 for c in cipher.clone()
836 { write!(txt, "{:02X} ", c); }
837 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
838 println!();
839
840 // Normal case for the message shorter than 8 bytes
841 let key = 0x_1234567890ABCDEF_u64;
842 println!("K =\t{:#016X}", key);
843 let mut a_des = DES::new_with_key_u64(key);
844
845 let message = "7 bytes";
846 println!("M =\t{}", message);
847 let mut cipher = Vec::<u8>::new();
848 a_des.encrypt_str_into_vec(&message, &mut cipher);
849 print!("C =\t");
850 for c in cipher.clone()
851 { print!("{:02X} ", c); }
852 println!();
853 let mut txt = String::new();
854 for c in cipher.clone()
855 { write!(txt, "{:02X} ", c); }
856 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
857 println!();
858
859 // Normal case for the message of 8 bytes
860 let key = 0x_1234567890ABCDEF_u64;
861 println!("K =\t{:#016X}", key);
862 let mut a_des = DES::new_with_key_u64(key);
863
864 let message = "I am OK.";
865 println!("M =\t{}", message);
866 let mut cipher = Vec::<u8>::new();
867 a_des.encrypt_str_into_vec(&message, &mut cipher);
868 print!("C =\t");
869 for c in cipher.clone()
870 { print!("{:02X} ", c); }
871 println!();
872 let mut txt = String::new();
873 for c in cipher.clone()
874 { write!(txt, "{:02X} ", c); }
875 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
876 println!();
877
878 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
879 let key = 0x_1234567890ABCDEF_u64;
880 println!("K =\t{:#016X}", key);
881 let mut a_des = DES::new_with_key_u64(key);
882
883 let message = "PARK Youngho";
884 println!("M =\t{}", message);
885 let mut cipher = Vec::<u8>::new();
886 a_des.encrypt_str_into_vec(&message, &mut cipher);
887 print!("C =\t");
888 for c in cipher.clone()
889 { print!("{:02X} ", c); }
890 println!();
891 let mut txt = String::new();
892 for c in cipher.clone()
893 { write!(txt, "{:02X} ", c); }
894 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
895 println!();
896
897
898 // Normal case for the message of 16 bytes
899 let key = 0x_1234567890ABCDEF_u64;
900 println!("K =\t{:#016X}", key);
901 let mut a_des = DES::new_with_key_u64(key);
902
903 let message = "고맙습니다.";
904 println!("M =\t{}", message);
905 let mut cipher = Vec::<u8>::new();
906 a_des.encrypt_str_into_vec(&message, &mut cipher);
907 print!("C =\t");
908 for c in cipher.clone()
909 { print!("{:02X} ", c); }
910 println!();
911 let mut txt = String::new();
912 for c in cipher.clone()
913 { write!(txt, "{:02X} ", c); }
914 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
915 println!("-------------------------------");
916}
917
918fn des_encrypt_str_with_padding_iso_ecb_into_array()
919{
920 println!("des_encrypt_str_with_padding_iso_ecb_into_array()");
921 use std::io::Write;
922 use std::fmt::Write as _;
923 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
924
925 // Normal case
926 let key = 0x_1234567890ABCDEF_u64;
927 println!("K =\t{:#016X}", key);
928 let mut a_des = DES::new_with_key_u64(key);
929
930 let message = "In the beginning God created the heavens and the earth.";
931 println!("M =\t{}", message);
932 let mut cipher = [0_u8; 56];
933 a_des.encrypt_str_into_array(&message, &mut cipher);
934 print!("C (16 rounds) =\t");
935 for c in cipher.clone()
936 { print!("{:02X} ", c); }
937 println!();
938 let mut txt = String::new();
939 for c in cipher.clone()
940 { write!(txt, "{:02X} ", c); }
941 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
942 println!();
943
944 // Expanded case for 128 rounds
945 let key = 0x_1234567890ABCDEF_u64;
946 println!("K =\t{:#016X}", key);
947 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
948
949 let message = "In the beginning God created the heavens and the earth.";
950 println!("M =\t{}", message);
951 let mut cipher = [0_u8; 56];
952 a_des.encrypt_str_into_array(&message, &mut cipher);
953 print!("C (128 rounds) =\t");
954 for c in cipher.clone()
955 { print!("{:02X} ", c); }
956 println!();
957 let mut txt = String::new();
958 for c in cipher.clone()
959 { write!(txt, "{:02X} ", c); }
960 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
961 println!();
962
963 // Expanded case for 0 rounds which means that key is meaningless
964 let key1 = 0x_1234567890ABCDEF_u64;
965 let key2 = 0_u64;
966 println!("K =\t{:#016X}", key);
967 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
968 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
969
970 let message = "In the beginning God created the heavens and the earth.";
971 println!("M =\t{}", message);
972 let mut cipher1 = [0_u8; 56];
973 let mut cipher2 = [0_u8; 56];
974 c_des.encrypt_str_into_array(&message, &mut cipher1);
975 d_des.encrypt_str_into_array(&message, &mut cipher2);
976 print!("C (0 rounds) =\t");
977 for c in cipher1.clone()
978 { print!("{:02X} ", c); }
979 println!();
980 let mut txt = String::new();
981 for c in cipher1.clone()
982 { write!(txt, "{:02X} ", c); }
983 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
984 print!("D (0 rounds) =\t");
985 for c in cipher2.clone()
986 { print!("{:02X} ", c); }
987 println!();
988 let mut txt = String::new();
989 for c in cipher2.clone()
990 { write!(txt, "{:02X} ", c); }
991 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
992 println!();
993
994 // Normal case for the message of 0 bytes
995 let key = 0x_1234567890ABCDEF_u64;
996 println!("K =\t{:#016X}", key);
997 let mut a_des = DES::new_with_key_u64(key);
998
999 let message = "";
1000 println!("M =\t{}", message);
1001 let mut cipher = [0_u8; 8];
1002 a_des.encrypt_str_into_array(&message, &mut cipher);
1003 print!("C =\t");
1004 for c in cipher.clone()
1005 { print!("{:02X} ", c); }
1006 println!();
1007 let mut txt = String::new();
1008 for c in cipher.clone()
1009 { write!(txt, "{:02X} ", c); }
1010 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1011 println!();
1012
1013 // Normal case for the message shorter than 8 bytes
1014 let key = 0x_1234567890ABCDEF_u64;
1015 println!("K =\t{:#016X}", key);
1016 let mut a_des = DES::new_with_key_u64(key);
1017
1018 let message = "7 bytes";
1019 println!("M =\t{}", message);
1020 let mut cipher = [0_u8; 8];
1021 a_des.encrypt_str_into_array(&message, &mut cipher);
1022 print!("C =\t");
1023 for c in cipher.clone()
1024 { print!("{:02X} ", c); }
1025 println!();
1026 let mut txt = String::new();
1027 for c in cipher.clone()
1028 { write!(txt, "{:02X} ", c); }
1029 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1030 println!();
1031
1032 // Normal case for the message of 8 bytes
1033 let key = 0x_1234567890ABCDEF_u64;
1034 println!("K =\t{:#016X}", key);
1035 let mut a_des = DES::new_with_key_u64(key);
1036
1037 let message = "I am OK.";
1038 println!("M =\t{}", message);
1039 let mut cipher = [0_u8; 16];
1040 a_des.encrypt_str_into_array(&message, &mut cipher);
1041 print!("C =\t");
1042 for c in cipher.clone()
1043 { print!("{:02X} ", c); }
1044 println!();
1045 let mut txt = String::new();
1046 for c in cipher.clone()
1047 { write!(txt, "{:02X} ", c); }
1048 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1049 println!();
1050
1051 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1052 let key = 0x_1234567890ABCDEF_u64;
1053 println!("K =\t{:#016X}", key);
1054 let mut a_des = DES::new_with_key_u64(key);
1055
1056 let message = "PARK Youngho";
1057 println!("M =\t{}", message);
1058 let mut cipher = [0_u8; 16];
1059 a_des.encrypt_str_into_array(&message, &mut cipher);
1060 print!("C =\t");
1061 for c in cipher.clone()
1062 { print!("{:02X} ", c); }
1063 println!();
1064 let mut txt = String::new();
1065 for c in cipher.clone()
1066 { write!(txt, "{:02X} ", c); }
1067 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1068 println!();
1069
1070
1071 // Normal case for the message of 16 bytes
1072 let key = 0x_1234567890ABCDEF_u64;
1073 println!("K =\t{:#016X}", key);
1074 let mut a_des = DES::new_with_key_u64(key);
1075
1076 let message = "고맙습니다.";
1077 println!("M =\t{}", message);
1078 let mut cipher = [0_u8; 24];
1079 a_des.encrypt_str_into_array(&message, &mut cipher);
1080 print!("C =\t");
1081 for c in cipher.clone()
1082 { print!("{:02X} ", c); }
1083 println!();
1084 let mut txt = String::new();
1085 for c in cipher.clone()
1086 { write!(txt, "{:02X} ", c); }
1087 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1088 println!("-------------------------------");
1089}
1090
1091fn des_encrypt_string_with_padding_iso_ecb()
1092{
1093 println!("des_encrypt_string_with_padding_iso_ecb()");
1094 use std::io::Write;
1095 use std::fmt::Write as _;
1096 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1097
1098 // Normal case
1099 let key = 0x_1234567890ABCDEF_u64;
1100 println!("K =\t{:#016X}", key);
1101 let mut a_des = DES::new_with_key_u64(key);
1102
1103 let message = "In the beginning God created the heavens and the earth.".to_string();
1104 println!("M =\t{}", message);
1105 let mut cipher = [0_u8; 56];
1106 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1107 print!("C (16 rounds) =\t");
1108 for c in cipher.clone()
1109 { print!("{:02X} ", c); }
1110 println!();
1111 let mut txt = String::new();
1112 for c in cipher.clone()
1113 { write!(txt, "{:02X} ", c); }
1114 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1115 println!();
1116
1117 // Expanded case for 128 rounds
1118 let key = 0x_1234567890ABCDEF_u64;
1119 println!("K =\t{:#016X}", key);
1120 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1121
1122 let message = "In the beginning God created the heavens and the earth.".to_string();
1123 println!("M =\t{}", message);
1124 let mut cipher = [0_u8; 56];
1125 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1126 print!("C (128 rounds) =\t");
1127 for c in cipher.clone()
1128 { print!("{:02X} ", c); }
1129 println!();
1130 let mut txt = String::new();
1131 for c in cipher.clone()
1132 { write!(txt, "{:02X} ", c); }
1133 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1134 println!();
1135
1136 // Expanded case for 0 rounds which means that key is meaningless
1137 let key1 = 0x_1234567890ABCDEF_u64;
1138 let key2 = 0_u64;
1139 println!("K =\t{:#016X}", key);
1140 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1141 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1142
1143 let message = "In the beginning God created the heavens and the earth.".to_string();
1144 println!("M =\t{}", message);
1145 let mut cipher1 = [0_u8; 56];
1146 let mut cipher2 = [0_u8; 56];
1147 c_des.encrypt_string(&message, cipher1.as_mut_ptr());
1148 d_des.encrypt_string(&message, cipher2.as_mut_ptr());
1149 print!("C (0 rounds) =\t");
1150 for c in cipher1.clone()
1151 { print!("{:02X} ", c); }
1152 println!();
1153 let mut txt = String::new();
1154 for c in cipher1.clone()
1155 { write!(txt, "{:02X} ", c); }
1156 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1157 print!("D (0 rounds) =\t");
1158 for c in cipher2.clone()
1159 { print!("{:02X} ", c); }
1160 println!();
1161 let mut txt = String::new();
1162 for c in cipher2.clone()
1163 { write!(txt, "{:02X} ", c); }
1164 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1165 println!();
1166
1167 // Normal case for the message of 0 bytes
1168 let key = 0x_1234567890ABCDEF_u64;
1169 println!("K =\t{:#016X}", key);
1170 let mut a_des = DES::new_with_key_u64(key);
1171
1172 let message = "".to_string();
1173 println!("M =\t{}", message);
1174 let mut cipher = [0_u8; 8];
1175 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1176 print!("C =\t");
1177 for c in cipher.clone()
1178 { print!("{:02X} ", c); }
1179 println!();
1180 let mut txt = String::new();
1181 for c in cipher.clone()
1182 { write!(txt, "{:02X} ", c); }
1183 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1184 println!();
1185
1186 // Normal case for the message shorter than 8 bytes
1187 let key = 0x_1234567890ABCDEF_u64;
1188 println!("K =\t{:#016X}", key);
1189 let mut a_des = DES::new_with_key_u64(key);
1190
1191 let message = "7 bytes".to_string();
1192 println!("M =\t{}", message);
1193 let mut cipher = [0_u8; 8];
1194 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1195 print!("C =\t");
1196 for c in cipher.clone()
1197 { print!("{:02X} ", c); }
1198 println!();
1199 let mut txt = String::new();
1200 for c in cipher.clone()
1201 { write!(txt, "{:02X} ", c); }
1202 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1203 println!();
1204
1205 // Normal case for the message of 8 bytes
1206 let key = 0x_1234567890ABCDEF_u64;
1207 println!("K =\t{:#016X}", key);
1208 let mut a_des = DES::new_with_key_u64(key);
1209
1210 let message = "I am OK.".to_string();
1211 println!("M =\t{}", message);
1212 let mut cipher = [0_u8; 16];
1213 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1214 print!("C =\t");
1215 for c in cipher.clone()
1216 { print!("{:02X} ", c); }
1217 println!();
1218 let mut txt = String::new();
1219 for c in cipher.clone()
1220 { write!(txt, "{:02X} ", c); }
1221 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1222 println!();
1223
1224 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1225 let key = 0x_1234567890ABCDEF_u64;
1226 println!("K =\t{:#016X}", key);
1227 let mut a_des = DES::new_with_key_u64(key);
1228
1229 let message = "PARK Youngho".to_string();
1230 println!("M =\t{}", message);
1231 let mut cipher = [0_u8; 16];
1232 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1233 print!("C =\t");
1234 for c in cipher.clone()
1235 { print!("{:02X} ", c); }
1236 println!();
1237 let mut txt = String::new();
1238 for c in cipher.clone()
1239 { write!(txt, "{:02X} ", c); }
1240 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1241 println!();
1242
1243
1244 // Normal case for the message of 16 bytes
1245 let key = 0x_1234567890ABCDEF_u64;
1246 println!("K =\t{:#016X}", key);
1247 let mut a_des = DES::new_with_key_u64(key);
1248
1249 let message = "고맙습니다.".to_string();
1250 println!("M =\t{}", message);
1251 let mut cipher = [0_u8; 24];
1252 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1253 print!("C =\t");
1254 for c in cipher.clone()
1255 { print!("{:02X} ", c); }
1256 println!();
1257 let mut txt = String::new();
1258 for c in cipher.clone()
1259 { write!(txt, "{:02X} ", c); }
1260 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1261 println!("-------------------------------");
1262}
1263
1264fn des_encrypt_string_with_padding_iso_ecb_into_vec()
1265{
1266 println!("des_encrypt_string_with_padding_iso_ecb_into_vec()");
1267 use std::io::Write;
1268 use std::fmt::Write as _;
1269 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1270
1271 // Normal case
1272 let key = 0x_1234567890ABCDEF_u64;
1273 println!("K =\t{:#016X}", key);
1274 let mut a_des = DES::new_with_key_u64(key);
1275
1276 let message = "In the beginning God created the heavens and the earth.".to_string();
1277 println!("M =\t{}", message);
1278 let mut cipher = Vec::<u8>::new();
1279 a_des.encrypt_string_into_vec(&message, &mut cipher);
1280 print!("C (16 rounds) =\t");
1281 for c in cipher.clone()
1282 { print!("{:02X} ", c); }
1283 println!();
1284 let mut txt = String::new();
1285 for c in cipher.clone()
1286 { write!(txt, "{:02X} ", c); }
1287 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1288 println!();
1289
1290 // Expanded case for 128 rounds
1291 let key = 0x_1234567890ABCDEF_u64;
1292 println!("K =\t{:#016X}", key);
1293 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1294
1295 let message = "In the beginning God created the heavens and the earth.".to_string();
1296 println!("M =\t{}", message);
1297 let mut cipher = Vec::<u8>::new();
1298 a_des.encrypt_string_into_vec(&message, &mut cipher);
1299 print!("C (128 rounds) =\t");
1300 for c in cipher.clone()
1301 { print!("{:02X} ", c); }
1302 println!();
1303 let mut txt = String::new();
1304 for c in cipher.clone()
1305 { write!(txt, "{:02X} ", c); }
1306 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1307 println!();
1308
1309 // Expanded case for 0 rounds which means that key is meaningless
1310 let key1 = 0x_1234567890ABCDEF_u64;
1311 let key2 = 0_u64;
1312 println!("K =\t{:#016X}", key);
1313 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1314 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1315
1316 let message = "In the beginning God created the heavens and the earth.".to_string();
1317 println!("M =\t{}", message);
1318 let mut cipher1 = Vec::<u8>::new();
1319 let mut cipher2 = Vec::<u8>::new();
1320 c_des.encrypt_string_into_vec(&message, &mut cipher1);
1321 d_des.encrypt_string_into_vec(&message, &mut cipher2);
1322 print!("C (0 rounds) =\t");
1323 for c in cipher1.clone()
1324 { print!("{:02X} ", c); }
1325 println!();
1326 let mut txt = String::new();
1327 for c in cipher1.clone()
1328 { write!(txt, "{:02X} ", c); }
1329 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1330 print!("D (0 rounds) =\t");
1331 for c in cipher2.clone()
1332 { print!("{:02X} ", c); }
1333 println!();
1334 let mut txt = String::new();
1335 for c in cipher2.clone()
1336 { write!(txt, "{:02X} ", c); }
1337 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1338 println!();
1339
1340 // Normal case for the message of 0 bytes
1341 let key = 0x_1234567890ABCDEF_u64;
1342 println!("K =\t{:#016X}", key);
1343 let mut a_des = DES::new_with_key_u64(key);
1344
1345 let message = "".to_string();
1346 println!("M =\t{}", message);
1347 let mut cipher = Vec::<u8>::new();
1348 a_des.encrypt_string_into_vec(&message, &mut cipher);
1349 print!("C =\t");
1350 for c in cipher.clone()
1351 { print!("{:02X} ", c); }
1352 println!();
1353 let mut txt = String::new();
1354 for c in cipher.clone()
1355 { write!(txt, "{:02X} ", c); }
1356 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1357 println!();
1358
1359 // Normal case for the message shorter than 8 bytes
1360 let key = 0x_1234567890ABCDEF_u64;
1361 println!("K =\t{:#016X}", key);
1362 let mut a_des = DES::new_with_key_u64(key);
1363
1364 let message = "7 bytes".to_string();
1365 println!("M =\t{}", message);
1366 let mut cipher = Vec::<u8>::new();
1367 a_des.encrypt_string_into_vec(&message, &mut cipher);
1368 print!("C =\t");
1369 for c in cipher.clone()
1370 { print!("{:02X} ", c); }
1371 println!();
1372 let mut txt = String::new();
1373 for c in cipher.clone()
1374 { write!(txt, "{:02X} ", c); }
1375 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1376 println!();
1377
1378 // Normal case for the message of 8 bytes
1379 let key = 0x_1234567890ABCDEF_u64;
1380 println!("K =\t{:#016X}", key);
1381 let mut a_des = DES::new_with_key_u64(key);
1382
1383 let message = "I am OK.".to_string();
1384 println!("M =\t{}", message);
1385 let mut cipher = Vec::<u8>::new();
1386 a_des.encrypt_string_into_vec(&message, &mut cipher);
1387 print!("C =\t");
1388 for c in cipher.clone()
1389 { print!("{:02X} ", c); }
1390 println!();
1391 let mut txt = String::new();
1392 for c in cipher.clone()
1393 { write!(txt, "{:02X} ", c); }
1394 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1395 println!();
1396
1397 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1398 let key = 0x_1234567890ABCDEF_u64;
1399 println!("K =\t{:#016X}", key);
1400 let mut a_des = DES::new_with_key_u64(key);
1401
1402 let message = "PARK Youngho".to_string();
1403 println!("M =\t{}", message);
1404 let mut cipher = Vec::<u8>::new();
1405 a_des.encrypt_string_into_vec(&message, &mut cipher);
1406 print!("C =\t");
1407 for c in cipher.clone()
1408 { print!("{:02X} ", c); }
1409 println!();
1410 let mut txt = String::new();
1411 for c in cipher.clone()
1412 { write!(txt, "{:02X} ", c); }
1413 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1414 println!();
1415
1416
1417 // Normal case for the message of 16 bytes
1418 let key = 0x_1234567890ABCDEF_u64;
1419 println!("K =\t{:#016X}", key);
1420 let mut a_des = DES::new_with_key_u64(key);
1421
1422 let message = "고맙습니다.".to_string();
1423 println!("M =\t{}", message);
1424 let mut cipher = Vec::<u8>::new();
1425 a_des.encrypt_string_into_vec(&message, &mut cipher);
1426 print!("C =\t");
1427 for c in cipher.clone()
1428 { print!("{:02X} ", c); }
1429 println!();
1430 let mut txt = String::new();
1431 for c in cipher.clone()
1432 { write!(txt, "{:02X} ", c); }
1433 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1434 println!("-------------------------------");
1435}
1436
1437fn des_encrypt_string_with_padding_iso_ecb_into_array()
1438{
1439 println!("des_encrypt_string_with_padding_iso_ecb_into_array()");
1440 use std::io::Write;
1441 use std::fmt::Write as _;
1442 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1443
1444 // Normal case
1445 let key = 0x_1234567890ABCDEF_u64;
1446 println!("K =\t{:#016X}", key);
1447 let mut a_des = DES::new_with_key_u64(key);
1448
1449 let message = "In the beginning God created the heavens and the earth.".to_string();
1450 println!("M =\t{}", message);
1451 let mut cipher = [0_u8; 56];
1452 a_des.encrypt_string_into_array(&message, &mut cipher);
1453 print!("C (16 rounds) =\t");
1454 for c in cipher.clone()
1455 { print!("{:02X} ", c); }
1456 println!();
1457 let mut txt = String::new();
1458 for c in cipher.clone()
1459 { write!(txt, "{:02X} ", c); }
1460 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1461 println!();
1462
1463 // Expanded case for 128 rounds
1464 let key = 0x_1234567890ABCDEF_u64;
1465 println!("K =\t{:#016X}", key);
1466 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1467
1468 let message = "In the beginning God created the heavens and the earth.".to_string();
1469 println!("M =\t{}", message);
1470 let mut cipher = [0_u8; 56];
1471 a_des.encrypt_string_into_array(&message, &mut cipher);
1472 print!("C (128 rounds) =\t");
1473 for c in cipher.clone()
1474 { print!("{:02X} ", c); }
1475 println!();
1476 let mut txt = String::new();
1477 for c in cipher.clone()
1478 { write!(txt, "{:02X} ", c); }
1479 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1480 println!();
1481
1482 // Expanded case for 0 rounds which means that key is meaningless
1483 let key1 = 0x_1234567890ABCDEF_u64;
1484 let key2 = 0_u64;
1485 println!("K =\t{:#016X}", key);
1486 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1487 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1488
1489 let message = "In the beginning God created the heavens and the earth.".to_string();
1490 println!("M =\t{}", message);
1491 let mut cipher1 = [0_u8; 56];
1492 let mut cipher2 = [0_u8; 56];
1493 c_des.encrypt_string_into_array(&message, &mut cipher1);
1494 d_des.encrypt_string_into_array(&message, &mut cipher2);
1495 print!("C (0 rounds) =\t");
1496 for c in cipher1.clone()
1497 { print!("{:02X} ", c); }
1498 println!();
1499 let mut txt = String::new();
1500 for c in cipher1.clone()
1501 { write!(txt, "{:02X} ", c); }
1502 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1503 print!("D (0 rounds) =\t");
1504 for c in cipher2.clone()
1505 { print!("{:02X} ", c); }
1506 println!();
1507 let mut txt = String::new();
1508 for c in cipher2.clone()
1509 { write!(txt, "{:02X} ", c); }
1510 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1511 println!();
1512
1513 // Normal case for the message of 0 bytes
1514 let key = 0x_1234567890ABCDEF_u64;
1515 println!("K =\t{:#016X}", key);
1516 let mut a_des = DES::new_with_key_u64(key);
1517
1518 let message = "".to_string();
1519 println!("M =\t{}", message);
1520 let mut cipher = [0_u8; 8];
1521 a_des.encrypt_string_into_array(&message, &mut cipher);
1522 print!("C =\t");
1523 for c in cipher.clone()
1524 { print!("{:02X} ", c); }
1525 println!();
1526 let mut txt = String::new();
1527 for c in cipher.clone()
1528 { write!(txt, "{:02X} ", c); }
1529 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1530 println!();
1531
1532 // Normal case for the message shorter than 8 bytes
1533 let key = 0x_1234567890ABCDEF_u64;
1534 println!("K =\t{:#016X}", key);
1535 let mut a_des = DES::new_with_key_u64(key);
1536
1537 let message = "7 bytes".to_string();
1538 println!("M =\t{}", message);
1539 let mut cipher = [0_u8; 8];
1540 a_des.encrypt_string_into_array(&message, &mut cipher);
1541 print!("C =\t");
1542 for c in cipher.clone()
1543 { print!("{:02X} ", c); }
1544 println!();
1545 let mut txt = String::new();
1546 for c in cipher.clone()
1547 { write!(txt, "{:02X} ", c); }
1548 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1549 println!();
1550
1551 // Normal case for the message of 8 bytes
1552 let key = 0x_1234567890ABCDEF_u64;
1553 println!("K =\t{:#016X}", key);
1554 let mut a_des = DES::new_with_key_u64(key);
1555
1556 let message = "I am OK.".to_string();
1557 println!("M =\t{}", message);
1558 let mut cipher = [0_u8; 16];
1559 a_des.encrypt_string_into_array(&message, &mut cipher);
1560 print!("C =\t");
1561 for c in cipher.clone()
1562 { print!("{:02X} ", c); }
1563 println!();
1564 let mut txt = String::new();
1565 for c in cipher.clone()
1566 { write!(txt, "{:02X} ", c); }
1567 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1568 println!();
1569
1570 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1571 let key = 0x_1234567890ABCDEF_u64;
1572 println!("K =\t{:#016X}", key);
1573 let mut a_des = DES::new_with_key_u64(key);
1574
1575 let message = "PARK Youngho".to_string();
1576 println!("M =\t{}", message);
1577 let mut cipher = [0_u8; 16];
1578 a_des.encrypt_string_into_array(&message, &mut cipher);
1579 print!("C =\t");
1580 for c in cipher.clone()
1581 { print!("{:02X} ", c); }
1582 println!();
1583 let mut txt = String::new();
1584 for c in cipher.clone()
1585 { write!(txt, "{:02X} ", c); }
1586 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1587 println!();
1588
1589 // Normal case for the message of 16 bytes
1590 let key = 0x_1234567890ABCDEF_u64;
1591 println!("K =\t{:#016X}", key);
1592 let mut a_des = DES::new_with_key_u64(key);
1593
1594 let message = "고맙습니다.".to_string();
1595 println!("M =\t{}", message);
1596 let mut cipher = [0_u8; 24];
1597 a_des.encrypt_string_into_array(&message, &mut cipher);
1598 print!("C =\t");
1599 for c in cipher.clone()
1600 { print!("{:02X} ", c); }
1601 println!();
1602 let mut txt = String::new();
1603 for c in cipher.clone()
1604 { write!(txt, "{:02X} ", c); }
1605 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1606 println!("-------------------------------");
1607}
1608
1609fn des_encrypt_vec_with_padding_iso_ecb()
1610{
1611 println!("des_encrypt_vec_with_padding_iso_ecb()");
1612 use std::io::Write;
1613 use std::fmt::Write as _;
1614 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1615
1616 // Normal case
1617 let key = 0x_1234567890ABCDEF_u64;
1618 println!("K =\t{:#016X}", key);
1619 let mut a_des = DES::new_with_key_u64(key);
1620
1621 let message = "In the beginning God created the heavens and the earth.";
1622 println!("M =\t{}", message);
1623 let message = unsafe { message.to_string().as_mut_vec().clone() };
1624 let mut cipher = [0_u8; 56];
1625 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1626 print!("C (16 rounds) =\t");
1627 for c in cipher.clone()
1628 { print!("{:02X} ", c); }
1629 println!();
1630 let mut txt = String::new();
1631 for c in cipher.clone()
1632 { write!(txt, "{:02X} ", c); }
1633 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1634 println!();
1635
1636 // Expanded case for 128 rounds
1637 let key = 0x_1234567890ABCDEF_u64;
1638 println!("K =\t{:#016X}", key);
1639 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1640
1641 let message = "In the beginning God created the heavens and the earth.";
1642 println!("M =\t{}", message);
1643 let message = unsafe { message.to_string().as_mut_vec().clone() };
1644 let mut cipher = [0_u8; 56];
1645 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1646 print!("C (128 rounds) =\t");
1647 for c in cipher.clone()
1648 { print!("{:02X} ", c); }
1649 println!();
1650 let mut txt = String::new();
1651 for c in cipher.clone()
1652 { write!(txt, "{:02X} ", c); }
1653 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1654 println!();
1655
1656 // Expanded case for 0 rounds which means that key is meaningless
1657 let key1 = 0x_1234567890ABCDEF_u64;
1658 let key2 = 0_u64;
1659 println!("K1 =\t{:#016X}", key1);
1660 println!("K2 =\t{:#016X}", key2);
1661 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1662 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1663
1664 let message = "In the beginning God created the heavens and the earth.";
1665 println!("M =\t{}", message);
1666 let message = unsafe { message.to_string().as_mut_vec().clone() };
1667 let mut cipher1 = [0_u8; 56];
1668 let mut cipher2 = [0_u8; 56];
1669 c_des.encrypt_vec(&message, cipher1.as_mut_ptr());
1670 d_des.encrypt_vec(&message, cipher2.as_mut_ptr());
1671 print!("C (0 rounds) =\t");
1672 for c in cipher1.clone()
1673 { print!("{:02X} ", c); }
1674 println!();
1675 let mut txt = String::new();
1676 for c in cipher1.clone()
1677 { write!(txt, "{:02X} ", c); }
1678 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1679 print!("D (0 rounds) =\t");
1680 for c in cipher2.clone()
1681 { print!("{:02X} ", c); }
1682 println!();
1683 let mut txt = String::new();
1684 for c in cipher2.clone()
1685 { write!(txt, "{:02X} ", c); }
1686 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1687 println!();
1688
1689 // Normal case for the message of 0 bytes
1690 let key = 0x_1234567890ABCDEF_u64;
1691 println!("K =\t{:#016X}", key);
1692 let mut a_des = DES::new_with_key_u64(key);
1693
1694 let message = "";
1695 println!("M =\t{}", message);
1696 let message = unsafe { message.to_string().as_mut_vec().clone() };
1697 let mut cipher = [0_u8; 8];
1698 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1699 print!("C =\t");
1700 for c in cipher.clone()
1701 { print!("{:02X} ", c); }
1702 println!();
1703 let mut txt = String::new();
1704 for c in cipher.clone()
1705 { write!(txt, "{:02X} ", c); }
1706 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1707 println!();
1708
1709 // Normal case for the message shorter than 8 bytes
1710 let key = 0x_1234567890ABCDEF_u64;
1711 println!("K =\t{:#016X}", key);
1712 let mut a_des = DES::new_with_key_u64(key);
1713
1714 let message = "7 bytes";
1715 println!("M =\t{}", message);
1716 let message = unsafe { message.to_string().as_mut_vec().clone() };
1717 let mut cipher = [0_u8; 8];
1718 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1719 print!("C =\t");
1720 for c in cipher.clone()
1721 { print!("{:02X} ", c); }
1722 println!();
1723 let mut txt = String::new();
1724 for c in cipher.clone()
1725 { write!(txt, "{:02X} ", c); }
1726 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1727 println!();
1728
1729 // Normal case for the message of 8 bytes
1730 let key = 0x_1234567890ABCDEF_u64;
1731 println!("K =\t{:#016X}", key);
1732 let mut a_des = DES::new_with_key_u64(key);
1733
1734 let message = "I am OK.";
1735 println!("M =\t{}", message);
1736 let message = unsafe { message.to_string().as_mut_vec().clone() };
1737 let mut cipher = [0_u8; 16];
1738 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1739 print!("C =\t");
1740 for c in cipher.clone()
1741 { print!("{:02X} ", c); }
1742 println!();
1743 let mut txt = String::new();
1744 for c in cipher.clone()
1745 { write!(txt, "{:02X} ", c); }
1746 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1747 println!();
1748
1749 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1750 let key = 0x_1234567890ABCDEF_u64;
1751 println!("K =\t{:#016X}", key);
1752 let mut a_des = DES::new_with_key_u64(key);
1753
1754 let message = "PARK Youngho";
1755 println!("M =\t{}", message);
1756 let message = unsafe { message.to_string().as_mut_vec().clone() };
1757 let mut cipher = [0_u8; 16];
1758 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1759 print!("C =\t");
1760 for c in cipher.clone()
1761 { print!("{:02X} ", c); }
1762 println!();
1763 let mut txt = String::new();
1764 for c in cipher.clone()
1765 { write!(txt, "{:02X} ", c); }
1766 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1767 println!();
1768
1769
1770 // Normal case for the message of 16 bytes
1771 let key = 0x_1234567890ABCDEF_u64;
1772 println!("K =\t{:#016X}", key);
1773 let mut a_des = DES::new_with_key_u64(key);
1774
1775 let message = "고맙습니다.";
1776 println!("M =\t{}", message);
1777 let message = unsafe { message.to_string().as_mut_vec().clone() };
1778 let mut cipher = [0_u8; 24];
1779 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1780 print!("C =\t");
1781 for c in cipher.clone()
1782 { print!("{:02X} ", c); }
1783 println!();
1784 let mut txt = String::new();
1785 for c in cipher.clone()
1786 { write!(txt, "{:02X} ", c); }
1787 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1788 println!("-------------------------------");
1789}
1790
1791fn des_encrypt_vec_with_padding_iso_ecb_into_vec()
1792{
1793 println!("des_encrypt_vec_with_padding_iso_ecb_into_vec()");
1794 use std::io::Write;
1795 use std::fmt::Write as _;
1796 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1797
1798 // Normal case
1799 let key = 0x_1234567890ABCDEF_u64;
1800 println!("K =\t{:#016X}", key);
1801 let mut a_des = DES::new_with_key_u64(key);
1802
1803 let message = "In the beginning God created the heavens and the earth.";
1804 println!("M =\t{}", message);
1805 let message = unsafe { message.to_string().as_mut_vec().clone() };
1806 let mut cipher = Vec::<u8>::new();
1807 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1808 print!("C (16 rounds) =\t");
1809 for c in cipher.clone()
1810 { print!("{:02X} ", c); }
1811 println!();
1812 let mut txt = String::new();
1813 for c in cipher.clone()
1814 { write!(txt, "{:02X} ", c); }
1815 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1816 println!();
1817
1818 // Expanded case for 128 rounds
1819 let key = 0x_1234567890ABCDEF_u64;
1820 println!("K =\t{:#016X}", key);
1821 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1822
1823 let message = "In the beginning God created the heavens and the earth.";
1824 println!("M =\t{}", message);
1825 let message = unsafe { message.to_string().as_mut_vec().clone() };
1826 let mut cipher = Vec::<u8>::new();
1827 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1828 print!("C (128 rounds) =\t");
1829 for c in cipher.clone()
1830 { print!("{:02X} ", c); }
1831 println!();
1832 let mut txt = String::new();
1833 for c in cipher.clone()
1834 { write!(txt, "{:02X} ", c); }
1835 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
1836 println!();
1837
1838 // Expanded case for 0 rounds which means that key is meaningless
1839 let key1 = 0x_1234567890ABCDEF_u64;
1840 let key2 = 0_u64;
1841 println!("K1 =\t{:#016X}", key1);
1842 println!("K2 =\t{:#016X}", key2);
1843 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1844 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1845
1846 let message = "In the beginning God created the heavens and the earth.";
1847 println!("M =\t{}", message);
1848 let message = unsafe { message.to_string().as_mut_vec().clone() };
1849
1850 let mut cipher1 = Vec::<u8>::new();
1851 let mut cipher2 = Vec::<u8>::new();
1852 c_des.encrypt_vec_into_vec(&message, &mut cipher1);
1853 d_des.encrypt_vec_into_vec(&message, &mut cipher2);
1854 print!("C (0 rounds) =\t");
1855 for c in cipher1.clone()
1856 { print!("{:02X} ", c); }
1857 println!();
1858 let mut txt = String::new();
1859 for c in cipher1.clone()
1860 { write!(txt, "{:02X} ", c); }
1861 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1862 print!("D (0 rounds) =\t");
1863 for c in cipher2.clone()
1864 { print!("{:02X} ", c); }
1865 println!();
1866 let mut txt = String::new();
1867 for c in cipher2.clone()
1868 { write!(txt, "{:02X} ", c); }
1869 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
1870 println!();
1871
1872 // Normal case for the message of 0 bytes
1873 let key = 0x_1234567890ABCDEF_u64;
1874 println!("K =\t{:#016X}", key);
1875 let mut a_des = DES::new_with_key_u64(key);
1876
1877 let message = "";
1878 println!("M =\t{}", message);
1879 let message = unsafe { message.to_string().as_mut_vec().clone() };
1880 let mut cipher = Vec::<u8>::new();
1881 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1882 print!("C =\t");
1883 for c in cipher.clone()
1884 { print!("{:02X} ", c); }
1885 println!();
1886 let mut txt = String::new();
1887 for c in cipher.clone()
1888 { write!(txt, "{:02X} ", c); }
1889 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
1890 println!();
1891
1892 // Normal case for the message shorter than 8 bytes
1893 let key = 0x_1234567890ABCDEF_u64;
1894 println!("K =\t{:#016X}", key);
1895 let mut a_des = DES::new_with_key_u64(key);
1896
1897 let message = "7 bytes";
1898 println!("M =\t{}", message);
1899 let message = unsafe { message.to_string().as_mut_vec().clone() };
1900 let mut cipher = Vec::<u8>::new();
1901 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1902 print!("C =\t");
1903 for c in cipher.clone()
1904 { print!("{:02X} ", c); }
1905 println!();
1906 let mut txt = String::new();
1907 for c in cipher.clone()
1908 { write!(txt, "{:02X} ", c); }
1909 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
1910 println!();
1911
1912 // Normal case for the message of 8 bytes
1913 let key = 0x_1234567890ABCDEF_u64;
1914 println!("K =\t{:#016X}", key);
1915 let mut a_des = DES::new_with_key_u64(key);
1916
1917 let message = "I am OK.";
1918 println!("M =\t{}", message);
1919 let message = unsafe { message.to_string().as_mut_vec().clone() };
1920 let mut cipher = Vec::<u8>::new();
1921 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1922 print!("C =\t");
1923 for c in cipher.clone()
1924 { print!("{:02X} ", c); }
1925 println!();
1926 let mut txt = String::new();
1927 for c in cipher.clone()
1928 { write!(txt, "{:02X} ", c); }
1929 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
1930 println!();
1931
1932 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1933 let key = 0x_1234567890ABCDEF_u64;
1934 println!("K =\t{:#016X}", key);
1935 let mut a_des = DES::new_with_key_u64(key);
1936
1937 let message = "PARK Youngho";
1938 println!("M =\t{}", message);
1939 let message = unsafe { message.to_string().as_mut_vec().clone() };
1940 let mut cipher = Vec::<u8>::new();
1941 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1942 print!("C =\t");
1943 for c in cipher.clone()
1944 { print!("{:02X} ", c); }
1945 println!();
1946 let mut txt = String::new();
1947 for c in cipher.clone()
1948 { write!(txt, "{:02X} ", c); }
1949 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
1950 println!();
1951
1952
1953 // Normal case for the message of 16 bytes
1954 let key = 0x_1234567890ABCDEF_u64;
1955 println!("K =\t{:#016X}", key);
1956 let mut a_des = DES::new_with_key_u64(key);
1957
1958 let message = "고맙습니다.";
1959 println!("M =\t{}", message);
1960 let message = unsafe { message.to_string().as_mut_vec().clone() };
1961 let mut cipher = Vec::<u8>::new();
1962 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1963 print!("C =\t");
1964 for c in cipher.clone()
1965 { print!("{:02X} ", c); }
1966 println!();
1967 let mut txt = String::new();
1968 for c in cipher.clone()
1969 { write!(txt, "{:02X} ", c); }
1970 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
1971 println!("-------------------------------");
1972}
1973
1974fn des_encrypt_vec_with_padding_iso_ecb_into_array()
1975{
1976 println!("des_encrypt_vec_with_padding_iso_ecb_into_array()");
1977 use std::io::Write;
1978 use std::fmt::Write as _;
1979 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
1980
1981 // Normal case
1982 let key = 0x_1234567890ABCDEF_u64;
1983 println!("K =\t{:#016X}", key);
1984 let mut a_des = DES::new_with_key_u64(key);
1985
1986 let message = "In the beginning God created the heavens and the earth.";
1987 println!("M =\t{}", message);
1988 let message = unsafe { message.to_string().as_mut_vec().clone() };
1989 let mut cipher = [0_u8; 56];
1990 a_des.encrypt_vec_into_array(&message, &mut cipher);
1991 print!("C (16 rounds) =\t");
1992 for c in cipher.clone()
1993 { print!("{:02X} ", c); }
1994 println!();
1995 let mut txt = String::new();
1996 for c in cipher.clone()
1997 { write!(txt, "{:02X} ", c); }
1998 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
1999 println!();
2000
2001 // Expanded case for 128 rounds
2002 let key = 0x_1234567890ABCDEF_u64;
2003 println!("K =\t{:#016X}", key);
2004 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2005
2006 let message = "In the beginning God created the heavens and the earth.";
2007 println!("M =\t{}", message);
2008 let message = unsafe { message.to_string().as_mut_vec().clone() };
2009 let mut cipher = [0_u8; 56];
2010 a_des.encrypt_vec_into_array(&message, &mut cipher);
2011 print!("C (128 rounds) =\t");
2012 for c in cipher.clone()
2013 { print!("{:02X} ", c); }
2014 println!();
2015 let mut txt = String::new();
2016 for c in cipher.clone()
2017 { write!(txt, "{:02X} ", c); }
2018 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2019 println!();
2020
2021 // Expanded case for 0 rounds which means that key is meaningless
2022 let key1 = 0x_1234567890ABCDEF_u64;
2023 let key2 = 0_u64;
2024 println!("K1 =\t{:#016X}", key1);
2025 println!("K2 =\t{:#016X}", key2);
2026 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2027 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2028
2029 let message = "In the beginning God created the heavens and the earth.";
2030 println!("M =\t{}", message);
2031 let message = unsafe { message.to_string().as_mut_vec().clone() };
2032 let mut cipher1 = [0_u8; 56];
2033 let mut cipher2 = [0_u8; 56];
2034 c_des.encrypt_vec_into_array(&message, &mut cipher1);
2035 d_des.encrypt_vec_into_array(&message, &mut cipher2);
2036 print!("C (0 rounds) =\t");
2037 for c in cipher1.clone()
2038 { print!("{:02X} ", c); }
2039 println!();
2040 let mut txt = String::new();
2041 for c in cipher1.clone()
2042 { write!(txt, "{:02X} ", c); }
2043 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2044 print!("D (0 rounds) =\t");
2045 for c in cipher2.clone()
2046 { print!("{:02X} ", c); }
2047 println!();
2048 let mut txt = String::new();
2049 for c in cipher2.clone()
2050 { write!(txt, "{:02X} ", c); }
2051 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2052 println!();
2053
2054 // Normal case for the message of 0 bytes
2055 let key = 0x_1234567890ABCDEF_u64;
2056 println!("K =\t{:#016X}", key);
2057 let mut a_des = DES::new_with_key_u64(key);
2058
2059 let message = "";
2060 println!("M =\t{}", message);
2061 let message = unsafe { message.to_string().as_mut_vec().clone() };
2062 let mut cipher = [0_u8; 8];
2063 a_des.encrypt_vec_into_array(&message, &mut cipher);
2064 print!("C =\t");
2065 for c in cipher.clone()
2066 { print!("{:02X} ", c); }
2067 println!();
2068 let mut txt = String::new();
2069 for c in cipher.clone()
2070 { write!(txt, "{:02X} ", c); }
2071 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2072 println!();
2073
2074 // Normal case for the message shorter than 8 bytes
2075 let key = 0x_1234567890ABCDEF_u64;
2076 println!("K =\t{:#016X}", key);
2077 let mut a_des = DES::new_with_key_u64(key);
2078
2079 let message = "7 bytes";
2080 println!("M =\t{}", message);
2081 let message = unsafe { message.to_string().as_mut_vec().clone() };
2082 let mut cipher = [0_u8; 8];
2083 a_des.encrypt_vec_into_array(&message, &mut cipher);
2084 print!("C =\t");
2085 for c in cipher.clone()
2086 { print!("{:02X} ", c); }
2087 println!();
2088 let mut txt = String::new();
2089 for c in cipher.clone()
2090 { write!(txt, "{:02X} ", c); }
2091 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2092 println!();
2093
2094 // Normal case for the message of 8 bytes
2095 let key = 0x_1234567890ABCDEF_u64;
2096 println!("K =\t{:#016X}", key);
2097 let mut a_des = DES::new_with_key_u64(key);
2098
2099 let message = "I am OK.";
2100 println!("M =\t{}", message);
2101 let message = unsafe { message.to_string().as_mut_vec().clone() };
2102 let mut cipher = [0_u8; 16];
2103 a_des.encrypt_vec_into_array(&message, &mut cipher);
2104 print!("C =\t");
2105 for c in cipher.clone()
2106 { print!("{:02X} ", c); }
2107 println!();
2108 let mut txt = String::new();
2109 for c in cipher.clone()
2110 { write!(txt, "{:02X} ", c); }
2111 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2112 println!();
2113
2114 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2115 let key = 0x_1234567890ABCDEF_u64;
2116 println!("K =\t{:#016X}", key);
2117 let mut a_des = DES::new_with_key_u64(key);
2118
2119 let message = "PARK Youngho";
2120 println!("M =\t{}", message);
2121 let message = unsafe { message.to_string().as_mut_vec().clone() };
2122 let mut cipher = [0_u8; 16];
2123 a_des.encrypt_vec_into_array(&message, &mut cipher);
2124 print!("C =\t");
2125 for c in cipher.clone()
2126 { print!("{:02X} ", c); }
2127 println!();
2128 let mut txt = String::new();
2129 for c in cipher.clone()
2130 { write!(txt, "{:02X} ", c); }
2131 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2132 println!();
2133
2134
2135 // Normal case for the message of 16 bytes
2136 let key = 0x_1234567890ABCDEF_u64;
2137 println!("K =\t{:#016X}", key);
2138 let mut a_des = DES::new_with_key_u64(key);
2139
2140 let message = "고맙습니다.";
2141 println!("M =\t{}", message);
2142 let message = unsafe { message.to_string().as_mut_vec().clone() };
2143 let mut cipher = [0_u8; 24];
2144 a_des.encrypt_vec_into_array(&message, &mut cipher);
2145 print!("C =\t");
2146 for c in cipher.clone()
2147 { print!("{:02X} ", c); }
2148 println!();
2149 let mut txt = String::new();
2150 for c in cipher.clone()
2151 { write!(txt, "{:02X} ", c); }
2152 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2153 println!("-------------------------------");
2154}
2155
2156fn des_encrypt_array_with_padding_iso_ecb()
2157{
2158 println!("des_encrypt_array_with_padding_iso_ecb()");
2159 use std::io::Write;
2160 use std::fmt::Write as _;
2161 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2162
2163 // Normal case
2164 let key = 0x_1234567890ABCDEF_u64;
2165 println!("K =\t{:#016X}", key);
2166 let mut a_des = DES::new_with_key_u64(key);
2167
2168 let mes = "In the beginning God created the heavens and the earth.";
2169 println!("M =\t{}", mes);
2170 let mut message = [0_u8; 55];
2171 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2172 let mut cipher = [0_u8; 56];
2173 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2174 print!("C (16 rounds) =\t");
2175 for c in cipher.clone()
2176 { print!("{:02X} ", c); }
2177 println!();
2178 let mut txt = String::new();
2179 for c in cipher.clone()
2180 { write!(txt, "{:02X} ", c); }
2181 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2182 println!();
2183
2184 // Expanded case for 128 rounds
2185 let key = 0x_1234567890ABCDEF_u64;
2186 println!("K =\t{:#016X}", key);
2187 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2188
2189 let mes = "In the beginning God created the heavens and the earth.";
2190 println!("M =\t{}", mes);
2191 let mut message = [0_u8; 55];
2192 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2193 let mut cipher = [0_u8; 56];
2194 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2195 print!("C (128 rounds) =\t");
2196 for c in cipher.clone()
2197 { print!("{:02X} ", c); }
2198 println!();
2199 let mut txt = String::new();
2200 for c in cipher.clone()
2201 { write!(txt, "{:02X} ", c); }
2202 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2203 println!();
2204
2205 // Expanded case for 0 rounds which means that key is meaningless
2206 let key1 = 0x_1234567890ABCDEF_u64;
2207 let key2 = 0_u64;
2208 println!("K1 =\t{:#016X}", key1);
2209 println!("K2 =\t{:#016X}", key2);
2210 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2211 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2212
2213 let mes = "In the beginning God created the heavens and the earth.";
2214 println!("M =\t{}", mes);
2215 let mut message = [0_u8; 55];
2216 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2217 let mut cipher1 = [0_u8; 56];
2218 let mut cipher2 = [0_u8; 56];
2219 c_des.encrypt_array(&message, cipher1.as_mut_ptr());
2220 d_des.encrypt_array(&message, cipher2.as_mut_ptr());
2221 print!("C (0 rounds) =\t");
2222 for c in cipher1.clone()
2223 { print!("{:02X} ", c); }
2224 println!();
2225 let mut txt = String::new();
2226 for c in cipher1.clone()
2227 { write!(txt, "{:02X} ", c); }
2228 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2229 print!("D (0 rounds) =\t");
2230 for c in cipher2.clone()
2231 { print!("{:02X} ", c); }
2232 println!();
2233 let mut txt = String::new();
2234 for c in cipher2.clone()
2235 { write!(txt, "{:02X} ", c); }
2236 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2237 println!();
2238
2239 // Normal case for the message of 0 bytes
2240 let key = 0x_1234567890ABCDEF_u64;
2241 println!("K =\t{:#016X}", key);
2242 let mut a_des = DES::new_with_key_u64(key);
2243
2244 let mes = "";
2245 println!("M =\t{}", mes);
2246 let mut message = [0_u8; 0];
2247 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2248 let mut cipher = [0_u8; 8];
2249 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2250 print!("C =\t");
2251 for c in cipher.clone()
2252 { print!("{:02X} ", c); }
2253 println!();
2254 let mut txt = String::new();
2255 for c in cipher.clone()
2256 { write!(txt, "{:02X} ", c); }
2257 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2258 println!();
2259
2260 // Normal case for the message shorter than 8 bytes
2261 let key = 0x_1234567890ABCDEF_u64;
2262 println!("K =\t{:#016X}", key);
2263 let mut a_des = DES::new_with_key_u64(key);
2264
2265 let mes = "7 bytes";
2266 println!("M =\t{}", mes);
2267 let mut message = [0_u8; 7];
2268 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2269 let mut cipher = [0_u8; 8];
2270 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2271 print!("C =\t");
2272 for c in cipher.clone()
2273 { print!("{:02X} ", c); }
2274 println!();
2275 let mut txt = String::new();
2276 for c in cipher.clone()
2277 { write!(txt, "{:02X} ", c); }
2278 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2279 println!();
2280
2281 // Normal case for the message of 8 bytes
2282 let key = 0x_1234567890ABCDEF_u64;
2283 println!("K =\t{:#016X}", key);
2284 let mut a_des = DES::new_with_key_u64(key);
2285
2286 let mes = "I am OK.";
2287 println!("M =\t{}", mes);
2288 let mut message = [0_u8; 8];
2289 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2290 let mut cipher = [0_u8; 16];
2291 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2292 print!("C =\t");
2293 for c in cipher.clone()
2294 { print!("{:02X} ", c); }
2295 println!();
2296 let mut txt = String::new();
2297 for c in cipher.clone()
2298 { write!(txt, "{:02X} ", c); }
2299 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2300 println!();
2301
2302 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2303 let key = 0x_1234567890ABCDEF_u64;
2304 println!("K =\t{:#016X}", key);
2305 let mut a_des = DES::new_with_key_u64(key);
2306
2307 let mes = "PARK Youngho";
2308 println!("M =\t{}", mes);
2309 let mut message = [0_u8; 12];
2310 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2311 let mut cipher = [0_u8; 16];
2312 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2313 print!("C =\t");
2314 for c in cipher.clone()
2315 { print!("{:02X} ", c); }
2316 println!();
2317 let mut txt = String::new();
2318 for c in cipher.clone()
2319 { write!(txt, "{:02X} ", c); }
2320 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2321 println!();
2322
2323
2324 // Normal case for the message of 16 bytes
2325 let key = 0x_1234567890ABCDEF_u64;
2326 println!("K =\t{:#016X}", key);
2327 let mut a_des = DES::new_with_key_u64(key);
2328
2329 let mes = "고맙습니다.";
2330 println!("M =\t{}", mes);
2331 let mut message = [0_u8; 16];
2332 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2333 let mut cipher = [0_u8; 24];
2334 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2335 print!("C =\t");
2336 for c in cipher.clone()
2337 { print!("{:02X} ", c); }
2338 println!();
2339 let mut txt = String::new();
2340 for c in cipher.clone()
2341 { write!(txt, "{:02X} ", c); }
2342 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2343 println!("-------------------------------");
2344}
2345
2346fn des_encrypt_array_with_padding_iso_ecb_into_vec()
2347{
2348 println!("des_encrypt_array_with_padding_iso_ecb_into_vec()");
2349 use std::io::Write;
2350 use std::fmt::Write as _;
2351 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2352
2353 // Normal case
2354 let key = 0x_1234567890ABCDEF_u64;
2355 println!("K =\t{:#016X}", key);
2356 let mut a_des = DES::new_with_key_u64(key);
2357
2358 let mes = "In the beginning God created the heavens and the earth.";
2359 println!("M =\t{}", mes);
2360 let mut message = [0_u8; 55];
2361 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2362 let mut cipher = Vec::<u8>::new();
2363 a_des.encrypt_array_into_vec(&message, &mut cipher);
2364 print!("C (16 rounds) =\t");
2365 for c in cipher.clone()
2366 { print!("{:02X} ", c); }
2367 println!();
2368 let mut txt = String::new();
2369 for c in cipher.clone()
2370 { write!(txt, "{:02X} ", c); }
2371 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2372 println!();
2373
2374 // Expanded case for 128 rounds
2375 let key = 0x_1234567890ABCDEF_u64;
2376 println!("K =\t{:#016X}", key);
2377 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2378
2379 let mes = "In the beginning God created the heavens and the earth.";
2380 println!("M =\t{}", mes);
2381 let mut message = [0_u8; 55];
2382 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2383 let mut cipher = Vec::<u8>::new();
2384 a_des.encrypt_array_into_vec(&message, &mut cipher);
2385 print!("C (128 rounds) =\t");
2386 for c in cipher.clone()
2387 { print!("{:02X} ", c); }
2388 println!();
2389 let mut txt = String::new();
2390 for c in cipher.clone()
2391 { write!(txt, "{:02X} ", c); }
2392 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2393 println!();
2394
2395 // Expanded case for 0 rounds which means that key is meaningless
2396 let key1 = 0x_1234567890ABCDEF_u64;
2397 let key2 = 0_u64;
2398 println!("K1 =\t{:#016X}", key1);
2399 println!("K2 =\t{:#016X}", key2);
2400 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2401 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2402
2403 let mes = "In the beginning God created the heavens and the earth.";
2404 println!("M =\t{}", mes);
2405 let mut message = [0_u8; 55];
2406 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2407
2408 let mut cipher1 = Vec::<u8>::new();
2409 let mut cipher2 = Vec::<u8>::new();
2410 c_des.encrypt_array_into_vec(&message, &mut cipher1);
2411 d_des.encrypt_array_into_vec(&message, &mut cipher2);
2412 print!("C (0 rounds) =\t");
2413 for c in cipher1.clone()
2414 { print!("{:02X} ", c); }
2415 println!();
2416 let mut txt = String::new();
2417 for c in cipher1.clone()
2418 { write!(txt, "{:02X} ", c); }
2419 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2420 print!("D (0 rounds) =\t");
2421 for c in cipher2.clone()
2422 { print!("{:02X} ", c); }
2423 println!();
2424 let mut txt = String::new();
2425 for c in cipher2.clone()
2426 { write!(txt, "{:02X} ", c); }
2427 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2428 println!();
2429
2430 // Normal case for the message of 0 bytes
2431 let key = 0x_1234567890ABCDEF_u64;
2432 println!("K =\t{:#016X}", key);
2433 let mut a_des = DES::new_with_key_u64(key);
2434
2435 let mes = "";
2436 println!("M =\t{}", mes);
2437 let mut message = [0_u8; 0];
2438 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2439 let mut cipher = Vec::<u8>::new();
2440 a_des.encrypt_array_into_vec(&message, &mut cipher);
2441 print!("C =\t");
2442 for c in cipher.clone()
2443 { print!("{:02X} ", c); }
2444 println!();
2445 let mut txt = String::new();
2446 for c in cipher.clone()
2447 { write!(txt, "{:02X} ", c); }
2448 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2449 println!();
2450
2451 // Normal case for the message shorter than 8 bytes
2452 let key = 0x_1234567890ABCDEF_u64;
2453 println!("K =\t{:#016X}", key);
2454 let mut a_des = DES::new_with_key_u64(key);
2455
2456 let mes = "7 bytes";
2457 println!("M =\t{}", mes);
2458 let mut message = [0_u8; 7];
2459 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460 let mut cipher = Vec::<u8>::new();
2461 a_des.encrypt_array_into_vec(&message, &mut cipher);
2462 print!("C =\t");
2463 for c in cipher.clone()
2464 { print!("{:02X} ", c); }
2465 println!();
2466 let mut txt = String::new();
2467 for c in cipher.clone()
2468 { write!(txt, "{:02X} ", c); }
2469 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2470 println!();
2471
2472 // Normal case for the message of 8 bytes
2473 let key = 0x_1234567890ABCDEF_u64;
2474 println!("K =\t{:#016X}", key);
2475 let mut a_des = DES::new_with_key_u64(key);
2476
2477 let mes = "I am OK.";
2478 println!("M =\t{}", mes);
2479 let mut message = [0_u8; 8];
2480 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2481 let mut cipher = Vec::<u8>::new();
2482 a_des.encrypt_array_into_vec(&message, &mut cipher);
2483 print!("C =\t");
2484 for c in cipher.clone()
2485 { print!("{:02X} ", c); }
2486 println!();
2487 let mut txt = String::new();
2488 for c in cipher.clone()
2489 { write!(txt, "{:02X} ", c); }
2490 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2491 println!();
2492
2493 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2494 let key = 0x_1234567890ABCDEF_u64;
2495 println!("K =\t{:#016X}", key);
2496 let mut a_des = DES::new_with_key_u64(key);
2497
2498 let mes = "PARK Youngho";
2499 println!("M =\t{}", mes);
2500 let mut message = [0_u8; 12];
2501 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2502 let mut cipher = Vec::<u8>::new();
2503 a_des.encrypt_array_into_vec(&message, &mut cipher);
2504 print!("C =\t");
2505 for c in cipher.clone()
2506 { print!("{:02X} ", c); }
2507 println!();
2508 let mut txt = String::new();
2509 for c in cipher.clone()
2510 { write!(txt, "{:02X} ", c); }
2511 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2512 println!();
2513
2514
2515 // Normal case for the message of 16 bytes
2516 let key = 0x_1234567890ABCDEF_u64;
2517 println!("K =\t{:#016X}", key);
2518 let mut a_des = DES::new_with_key_u64(key);
2519
2520 let mes = "고맙습니다.";
2521 println!("M =\t{}", mes);
2522 let mut message = [0_u8; 16];
2523 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2524 let mut cipher = Vec::<u8>::new();
2525 a_des.encrypt_array_into_vec(&message, &mut cipher);
2526 print!("C =\t");
2527 for c in cipher.clone()
2528 { print!("{:02X} ", c); }
2529 println!();
2530 let mut txt = String::new();
2531 for c in cipher.clone()
2532 { write!(txt, "{:02X} ", c); }
2533 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2534 println!("-------------------------------");
2535}
2536
2537fn des_encrypt_array_with_padding_iso_ecb_into_array()
2538{
2539 println!("des_encrypt_array_with_padding_iso_ecb_into_array()");
2540 use std::io::Write;
2541 use std::fmt::Write as _;
2542 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2543
2544 // Normal case
2545 let key = 0x_1234567890ABCDEF_u64;
2546 println!("K =\t{:#016X}", key);
2547 let mut a_des = DES::new_with_key_u64(key);
2548
2549 let mes = "In the beginning God created the heavens and the earth.";
2550 println!("M =\t{}", mes);
2551 let mut message = [0_u8; 55];
2552 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2553 let mut cipher = [0_u8; 56];
2554 a_des.encrypt_array_into_array(&message, &mut cipher);
2555 for c in cipher.clone()
2556 { print!("{:02X} ", c); }
2557 println!();
2558 let mut txt = String::new();
2559 for c in cipher.clone()
2560 { write!(txt, "{:02X} ", c); }
2561 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2562 println!();
2563
2564 // Expanded case for 128 rounds
2565 let key = 0x_1234567890ABCDEF_u64;
2566 println!("K =\t{:#016X}", key);
2567 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2568
2569 let mes = "In the beginning God created the heavens and the earth.";
2570 println!("M =\t{}", mes);
2571 let mut message = [0_u8; 55];
2572 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2573 let mut cipher = [0_u8; 56];
2574 a_des.encrypt_array_into_array(&message, &mut cipher);
2575 print!("C (128 rounds) =\t");
2576 for c in cipher.clone()
2577 { print!("{:02X} ", c); }
2578 println!();
2579 let mut txt = String::new();
2580 for c in cipher.clone()
2581 { write!(txt, "{:02X} ", c); }
2582 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2583 println!();
2584
2585 // Expanded case for 0 rounds which means that key is meaningless
2586 let key1 = 0x_1234567890ABCDEF_u64;
2587 let key2 = 0_u64;
2588 println!("K1 =\t{:#016X}", key1);
2589 println!("K2 =\t{:#016X}", key2);
2590 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2591 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2592
2593 let mes = "In the beginning God created the heavens and the earth.";
2594 println!("M =\t{}", mes);
2595 let mut message = [0_u8; 55];
2596 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2597 let mut cipher1 = [0_u8; 56];
2598 let mut cipher2 = [0_u8; 56];
2599 c_des.encrypt_array_into_array(&message, &mut cipher1);
2600 d_des.encrypt_array_into_array(&message, &mut cipher2);
2601 print!("C (0 rounds) =\t");
2602 for c in cipher1.clone()
2603 { print!("{:02X} ", c); }
2604 println!();
2605 let mut txt = String::new();
2606 for c in cipher1.clone()
2607 { write!(txt, "{:02X} ", c); }
2608 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2609 print!("D (0 rounds) =\t");
2610 for c in cipher2.clone()
2611 { print!("{:02X} ", c); }
2612 println!();
2613 let mut txt = String::new();
2614 for c in cipher2.clone()
2615 { write!(txt, "{:02X} ", c); }
2616 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2617 println!();
2618
2619 // Normal case for the message of 0 bytes
2620 let key = 0x_1234567890ABCDEF_u64;
2621 println!("K =\t{:#016X}", key);
2622 let mut a_des = DES::new_with_key_u64(key);
2623
2624 let mes = "";
2625 println!("M =\t{}", mes);
2626 let mut message = [0_u8; 0];
2627 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2628 let mut cipher = [0_u8; 8];
2629 a_des.encrypt_array_into_array(&message, &mut cipher);
2630 print!("C =\t");
2631 for c in cipher.clone()
2632 { print!("{:02X} ", c); }
2633 println!();
2634 let mut txt = String::new();
2635 for c in cipher.clone()
2636 { write!(txt, "{:02X} ", c); }
2637 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2638 println!();
2639
2640 // Normal case for the message shorter than 8 bytes
2641 let key = 0x_1234567890ABCDEF_u64;
2642 println!("K =\t{:#016X}", key);
2643 let mut a_des = DES::new_with_key_u64(key);
2644
2645 let mes = "7 bytes";
2646 println!("M =\t{}", mes);
2647 let mut message = [0_u8; 7];
2648 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2649 let mut cipher = [0_u8; 8];
2650 a_des.encrypt_array_into_array(&message, &mut cipher);
2651 print!("C =\t");
2652 for c in cipher.clone()
2653 { print!("{:02X} ", c); }
2654 println!();
2655 let mut txt = String::new();
2656 for c in cipher.clone()
2657 { write!(txt, "{:02X} ", c); }
2658 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2659 println!();
2660
2661 // Normal case for the message of 8 bytes
2662 let key = 0x_1234567890ABCDEF_u64;
2663 println!("K =\t{:#016X}", key);
2664 let mut a_des = DES::new_with_key_u64(key);
2665
2666 let mes = "I am OK.";
2667 println!("M =\t{}", mes);
2668 let mut message = [0_u8; 8];
2669 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2670 let mut cipher = [0_u8; 16];
2671 a_des.encrypt_array_into_array(&message, &mut cipher);
2672 print!("C =\t");
2673 for c in cipher.clone()
2674 { print!("{:02X} ", c); }
2675 println!();
2676 let mut txt = String::new();
2677 for c in cipher.clone()
2678 { write!(txt, "{:02X} ", c); }
2679 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2680 println!();
2681
2682 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2683 let key = 0x_1234567890ABCDEF_u64;
2684 println!("K =\t{:#016X}", key);
2685 let mut a_des = DES::new_with_key_u64(key);
2686
2687 let mes = "PARK Youngho";
2688 println!("M =\t{}", mes);
2689 let mut message = [0_u8; 12];
2690 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2691 let mut cipher = [0_u8; 16];
2692 a_des.encrypt_array_into_array(&message, &mut cipher);
2693 print!("C =\t");
2694 for c in cipher.clone()
2695 { print!("{:02X} ", c); }
2696 println!();
2697 let mut txt = String::new();
2698 for c in cipher.clone()
2699 { write!(txt, "{:02X} ", c); }
2700 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
2701 println!();
2702
2703
2704 // Normal case for the message of 16 bytes
2705 let key = 0x_1234567890ABCDEF_u64;
2706 println!("K =\t{:#016X}", key);
2707 let mut a_des = DES::new_with_key_u64(key);
2708
2709 let mes = "고맙습니다.";
2710 println!("M =\t{}", mes);
2711 let mut message = [0_u8; 16];
2712 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2713 let mut cipher = [0_u8; 24];
2714 a_des.encrypt_array_into_array(&message, &mut cipher);
2715 print!("C =\t");
2716 for c in cipher.clone()
2717 { print!("{:02X} ", c); }
2718 println!();
2719 let mut txt = String::new();
2720 for c in cipher.clone()
2721 { write!(txt, "{:02X} ", c); }
2722 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
2723 println!("-------------------------------");
2724}
2725
2726fn des_decrypt_with_padding_iso_ecb()
2727{
2728 println!("des_decrypt_with_padding_iso_ecb()");
2729 use std::io::Write;
2730 use std::fmt::Write as _;
2731 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
2732
2733 // Normal case
2734 let key = 0x_1234567890ABCDEF_u64;
2735 println!("K =\t{:#016X}", key);
2736 let mut a_des = DES::new_with_key_u64(key);
2737
2738 let message = "In the beginning God created the heavens and the earth.";
2739 println!("M =\t{}", message);
2740 let mut cipher = Vec::<u8>::new();
2741 a_des.encrypt_str_into_vec(&message, &mut cipher);
2742 print!("C (16 rounds) =\t");
2743 for c in cipher.clone()
2744 { print!("{:02X} ", c); }
2745 println!();
2746 let mut txt = String::new();
2747 for c in cipher.clone()
2748 { write!(txt, "{:02X} ", c); }
2749 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
2750
2751 let mut recovered = vec![0; 55];
2752 a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2753 print!("Ba (16 rounds) =\t");
2754 for b in recovered.clone()
2755 { print!("{:02X} ", b); }
2756 println!();
2757 let mut txt = String::new();
2758 for c in recovered.clone()
2759 { write!(txt, "{:02X} ", c); }
2760 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2761
2762 let mut converted = String::new();
2763 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2764
2765 println!("Bb (16 rounds) =\t{}", converted);
2766 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2767 assert_eq!(converted, message);
2768 println!();
2769
2770 // Expanded case for 128 rounds
2771 let key = 0x_1234567890ABCDEF_u64;
2772 println!("K =\t{:#016X}", key);
2773 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2774
2775 let message = "In the beginning God created the heavens and the earth.";
2776 println!("M =\t{}", message);
2777 let mut cipher = Vec::<u8>::new();
2778 a_des.encrypt_str_into_vec(&message, &mut cipher);
2779 print!("C (128 rounds) =\t");
2780 for c in cipher.clone()
2781 { print!("{:02X} ", c); }
2782 println!();
2783 let mut txt = String::new();
2784 for c in cipher.clone()
2785 { write!(txt, "{:02X} ", c); }
2786 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
2787
2788 let mut recovered = vec![0; 55];
2789 a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2790 print!("Ba (128 rounds) =\t");
2791 for b in recovered.clone()
2792 { print!("{:02X} ", b); }
2793 println!();
2794 let mut txt = String::new();
2795 for c in recovered.clone()
2796 { write!(txt, "{:02X} ", c); }
2797 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2798
2799 let mut converted = String::new();
2800 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2801
2802 println!("Bb (128 rounds) =\t{}", converted);
2803 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2804 assert_eq!(converted, message);
2805 println!();
2806
2807 // Expanded case for 0 rounds which means that key is meaningless
2808 let key1 = 0x_1234567890ABCDEF_u64;
2809 let key2 = 0_u64;
2810 println!("K =\t{:#016X}", key);
2811 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2812 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2813
2814 let message = "In the beginning God created the heavens and the earth.";
2815 println!("M =\t{}", message);
2816 let mut cipher1 = Vec::<u8>::new();
2817 let mut cipher2 = Vec::<u8>::new();
2818 c_des.encrypt_str_into_vec(&message, &mut cipher1);
2819 d_des.encrypt_str_into_vec(&message, &mut cipher2);
2820 print!("C (0 rounds) =\t");
2821 for c in cipher1.clone()
2822 { print!("{:02X} ", c); }
2823 println!();
2824 let mut txt = String::new();
2825 for c in cipher1.clone()
2826 { write!(txt, "{:02X} ", c); }
2827 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2828 print!("D (0 rounds) =\t");
2829 for c in cipher2.clone()
2830 { print!("{:02X} ", c); }
2831 println!();
2832 let mut txt = String::new();
2833 for c in cipher2.clone()
2834 { write!(txt, "{:02X} ", c); }
2835 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
2836
2837 let mut recovered1 = vec![0; 55];
2838 let mut recovered2 = vec![0; 55];
2839 c_des.decrypt(cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
2840 d_des.decrypt(cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
2841 print!("B1a (0 rounds) =\t");
2842 for b in recovered1.clone()
2843 { print!("{:02X} ", b); }
2844 println!();
2845 let mut txt = String::new();
2846 for c in recovered1.clone()
2847 { write!(txt, "{:02X} ", c); }
2848 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2849 print!("B2a (0 rounds) =\t");
2850 for b in recovered2.clone()
2851 { print!("{:02X} ", b); }
2852 println!();
2853 let mut txt = String::new();
2854 for c in recovered2.clone()
2855 { write!(txt, "{:02X} ", c); }
2856 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2857
2858 let mut converted1 = String::new();
2859 let mut converted2 = String::new();
2860 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
2861 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
2862
2863 println!("B1b (0 rounds) =\t{}", converted1);
2864 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
2865 assert_eq!(converted1, message);
2866 println!("B2b (0 rounds) =\t{}", converted2);
2867 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
2868 assert_eq!(converted2, message);
2869 assert_eq!(converted1, converted1);
2870 println!();
2871
2872 // Normal case for the message of 0 bytes
2873 let key = 0x_1234567890ABCDEF_u64;
2874 println!("K =\t{:#016X}", key);
2875 let mut a_des = DES::new_with_key_u64(key);
2876
2877 let message = "";
2878 println!("M =\t{}", message);
2879 let mut cipher = Vec::<u8>::new();
2880 a_des.encrypt_str_into_vec(&message, &mut cipher);
2881 print!("C =\t");
2882 for c in cipher.clone()
2883 { print!("{:02X} ", c); }
2884 println!();
2885 let mut txt = String::new();
2886 for c in cipher.clone()
2887 { write!(txt, "{:02X} ", c); }
2888 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
2889
2890 let mut recovered = vec![0; 8];
2891 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2892 print!("Ba =\t");
2893 for b in recovered.clone()
2894 { print!("{:02X} ", b); }
2895 println!();
2896 let mut txt = String::new();
2897 for c in recovered.clone()
2898 { write!(txt, "{:02X} ", c); }
2899 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2900
2901 let mut converted = String::new();
2902 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2903 converted.truncate(len as usize);
2904
2905 println!("Bb =\t{}", converted);
2906 assert_eq!(converted, "");
2907 assert_eq!(converted, message);
2908 println!();
2909
2910 // Normal case for the message shorter than 8 bytes
2911 let key = 0x_1234567890ABCDEF_u64;
2912 println!("K =\t{:#016X}", key);
2913 let mut a_des = DES::new_with_key_u64(key);
2914
2915 let message = "7 bytes";
2916 println!("M =\t{}", message);
2917 let mut cipher = Vec::<u8>::new();
2918 a_des.encrypt_str_into_vec(&message, &mut cipher);
2919 print!("C =\t");
2920 for c in cipher.clone()
2921 { print!("{:02X} ", c); }
2922 println!();
2923 let mut txt = String::new();
2924 for c in cipher.clone()
2925 { write!(txt, "{:02X} ", c); }
2926 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
2927
2928 let mut recovered = vec![0; 8];
2929 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2930 print!("Ba =\t");
2931 for b in recovered.clone()
2932 { print!("{:02X} ", b); }
2933 println!();
2934 let mut txt = String::new();
2935 for c in recovered.clone()
2936 { write!(txt, "{:02X} ", c); }
2937 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
2938
2939 let mut converted = String::new();
2940 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2941 converted.truncate(len as usize);
2942
2943 println!("Bb =\t{}", converted);
2944 assert_eq!(converted, "7 bytes");
2945 assert_eq!(converted, message);
2946 println!();
2947
2948 // Normal case for the message of 8 bytes
2949 let key = 0x_1234567890ABCDEF_u64;
2950 println!("K =\t{:#016X}", key);
2951 let mut a_des = DES::new_with_key_u64(key);
2952
2953 let message = "I am OK.";
2954 println!("M =\t{}", message);
2955 let mut cipher = Vec::<u8>::new();
2956 a_des.encrypt_str_into_vec(&message, &mut cipher);
2957 print!("C =\t");
2958 for c in cipher.clone()
2959 { print!("{:02X} ", c); }
2960 println!();
2961 let mut txt = String::new();
2962 for c in cipher.clone()
2963 { write!(txt, "{:02X} ", c); }
2964 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
2965
2966 let mut recovered = vec![0; 16];
2967 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2968 print!("Ba =\t");
2969 for b in recovered.clone()
2970 { print!("{:02X} ", b); }
2971 println!();
2972 let mut txt = String::new();
2973 for c in recovered.clone()
2974 { write!(txt, "{:02X} ", c); }
2975 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
2976
2977 let mut converted = String::new();
2978 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2979 converted.truncate(len as usize);
2980
2981 println!("Bb =\t{}", converted);
2982 assert_eq!(converted, "I am OK.");
2983 assert_eq!(converted, message);
2984 println!();
2985
2986 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2987 let key = 0x_1234567890ABCDEF_u64;
2988 println!("K =\t{:#016X}", key);
2989 let mut a_des = DES::new_with_key_u64(key);
2990
2991 let message = "PARK Youngho";
2992 println!("M =\t{}", message);
2993 let mut cipher = Vec::<u8>::new();
2994 a_des.encrypt_str_into_vec(&message, &mut cipher);
2995 print!("C =\t");
2996 for c in cipher.clone()
2997 { print!("{:02X} ", c); }
2998 println!();
2999 let mut txt = String::new();
3000 for c in cipher.clone()
3001 { write!(txt, "{:02X} ", c); }
3002 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3003
3004 let mut recovered = vec![0; 16];
3005 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3006 print!("Ba =\t");
3007 for b in recovered.clone()
3008 { print!("{:02X} ", b); }
3009 println!();
3010 let mut txt = String::new();
3011 for c in recovered.clone()
3012 { write!(txt, "{:02X} ", c); }
3013 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3014
3015 let mut converted = String::new();
3016 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3017 converted.truncate(len as usize);
3018
3019 println!("Bb =\t{}", converted);
3020 assert_eq!(converted, "PARK Youngho");
3021 assert_eq!(converted, message);
3022 println!();
3023
3024
3025 // Normal case for the message of 16 bytes
3026 let key = 0x_1234567890ABCDEF_u64;
3027 println!("K =\t{:#016X}", key);
3028 let mut a_des = DES::new_with_key_u64(key);
3029
3030 let message = "고맙습니다.";
3031 println!("M =\t{}", message);
3032 let mut cipher = Vec::<u8>::new();
3033 a_des.encrypt_str_into_vec(&message, &mut cipher);
3034 print!("C =\t");
3035 for c in cipher.clone()
3036 { print!("{:02X} ", c); }
3037 println!();
3038 let mut txt = String::new();
3039 for c in cipher.clone()
3040 { write!(txt, "{:02X} ", c); }
3041 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3042
3043 let mut recovered = vec![0; 24];
3044 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3045 print!("Ba =\t");
3046 for b in recovered.clone()
3047 { print!("{:02X} ", b); }
3048 println!();
3049 let mut txt = String::new();
3050 for c in recovered.clone()
3051 { write!(txt, "{:02X} ", c); }
3052 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3053
3054 let mut converted = String::new();
3055 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3056 converted.truncate(len as usize);
3057
3058 println!("Bb =\t{}", converted);
3059 assert_eq!(converted, "고맙습니다.");
3060 assert_eq!(converted, message);
3061 println!("-------------------------------");
3062}
3063
3064fn des_decrypt_with_padding_iso_ecb_into_vec()
3065{
3066 println!("des_decrypt_with_padding_iso_ecb_into_vec()");
3067 use std::io::Write;
3068 use std::fmt::Write as _;
3069 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3070
3071 // Normal case
3072 let key = 0x_1234567890ABCDEF_u64;
3073 println!("K =\t{:#016X}", key);
3074 let mut a_des = DES::new_with_key_u64(key);
3075
3076 let message = "In the beginning God created the heavens and the earth.";
3077 println!("M =\t{}", message);
3078 let mut cipher = Vec::<u8>::new();
3079 a_des.encrypt_str_into_vec(&message, &mut cipher);
3080 print!("C (16 rounds) =\t");
3081 for c in cipher.clone()
3082 { print!("{:02X} ", c); }
3083 println!();
3084 let mut txt = String::new();
3085 for c in cipher.clone()
3086 { write!(txt, "{:02X} ", c); }
3087 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3088
3089 let mut recovered = Vec::<u8>::new();
3090 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3091 print!("Ba (16 rounds) =\t");
3092 for b in recovered.clone()
3093 { print!("{:02X} ", b); }
3094 println!();
3095 let mut txt = String::new();
3096 for c in recovered.clone()
3097 { write!(txt, "{:02X} ", c); }
3098 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3099
3100 let mut converted = String::new();
3101 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3102
3103 println!("Bb (16 rounds) =\t{}", converted);
3104 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3105 assert_eq!(converted, message);
3106 println!();
3107
3108 // Expanded case for 128 rounds
3109 let key = 0x_1234567890ABCDEF_u64;
3110 println!("K =\t{:#016X}", key);
3111 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3112
3113 let message = "In the beginning God created the heavens and the earth.";
3114 println!("M =\t{}", message);
3115 let mut cipher = Vec::<u8>::new();
3116 a_des.encrypt_str_into_vec(&message, &mut cipher);
3117 print!("C (128 rounds) =\t");
3118 for c in cipher.clone()
3119 { print!("{:02X} ", c); }
3120 println!();
3121 let mut txt = String::new();
3122 for c in cipher.clone()
3123 { write!(txt, "{:02X} ", c); }
3124 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3125
3126 let mut recovered = Vec::<u8>::new();
3127 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3128 print!("Ba (128 rounds) =\t");
3129 for b in recovered.clone()
3130 { print!("{:02X} ", b); }
3131 println!();
3132 let mut txt = String::new();
3133 for c in recovered.clone()
3134 { write!(txt, "{:02X} ", c); }
3135 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3136
3137 let mut converted = String::new();
3138 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139
3140 println!("Bb (128 rounds) =\t{}", converted);
3141 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3142 assert_eq!(converted, message);
3143 println!();
3144
3145 // Expanded case for 0 rounds which means that key is meaningless
3146 let key1 = 0x_1234567890ABCDEF_u64;
3147 let key2 = 0_u64;
3148 println!("K =\t{:#016X}", key);
3149 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3150 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3151
3152 let message = "In the beginning God created the heavens and the earth.";
3153 println!("M =\t{}", message);
3154 let mut cipher1 = Vec::<u8>::new();
3155 let mut cipher2 = Vec::<u8>::new();
3156 c_des.encrypt_str_into_vec(&message, &mut cipher1);
3157 d_des.encrypt_str_into_vec(&message, &mut cipher2);
3158 print!("C (0 rounds) =\t");
3159 for c in cipher1.clone()
3160 { print!("{:02X} ", c); }
3161 println!();
3162 let mut txt = String::new();
3163 for c in cipher1.clone()
3164 { write!(txt, "{:02X} ", c); }
3165 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3166 print!("D (0 rounds) =\t");
3167 for c in cipher2.clone()
3168 { print!("{:02X} ", c); }
3169 println!();
3170 let mut txt = String::new();
3171 for c in cipher2.clone()
3172 { write!(txt, "{:02X} ", c); }
3173 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3174
3175 let mut recovered1 = Vec::<u8>::new();
3176 let mut recovered2 = Vec::<u8>::new();
3177 c_des.decrypt_into_vec(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3178 d_des.decrypt_into_vec(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3179 print!("B1a (0 rounds) =\t");
3180 for b in recovered1.clone()
3181 { print!("{:02X} ", b); }
3182 println!();
3183 let mut txt = String::new();
3184 for c in recovered1.clone()
3185 { write!(txt, "{:02X} ", c); }
3186 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3187 print!("B2a (0 rounds) =\t");
3188 for b in recovered2.clone()
3189 { print!("{:02X} ", b); }
3190 println!();
3191 let mut txt = String::new();
3192 for c in recovered2.clone()
3193 { write!(txt, "{:02X} ", c); }
3194 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3195
3196 let mut converted1 = String::new();
3197 let mut converted2 = String::new();
3198 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3199 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3200
3201 println!("B1b (0 rounds) =\t{}", converted1);
3202 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3203 assert_eq!(converted1, message);
3204 println!("B2b (0 rounds) =\t{}", converted2);
3205 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3206 assert_eq!(converted2, message);
3207 assert_eq!(converted1, converted1);
3208 println!();
3209
3210 // Normal case for the message of 0 bytes
3211 let key = 0x_1234567890ABCDEF_u64;
3212 println!("K =\t{:#016X}", key);
3213 let mut a_des = DES::new_with_key_u64(key);
3214
3215 let message = "";
3216 println!("M =\t{}", message);
3217 let mut cipher = Vec::<u8>::new();
3218 a_des.encrypt_str_into_vec(&message, &mut cipher);
3219 print!("C =\t");
3220 for c in cipher.clone()
3221 { print!("{:02X} ", c); }
3222 println!();
3223 let mut txt = String::new();
3224 for c in cipher.clone()
3225 { write!(txt, "{:02X} ", c); }
3226 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3227
3228 let mut recovered = Vec::<u8>::new();
3229 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3230 print!("Ba =\t");
3231 for b in recovered.clone()
3232 { print!("{:02X} ", b); }
3233 println!();
3234 let mut txt = String::new();
3235 for c in recovered.clone()
3236 { write!(txt, "{:02X} ", c); }
3237 assert_eq!(txt, "");
3238
3239 let mut converted = String::new();
3240 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3241
3242 println!("Bb =\t{}", converted);
3243 assert_eq!(converted, "");
3244 assert_eq!(converted, message);
3245 println!();
3246
3247 // Normal case for the message shorter than 8 bytes
3248 let key = 0x_1234567890ABCDEF_u64;
3249 println!("K =\t{:#016X}", key);
3250 let mut a_des = DES::new_with_key_u64(key);
3251
3252 let message = "7 bytes";
3253 println!("M =\t{}", message);
3254 let mut cipher = Vec::<u8>::new();
3255 a_des.encrypt_str_into_vec(&message, &mut cipher);
3256 print!("C =\t");
3257 for c in cipher.clone()
3258 { print!("{:02X} ", c); }
3259 println!();
3260 let mut txt = String::new();
3261 for c in cipher.clone()
3262 { write!(txt, "{:02X} ", c); }
3263 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3264
3265 let mut recovered = Vec::<u8>::new();
3266 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3267 print!("Ba =\t");
3268 for b in recovered.clone()
3269 { print!("{:02X} ", b); }
3270 println!();
3271 let mut txt = String::new();
3272 for c in recovered.clone()
3273 { write!(txt, "{:02X} ", c); }
3274 assert_eq!(txt, "37 20 62 79 74 65 73 ");
3275
3276 let mut converted = String::new();
3277 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3278
3279 println!("Bb =\t{}", converted);
3280 assert_eq!(converted, "7 bytes");
3281 assert_eq!(converted, message);
3282 println!();
3283
3284 // Normal case for the message of 8 bytes
3285 let key = 0x_1234567890ABCDEF_u64;
3286 println!("K =\t{:#016X}", key);
3287 let mut a_des = DES::new_with_key_u64(key);
3288
3289 let message = "I am OK.";
3290 println!("M =\t{}", message);
3291 let mut cipher = Vec::<u8>::new();
3292 a_des.encrypt_str_into_vec(&message, &mut cipher);
3293 print!("C =\t");
3294 for c in cipher.clone()
3295 { print!("{:02X} ", c); }
3296 println!();
3297 let mut txt = String::new();
3298 for c in cipher.clone()
3299 { write!(txt, "{:02X} ", c); }
3300 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3301
3302 let mut recovered = Vec::<u8>::new();
3303 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3304 print!("Ba =\t");
3305 for b in recovered.clone()
3306 { print!("{:02X} ", b); }
3307 println!();
3308 let mut txt = String::new();
3309 for c in recovered.clone()
3310 { write!(txt, "{:02X} ", c); }
3311 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3312
3313 let mut converted = String::new();
3314 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3315
3316 println!("Bb =\t{}", converted);
3317 assert_eq!(converted, "I am OK.");
3318 assert_eq!(converted, message);
3319 println!();
3320
3321 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3322 let key = 0x_1234567890ABCDEF_u64;
3323 println!("K =\t{:#016X}", key);
3324 let mut a_des = DES::new_with_key_u64(key);
3325
3326 let message = "PARK Youngho";
3327 println!("M =\t{}", message);
3328 let mut cipher = Vec::<u8>::new();
3329 a_des.encrypt_str_into_vec(&message, &mut cipher);
3330 print!("C =\t");
3331 for c in cipher.clone()
3332 { print!("{:02X} ", c); }
3333 println!();
3334 let mut txt = String::new();
3335 for c in cipher.clone()
3336 { write!(txt, "{:02X} ", c); }
3337 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3338
3339 let mut recovered = Vec::<u8>::new();
3340 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3341 print!("Ba =\t");
3342 for b in recovered.clone()
3343 { print!("{:02X} ", b); }
3344 println!();
3345 let mut txt = String::new();
3346 for c in recovered.clone()
3347 { write!(txt, "{:02X} ", c); }
3348 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3349
3350 let mut converted = String::new();
3351 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3352
3353 println!("Bb =\t{}", converted);
3354 assert_eq!(converted, "PARK Youngho");
3355 assert_eq!(converted, message);
3356 println!();
3357
3358 // Normal case for the message of 16 bytes
3359 let key = 0x_1234567890ABCDEF_u64;
3360 println!("K =\t{:#016X}", key);
3361 let mut a_des = DES::new_with_key_u64(key);
3362
3363 let message = "고맙습니다.";
3364 println!("M =\t{}", message);
3365 let mut cipher = Vec::<u8>::new();
3366 a_des.encrypt_str_into_vec(&message, &mut cipher);
3367 print!("C =\t");
3368 for c in cipher.clone()
3369 { print!("{:02X} ", c); }
3370 println!();
3371 let mut txt = String::new();
3372 for c in cipher.clone()
3373 { write!(txt, "{:02X} ", c); }
3374 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3375
3376 let mut recovered = Vec::<u8>::new();
3377 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3378 print!("Ba =\t");
3379 for b in recovered.clone()
3380 { print!("{:02X} ", b); }
3381 println!();
3382 let mut txt = String::new();
3383 for c in recovered.clone()
3384 { write!(txt, "{:02X} ", c); }
3385 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3386
3387 let mut converted = String::new();
3388 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3389
3390 println!("Bb =\t{}", converted);
3391 assert_eq!(converted, "고맙습니다.");
3392 assert_eq!(converted, message);
3393 println!("-------------------------------");
3394}
3395
3396fn des_decrypt_with_padding_iso_ecb_into_array()
3397{
3398 println!("des_decrypt_with_padding_iso_ecb_into_array()");
3399 use std::io::Write;
3400 use std::fmt::Write as _;
3401 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3402
3403 // Normal case
3404 let key = 0x_1234567890ABCDEF_u64;
3405 println!("K =\t{:#016X}", key);
3406 let mut a_des = DES::new_with_key_u64(key);
3407
3408 let message = "In the beginning God created the heavens and the earth.";
3409 println!("M =\t{}", message);
3410 let mut cipher = Vec::<u8>::new();
3411 a_des.encrypt_str_into_vec(&message, &mut cipher);
3412 print!("C (16 rounds) =\t");
3413 for c in cipher.clone()
3414 { print!("{:02X} ", c); }
3415 println!();
3416 let mut txt = String::new();
3417 for c in cipher.clone()
3418 { write!(txt, "{:02X} ", c); }
3419 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3420
3421 let mut recovered = [0u8; 56];
3422 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3423 print!("Ba (16 rounds) =\t");
3424 for b in recovered.clone()
3425 { print!("{:02X} ", b); }
3426 println!();
3427 let mut txt = String::new();
3428 for c in recovered.clone()
3429 { write!(txt, "{:02X} ", c); }
3430 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3431
3432 let mut converted = String::new();
3433 unsafe { converted.as_mut_vec() }.write(&recovered);
3434 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3435 println!("Bb (16 rounds) =\t{}", converted);
3436 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3437 assert_eq!(converted, message);
3438 println!();
3439
3440 // Expanded case for 128 rounds
3441 let key = 0x_1234567890ABCDEF_u64;
3442 println!("K =\t{:#016X}", key);
3443 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3444
3445 let message = "In the beginning God created the heavens and the earth.";
3446 println!("M =\t{}", message);
3447 let mut cipher = Vec::<u8>::new();
3448 a_des.encrypt_str_into_vec(&message, &mut cipher);
3449 print!("C (128 rounds) =\t");
3450 for c in cipher.clone()
3451 { print!("{:02X} ", c); }
3452 println!();
3453 let mut txt = String::new();
3454 for c in cipher.clone()
3455 { write!(txt, "{:02X} ", c); }
3456 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3457
3458 let mut recovered = [0u8; 56];
3459 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3460 print!("Ba (16 rounds) =\t");
3461 for b in recovered.clone()
3462 { print!("{:02X} ", b); }
3463 println!();
3464 let mut txt = String::new();
3465 for c in recovered.clone()
3466 { write!(txt, "{:02X} ", c); }
3467 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3468
3469 let mut converted = String::new();
3470 unsafe { converted.as_mut_vec() }.write(&recovered);
3471 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3472 println!("Bb (16 rounds) =\t{}", converted);
3473 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3474 assert_eq!(converted, message);
3475 println!();
3476
3477 // Expanded case for 0 rounds which means that key is meaningless
3478 let key1 = 0x_1234567890ABCDEF_u64;
3479 let key2 = 0_u64;
3480 println!("K =\t{:#016X}", key);
3481 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3482 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3483
3484 let message = "In the beginning God created the heavens and the earth.";
3485 println!("M =\t{}", message);
3486 let mut cipher1 = Vec::<u8>::new();
3487 let mut cipher2 = Vec::<u8>::new();
3488 c_des.encrypt_str_into_vec(&message, &mut cipher1);
3489 d_des.encrypt_str_into_vec(&message, &mut cipher2);
3490 print!("C (0 rounds) =\t");
3491 for c in cipher1.clone()
3492 { print!("{:02X} ", c); }
3493 println!();
3494 let mut txt = String::new();
3495 for c in cipher1.clone()
3496 { write!(txt, "{:02X} ", c); }
3497 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3498 print!("D (0 rounds) =\t");
3499 for c in cipher2.clone()
3500 { print!("{:02X} ", c); }
3501 println!();
3502 let mut txt = String::new();
3503 for c in cipher2.clone()
3504 { write!(txt, "{:02X} ", c); }
3505 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3506
3507 let mut recovered1 = [0u8; 56];
3508 let mut recovered2 = [0u8; 56];
3509 let len1 = c_des.decrypt_into_array(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3510 let len2 = d_des.decrypt_into_array(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3511 print!("B1a (0 rounds) =\t");
3512 for b in recovered1.clone()
3513 { print!("{:02X} ", b); }
3514 println!();
3515 let mut txt = String::new();
3516 for c in recovered1.clone()
3517 { write!(txt, "{:02X} ", c); }
3518 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3519 print!("B2a (0 rounds) =\t");
3520 for b in recovered2.clone()
3521 { print!("{:02X} ", b); }
3522 println!();
3523 let mut txt = String::new();
3524 for c in recovered.clone()
3525 { write!(txt, "{:02X} ", c); }
3526 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3527
3528 let mut converted1 = String::new();
3529 let mut converted2 = String::new();
3530 unsafe { converted1.as_mut_vec() }.write(&recovered1);
3531 unsafe { converted2.as_mut_vec() }.write(&recovered2);
3532 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3533 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3534 println!("B1b (0 rounds) =\t{}", converted1);
3535 println!("B2b (0 rounds) =\t{}", converted2);
3536 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3537 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3538 assert_eq!(converted1, message);
3539 assert_eq!(converted2, message);
3540 assert_eq!(converted1, converted2);
3541 println!();
3542
3543 // Normal case for the message of 0 bytes
3544 let key = 0x_1234567890ABCDEF_u64;
3545 println!("K =\t{:#016X}", key);
3546 let mut a_des = DES::new_with_key_u64(key);
3547
3548 let message = "";
3549 println!("M =\t{}", message);
3550 let mut cipher = Vec::<u8>::new();
3551 a_des.encrypt_str_into_vec(&message, &mut cipher);
3552 print!("C =\t");
3553 for c in cipher.clone()
3554 { print!("{:02X} ", c); }
3555 println!();
3556 let mut txt = String::new();
3557 for c in cipher.clone()
3558 { write!(txt, "{:02X} ", c); }
3559 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3560
3561 let mut recovered = [0u8; 8];
3562 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3563
3564 print!("Ba =\t");
3565 for b in recovered.clone()
3566 { print!("{:02X} ", b); }
3567 println!();
3568 let mut txt = String::new();
3569 for c in recovered.clone()
3570 { write!(txt, "{:02X} ", c); }
3571 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3572
3573 let mut converted = String::new();
3574 unsafe { converted.as_mut_vec() }.write(&recovered);
3575 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3576 println!("Bb =\t{}", converted);
3577 assert_eq!(converted, "");
3578 assert_eq!(converted, message);
3579 println!();
3580
3581 // Normal case for the message shorter than 8 bytes
3582 let key = 0x_1234567890ABCDEF_u64;
3583 println!("K =\t{:#016X}", key);
3584 let mut a_des = DES::new_with_key_u64(key);
3585
3586 let message = "7 bytes";
3587 println!("M =\t{}", message);
3588 let mut cipher = Vec::<u8>::new();
3589 a_des.encrypt_str_into_vec(&message, &mut cipher);
3590 print!("C =\t");
3591 for c in cipher.clone()
3592 { print!("{:02X} ", c); }
3593 println!();
3594 let mut txt = String::new();
3595 for c in cipher.clone()
3596 { write!(txt, "{:02X} ", c); }
3597 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3598
3599 let mut recovered = [0u8; 8];
3600 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3601
3602 print!("Ba =\t");
3603 for b in recovered.clone()
3604 { print!("{:02X} ", b); }
3605 println!();
3606 let mut txt = String::new();
3607 for c in recovered.clone()
3608 { write!(txt, "{:02X} ", c); }
3609 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3610
3611 let mut converted = String::new();
3612 unsafe { converted.as_mut_vec() }.write(&recovered);
3613 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3614 println!("Bb =\t{}", converted);
3615 assert_eq!(converted, "7 bytes");
3616 assert_eq!(converted, message);
3617 println!();
3618
3619 // Normal case for the message of 8 bytes
3620 let key = 0x_1234567890ABCDEF_u64;
3621 println!("K =\t{:#016X}", key);
3622 let mut a_des = DES::new_with_key_u64(key);
3623
3624 let message = "I am OK.";
3625 println!("M =\t{}", message);
3626 let mut cipher = Vec::<u8>::new();
3627 a_des.encrypt_str_into_vec(&message, &mut cipher);
3628 print!("C =\t");
3629 for c in cipher.clone()
3630 { print!("{:02X} ", c); }
3631 println!();
3632 let mut txt = String::new();
3633 for c in cipher.clone()
3634 { write!(txt, "{:02X} ", c); }
3635 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3636
3637 let mut recovered = [0u8; 16];
3638 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3639
3640 print!("Ba =\t");
3641 for b in recovered.clone()
3642 { print!("{:02X} ", b); }
3643 println!();
3644 let mut txt = String::new();
3645 for c in recovered.clone()
3646 { write!(txt, "{:02X} ", c); }
3647 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3648
3649 let mut converted = String::new();
3650 unsafe { converted.as_mut_vec() }.write(&recovered);
3651 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3652 println!("Bb =\t{}", converted);
3653 assert_eq!(converted, "I am OK.");
3654 assert_eq!(converted, message);
3655 println!();
3656
3657 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3658 let key = 0x_1234567890ABCDEF_u64;
3659 println!("K =\t{:#016X}", key);
3660 let mut a_des = DES::new_with_key_u64(key);
3661
3662 let message = "PARK Youngho";
3663 println!("M =\t{}", message);
3664 let mut cipher = Vec::<u8>::new();
3665 a_des.encrypt_str_into_vec(&message, &mut cipher);
3666 print!("C =\t");
3667 for c in cipher.clone()
3668 { print!("{:02X} ", c); }
3669 println!();
3670 let mut txt = String::new();
3671 for c in cipher.clone()
3672 { write!(txt, "{:02X} ", c); }
3673 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3674
3675 let mut recovered = [0u8; 16];
3676 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3677
3678 print!("Ba =\t");
3679 for b in recovered.clone()
3680 { print!("{:02X} ", b); }
3681 println!();
3682 let mut txt = String::new();
3683 for c in recovered.clone()
3684 { write!(txt, "{:02X} ", c); }
3685 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3686
3687 let mut converted = String::new();
3688 unsafe { converted.as_mut_vec() }.write(&recovered);
3689 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3690 println!("Bb =\t{}", converted);
3691 assert_eq!(converted, "PARK Youngho");
3692 assert_eq!(converted, message);
3693 println!();
3694
3695 // Normal case for the message of 16 bytes
3696 let key = 0x_1234567890ABCDEF_u64;
3697 println!("K =\t{:#016X}", key);
3698 let mut a_des = DES::new_with_key_u64(key);
3699
3700 let message = "고맙습니다.";
3701 println!("M =\t{}", message);
3702 let mut cipher = Vec::<u8>::new();
3703 a_des.encrypt_str_into_vec(&message, &mut cipher);
3704 print!("C =\t");
3705 for c in cipher.clone()
3706 { print!("{:02X} ", c); }
3707 println!();
3708 let mut txt = String::new();
3709 for c in cipher.clone()
3710 { write!(txt, "{:02X} ", c); }
3711 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3712
3713 let mut recovered = [0u8; 24];
3714 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3715
3716 print!("Ba =\t");
3717 for b in recovered.clone()
3718 { print!("{:02X} ", b); }
3719 println!();
3720 let mut txt = String::new();
3721 for c in recovered.clone()
3722 { write!(txt, "{:02X} ", c); }
3723 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3724
3725 let mut converted = String::new();
3726 unsafe { converted.as_mut_vec() }.write(&recovered);
3727 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3728 println!("Bb =\t{}", converted);
3729 assert_eq!(converted, "고맙습니다.");
3730 assert_eq!(converted, message);
3731 println!("-------------------------------");
3732}
3733
3734fn des_decrypt_with_padding_iso_ecb_into_string()
3735{
3736 println!("des_decrypt_with_padding_iso_ecb_into_string()");
3737 use std::io::Write;
3738 use std::fmt::Write as _;
3739 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3740
3741 // Normal case
3742 let key = 0x_1234567890ABCDEF_u64;
3743 println!("K =\t{:#016X}", key);
3744 let mut a_des = DES::new_with_key_u64(key);
3745
3746 let message = "In the beginning God created the heavens and the earth.";
3747 println!("M =\t{}", message);
3748 let mut cipher = Vec::<u8>::new();
3749 a_des.encrypt_str_into_vec(&message, &mut cipher);
3750 print!("C (16 rounds) =\t");
3751 for c in cipher.clone()
3752 { print!("{:02X} ", c); }
3753 println!();
3754 let mut txt = String::new();
3755 for c in cipher.clone()
3756 { write!(txt, "{:02X} ", c); }
3757 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3758
3759 let mut recovered = String::new();
3760 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3761 println!("B (16 rounds) =\t{}", recovered);
3762 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3763 assert_eq!(recovered, message);
3764 println!();
3765
3766 // Expanded case for 128 rounds
3767 let key = 0x_1234567890ABCDEF_u64;
3768 println!("K =\t{:#016X}", key);
3769 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3770
3771 let message = "In the beginning God created the heavens and the earth.";
3772 println!("M =\t{}", message);
3773 let mut cipher = Vec::<u8>::new();
3774 a_des.encrypt_str_into_vec(&message, &mut cipher);
3775 print!("C (128 rounds) =\t");
3776 for c in cipher.clone()
3777 { print!("{:02X} ", c); }
3778 println!();
3779 let mut txt = String::new();
3780 for c in cipher.clone()
3781 { write!(txt, "{:02X} ", c); }
3782 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
3783
3784 let mut recovered = String::new();
3785 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3786 println!("B (128 rounds) =\t{}", recovered);
3787 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3788 assert_eq!(recovered, message);
3789 println!();
3790
3791 // Expanded case for 0 rounds which means that key is meaningless
3792 let key1 = 0x_1234567890ABCDEF_u64;
3793 let key2 = 0_u64;
3794 println!("K =\t{:#016X}", key);
3795 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3796 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3797
3798 let message = "In the beginning God created the heavens and the earth.";
3799 println!("M =\t{}", message);
3800 let mut cipher1 = Vec::<u8>::new();
3801 let mut cipher2 = Vec::<u8>::new();
3802 c_des.encrypt_str_into_vec(&message, &mut cipher1);
3803 d_des.encrypt_str_into_vec(&message, &mut cipher2);
3804 print!("C (0 rounds) =\t");
3805 for c in cipher1.clone()
3806 { print!("{:02X} ", c); }
3807 println!();
3808 let mut txt = String::new();
3809 for c in cipher1.clone()
3810 { write!(txt, "{:02X} ", c); }
3811 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3812 print!("D (0 rounds) =\t");
3813 for c in cipher2.clone()
3814 { print!("{:02X} ", c); }
3815 println!();
3816 let mut txt = String::new();
3817 for c in cipher2.clone()
3818 { write!(txt, "{:02X} ", c); }
3819 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
3820
3821 let mut recovered1 = String::new();
3822 let mut recovered2 = String::new();
3823 c_des.decrypt_into_string(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3824 d_des.decrypt_into_string(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3825 println!("B1 (0 rounds) =\t{}", recovered1);
3826 println!("B2 (0 rounds) =\t{}", recovered2);
3827 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
3828 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
3829 assert_eq!(recovered1, message);
3830 assert_eq!(recovered2, message);
3831 assert_eq!(recovered1, recovered2);
3832 println!();
3833
3834 // Normal case for the message of 0 bytes
3835 let key = 0x_1234567890ABCDEF_u64;
3836 println!("K =\t{:#016X}", key);
3837 let mut a_des = DES::new_with_key_u64(key);
3838
3839 let message = "";
3840 println!("M =\t{}", message);
3841 let mut cipher = Vec::<u8>::new();
3842 a_des.encrypt_str_into_vec(&message, &mut cipher);
3843 print!("C =\t");
3844 for c in cipher.clone()
3845 { print!("{:02X} ", c); }
3846 println!();
3847 let mut txt = String::new();
3848 for c in cipher.clone()
3849 { write!(txt, "{:02X} ", c); }
3850 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
3851
3852 let mut recovered = String::new();
3853 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3854 println!("B =\t{}", recovered);
3855 assert_eq!(recovered, "");
3856 assert_eq!(recovered, message);
3857 println!();
3858
3859 // Normal case for the message shorter than 8 bytes
3860 let key = 0x_1234567890ABCDEF_u64;
3861 println!("K =\t{:#016X}", key);
3862 let mut a_des = DES::new_with_key_u64(key);
3863
3864 let message = "7 bytes";
3865 println!("M =\t{}", message);
3866 let mut cipher = Vec::<u8>::new();
3867 a_des.encrypt_str_into_vec(&message, &mut cipher);
3868 print!("C =\t");
3869 for c in cipher.clone()
3870 { print!("{:02X} ", c); }
3871 println!();
3872 let mut txt = String::new();
3873 for c in cipher.clone()
3874 { write!(txt, "{:02X} ", c); }
3875 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
3876
3877 let mut recovered = String::new();
3878 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3879 println!("B =\t{}", recovered);
3880 assert_eq!(recovered, "7 bytes");
3881 assert_eq!(recovered, message);
3882 println!();
3883
3884 // Normal case for the message of 8 bytes
3885 let key = 0x_1234567890ABCDEF_u64;
3886 println!("K =\t{:#016X}", key);
3887 let mut a_des = DES::new_with_key_u64(key);
3888
3889 let message = "I am OK.";
3890 println!("M =\t{}", message);
3891 let mut cipher = Vec::<u8>::new();
3892 a_des.encrypt_str_into_vec(&message, &mut cipher);
3893 print!("C =\t");
3894 for c in cipher.clone()
3895 { print!("{:02X} ", c); }
3896 println!();
3897 let mut txt = String::new();
3898 for c in cipher.clone()
3899 { write!(txt, "{:02X} ", c); }
3900 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
3901
3902 let mut recovered = String::new();
3903 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3904 println!("B =\t{}", recovered);
3905 assert_eq!(recovered, "I am OK.");
3906 assert_eq!(recovered, message);
3907 println!();
3908
3909 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3910 let key = 0x_1234567890ABCDEF_u64;
3911 println!("K =\t{:#016X}", key);
3912 let mut a_des = DES::new_with_key_u64(key);
3913
3914 let message = "PARK Youngho";
3915 println!("M =\t{}", message);
3916 let mut cipher = Vec::<u8>::new();
3917 a_des.encrypt_str_into_vec(&message, &mut cipher);
3918 print!("C =\t");
3919 for c in cipher.clone()
3920 { print!("{:02X} ", c); }
3921 println!();
3922 let mut txt = String::new();
3923 for c in cipher.clone()
3924 { write!(txt, "{:02X} ", c); }
3925 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
3926
3927 let mut recovered = String::new();
3928 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3929 println!("B =\t{}", recovered);
3930 assert_eq!(recovered, "PARK Youngho");
3931 assert_eq!(recovered, message);
3932 println!();
3933
3934 // Normal case for the message of 16 bytes
3935 let key = 0x_1234567890ABCDEF_u64;
3936 println!("K =\t{:#016X}", key);
3937 let mut a_des = DES::new_with_key_u64(key);
3938
3939 let message = "고맙습니다.";
3940 println!("M =\t{}", message);
3941 let mut cipher = Vec::<u8>::new();
3942 a_des.encrypt_str_into_vec(&message, &mut cipher);
3943 print!("C =\t");
3944 for c in cipher.clone()
3945 { print!("{:02X} ", c); }
3946 println!();
3947 let mut txt = String::new();
3948 for c in cipher.clone()
3949 { write!(txt, "{:02X} ", c); }
3950 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
3951
3952 let mut recovered = String::new();
3953 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3954 println!("B =\t{}", recovered);
3955 assert_eq!(recovered, "고맙습니다.");
3956 assert_eq!(recovered, message);
3957 println!("-------------------------------");
3958}
3959
3960fn des_decrypt_vec_with_padding_iso_ecb()
3961{
3962 println!("des_decrypt_vec_with_padding_iso_ecb()");
3963 use std::io::Write;
3964 use std::fmt::Write as _;
3965 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
3966
3967 // Normal case
3968 let key = 0x_1234567890ABCDEF_u64;
3969 println!("K =\t{:#016X}", key);
3970 let mut a_des = DES::new_with_key_u64(key);
3971
3972 let message = "In the beginning God created the heavens and the earth.";
3973 println!("M =\t{}", message);
3974 let mut cipher = Vec::<u8>::new();
3975 a_des.encrypt_str_into_vec(&message, &mut cipher);
3976 print!("C (16 rounds) =\t");
3977 for c in cipher.clone()
3978 { print!("{:02X} ", c); }
3979 println!();
3980 let mut txt = String::new();
3981 for c in cipher.clone()
3982 { write!(txt, "{:02X} ", c); }
3983 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
3984
3985 let mut recovered = vec![0; 55];
3986 a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
3987 print!("Ba (16 rounds) =\t");
3988 for b in recovered.clone()
3989 { print!("{:02X} ", b); }
3990 println!();
3991 let mut txt = String::new();
3992 for c in recovered.clone()
3993 { write!(txt, "{:02X} ", c); }
3994 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3995
3996 let mut converted = String::new();
3997 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3998
3999 println!("Bb (16 rounds) =\t{}", converted);
4000 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4001 assert_eq!(converted, message);
4002 println!();
4003
4004 // Expanded case for 128 rounds
4005 let key = 0x_1234567890ABCDEF_u64;
4006 println!("K =\t{:#016X}", key);
4007 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4008
4009 let message = "In the beginning God created the heavens and the earth.";
4010 println!("M =\t{}", message);
4011 let mut cipher = Vec::<u8>::new();
4012 a_des.encrypt_str_into_vec(&message, &mut cipher);
4013 print!("C (128 rounds) =\t");
4014 for c in cipher.clone()
4015 { print!("{:02X} ", c); }
4016 println!();
4017 let mut txt = String::new();
4018 for c in cipher.clone()
4019 { write!(txt, "{:02X} ", c); }
4020 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4021
4022 let mut recovered = vec![0; 55];
4023 a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4024 print!("Ba (128 rounds) =\t");
4025 for b in recovered.clone()
4026 { print!("{:02X} ", b); }
4027 println!();
4028 let mut txt = String::new();
4029 for c in recovered.clone()
4030 { write!(txt, "{:02X} ", c); }
4031 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4032
4033 let mut converted = String::new();
4034 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4035
4036 println!("Bb (128 rounds) =\t{}", converted);
4037 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4038 assert_eq!(converted, message);
4039 println!();
4040
4041 // Expanded case for 0 rounds which means that key is meaningless
4042 let key1 = 0x_1234567890ABCDEF_u64;
4043 let key2 = 0_u64;
4044 println!("K =\t{:#016X}", key);
4045 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4046 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4047
4048 let message = "In the beginning God created the heavens and the earth.";
4049 println!("M =\t{}", message);
4050 let mut cipher1 = Vec::<u8>::new();
4051 let mut cipher2 = Vec::<u8>::new();
4052 c_des.encrypt_str_into_vec(&message, &mut cipher1);
4053 d_des.encrypt_str_into_vec(&message, &mut cipher2);
4054 print!("C (0 rounds) =\t");
4055 for c in cipher1.clone()
4056 { print!("{:02X} ", c); }
4057 println!();
4058 let mut txt = String::new();
4059 for c in cipher1.clone()
4060 { write!(txt, "{:02X} ", c); }
4061 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4062 print!("D (0 rounds) =\t");
4063 for c in cipher2.clone()
4064 { print!("{:02X} ", c); }
4065 println!();
4066 let mut txt = String::new();
4067 for c in cipher2.clone()
4068 { write!(txt, "{:02X} ", c); }
4069 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4070
4071 let mut recovered1 = vec![0; 55];
4072 let mut recovered2 = vec![0; 55];
4073 c_des.decrypt_vec(&cipher1, recovered1.as_mut_ptr());
4074 d_des.decrypt_vec(&cipher2, recovered2.as_mut_ptr());
4075 print!("B1a (0 rounds) =\t");
4076 for b in recovered1.clone()
4077 { print!("{:02X} ", b); }
4078 println!();
4079 let mut txt = String::new();
4080 for c in recovered1.clone()
4081 { write!(txt, "{:02X} ", c); }
4082 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4083 print!("B2a (0 rounds) =\t");
4084 for b in recovered2.clone()
4085 { print!("{:02X} ", b); }
4086 println!();
4087 let mut txt = String::new();
4088 for c in recovered2.clone()
4089 { write!(txt, "{:02X} ", c); }
4090 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4091
4092 let mut converted1 = String::new();
4093 let mut converted2 = String::new();
4094 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4095 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4096
4097 println!("B1b (0 rounds) =\t{}", converted1);
4098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4099 assert_eq!(converted1, message);
4100 println!("B2b (0 rounds) =\t{}", converted2);
4101 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4102 assert_eq!(converted2, message);
4103 assert_eq!(converted1, converted1);
4104 println!();
4105
4106 // Normal case for the message of 0 bytes
4107 let key = 0x_1234567890ABCDEF_u64;
4108 println!("K =\t{:#016X}", key);
4109 let mut a_des = DES::new_with_key_u64(key);
4110
4111 let message = "";
4112 println!("M =\t{}", message);
4113 let mut cipher = Vec::<u8>::new();
4114 a_des.encrypt_str_into_vec(&message, &mut cipher);
4115 print!("C =\t");
4116 for c in cipher.clone()
4117 { print!("{:02X} ", c); }
4118 println!();
4119 let mut txt = String::new();
4120 for c in cipher.clone()
4121 { write!(txt, "{:02X} ", c); }
4122 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4123
4124 let mut recovered = vec![0; 8];
4125 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4126 print!("Ba =\t");
4127 for b in recovered.clone()
4128 { print!("{:02X} ", b); }
4129 println!();
4130 let mut txt = String::new();
4131 for c in recovered.clone()
4132 { write!(txt, "{:02X} ", c); }
4133 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4134
4135 let mut converted = String::new();
4136 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4137 converted.truncate(len as usize);
4138
4139 println!("Bb =\t{}", converted);
4140 assert_eq!(converted, "");
4141 assert_eq!(converted, message);
4142 println!();
4143
4144 // Normal case for the message shorter than 8 bytes
4145 let key = 0x_1234567890ABCDEF_u64;
4146 println!("K =\t{:#016X}", key);
4147 let mut a_des = DES::new_with_key_u64(key);
4148
4149 let message = "7 bytes";
4150 println!("M =\t{}", message);
4151 let mut cipher = Vec::<u8>::new();
4152 a_des.encrypt_str_into_vec(&message, &mut cipher);
4153 print!("C =\t");
4154 for c in cipher.clone()
4155 { print!("{:02X} ", c); }
4156 println!();
4157 let mut txt = String::new();
4158 for c in cipher.clone()
4159 { write!(txt, "{:02X} ", c); }
4160 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4161
4162 let mut recovered = vec![0; 8];
4163 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4164 print!("Ba =\t");
4165 for b in recovered.clone()
4166 { print!("{:02X} ", b); }
4167 println!();
4168 let mut txt = String::new();
4169 for c in recovered.clone()
4170 { write!(txt, "{:02X} ", c); }
4171 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4172
4173 let mut converted = String::new();
4174 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4175 converted.truncate(len as usize);
4176
4177 println!("Bb =\t{}", converted);
4178 assert_eq!(converted, "7 bytes");
4179 assert_eq!(converted, message);
4180 println!();
4181
4182 // Normal case for the message of 8 bytes
4183 let key = 0x_1234567890ABCDEF_u64;
4184 println!("K =\t{:#016X}", key);
4185 let mut a_des = DES::new_with_key_u64(key);
4186
4187 let message = "I am OK.";
4188 println!("M =\t{}", message);
4189 let mut cipher = Vec::<u8>::new();
4190 a_des.encrypt_str_into_vec(&message, &mut cipher);
4191 print!("C =\t");
4192 for c in cipher.clone()
4193 { print!("{:02X} ", c); }
4194 println!();
4195 let mut txt = String::new();
4196 for c in cipher.clone()
4197 { write!(txt, "{:02X} ", c); }
4198 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4199
4200 let mut recovered = vec![0; 16];
4201 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4202 print!("Ba =\t");
4203 for b in recovered.clone()
4204 { print!("{:02X} ", b); }
4205 println!();
4206 let mut txt = String::new();
4207 for c in recovered.clone()
4208 { write!(txt, "{:02X} ", c); }
4209 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4210
4211 let mut converted = String::new();
4212 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4213 converted.truncate(len as usize);
4214
4215 println!("Bb =\t{}", converted);
4216 assert_eq!(converted, "I am OK.");
4217 assert_eq!(converted, message);
4218 println!();
4219
4220 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4221 let key = 0x_1234567890ABCDEF_u64;
4222 println!("K =\t{:#016X}", key);
4223 let mut a_des = DES::new_with_key_u64(key);
4224
4225 let message = "PARK Youngho";
4226 println!("M =\t{}", message);
4227 let mut cipher = Vec::<u8>::new();
4228 a_des.encrypt_str_into_vec(&message, &mut cipher);
4229 print!("C =\t");
4230 for c in cipher.clone()
4231 { print!("{:02X} ", c); }
4232 println!();
4233 let mut txt = String::new();
4234 for c in cipher.clone()
4235 { write!(txt, "{:02X} ", c); }
4236 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4237
4238 let mut recovered = vec![0; 16];
4239 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4240 print!("Ba =\t");
4241 for b in recovered.clone()
4242 { print!("{:02X} ", b); }
4243 println!();
4244 let mut txt = String::new();
4245 for c in recovered.clone()
4246 { write!(txt, "{:02X} ", c); }
4247 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4248
4249 let mut converted = String::new();
4250 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4251 converted.truncate(len as usize);
4252
4253 println!("Bb =\t{}", converted);
4254 assert_eq!(converted, "PARK Youngho");
4255 assert_eq!(converted, message);
4256 println!();
4257
4258 // Normal case for the message of 16 bytes
4259 let key = 0x_1234567890ABCDEF_u64;
4260 println!("K =\t{:#016X}", key);
4261 let mut a_des = DES::new_with_key_u64(key);
4262
4263 let message = "고맙습니다.";
4264 println!("M =\t{}", message);
4265 let mut cipher = Vec::<u8>::new();
4266 a_des.encrypt_str_into_vec(&message, &mut cipher);
4267 print!("C =\t");
4268 for c in cipher.clone()
4269 { print!("{:02X} ", c); }
4270 println!();
4271 let mut txt = String::new();
4272 for c in cipher.clone()
4273 { write!(txt, "{:02X} ", c); }
4274 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4275
4276 let mut recovered = vec![0; 24];
4277 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4278 print!("Ba =\t");
4279 for b in recovered.clone()
4280 { print!("{:02X} ", b); }
4281 println!();
4282 let mut txt = String::new();
4283 for c in recovered.clone()
4284 { write!(txt, "{:02X} ", c); }
4285 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4286
4287 let mut converted = String::new();
4288 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4289 converted.truncate(len as usize);
4290
4291 println!("Bb =\t{}", converted);
4292 assert_eq!(converted, "고맙습니다.");
4293 assert_eq!(converted, message);
4294 println!("-------------------------------");
4295}
4296
4297fn des_decrypt_vec_with_padding_iso_ecb_into_vec()
4298{
4299 println!("des_decrypt_vec_with_padding_iso_ecb_into_vec()");
4300 use std::io::Write;
4301 use std::fmt::Write as _;
4302 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4303
4304 // Normal case
4305 let key = 0x_1234567890ABCDEF_u64;
4306 println!("K =\t{:#016X}", key);
4307 let mut a_des = DES::new_with_key_u64(key);
4308
4309 let message = "In the beginning God created the heavens and the earth.";
4310 println!("M =\t{}", message);
4311 let mut cipher = Vec::<u8>::new();
4312 a_des.encrypt_str_into_vec(&message, &mut cipher);
4313 print!("C (16 rounds) =\t");
4314 for c in cipher.clone()
4315 { print!("{:02X} ", c); }
4316 println!();
4317 let mut txt = String::new();
4318 for c in cipher.clone()
4319 { write!(txt, "{:02X} ", c); }
4320 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4321
4322 let mut recovered = Vec::<u8>::new();
4323 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4324 print!("Ba (16 rounds) =\t");
4325 for b in recovered.clone()
4326 { print!("{:02X} ", b); }
4327 println!();
4328 let mut txt = String::new();
4329 for c in recovered.clone()
4330 { write!(txt, "{:02X} ", c); }
4331 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4332
4333 let mut converted = String::new();
4334 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4335
4336 println!("Bb (16 rounds) =\t{}", converted);
4337 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4338 assert_eq!(converted, message);
4339 println!();
4340
4341 // Expanded case for 128 rounds
4342 let key = 0x_1234567890ABCDEF_u64;
4343 println!("K =\t{:#016X}", key);
4344 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4345
4346 let message = "In the beginning God created the heavens and the earth.";
4347 println!("M =\t{}", message);
4348 let mut cipher = Vec::<u8>::new();
4349 a_des.encrypt_str_into_vec(&message, &mut cipher);
4350 print!("C (128 rounds) =\t");
4351 for c in cipher.clone()
4352 { print!("{:02X} ", c); }
4353 println!();
4354 let mut txt = String::new();
4355 for c in cipher.clone()
4356 { write!(txt, "{:02X} ", c); }
4357 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4358
4359 let mut recovered = Vec::<u8>::new();
4360 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4361 print!("Ba (128 rounds) =\t");
4362 for b in recovered.clone()
4363 { print!("{:02X} ", b); }
4364 println!();
4365 let mut txt = String::new();
4366 for c in recovered.clone()
4367 { write!(txt, "{:02X} ", c); }
4368 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4369
4370 let mut converted = String::new();
4371 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4372
4373 println!("Bb (128 rounds) =\t{}", converted);
4374 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4375 assert_eq!(converted, message);
4376 println!();
4377
4378 // Expanded case for 0 rounds which means that key is meaningless
4379 let key1 = 0x_1234567890ABCDEF_u64;
4380 let key2 = 0_u64;
4381 println!("K =\t{:#016X}", key);
4382 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4383 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4384
4385 let message = "In the beginning God created the heavens and the earth.";
4386 println!("M =\t{}", message);
4387 let mut cipher1 = Vec::<u8>::new();
4388 let mut cipher2 = Vec::<u8>::new();
4389 c_des.encrypt_str_into_vec(&message, &mut cipher1);
4390 d_des.encrypt_str_into_vec(&message, &mut cipher2);
4391 print!("C (0 rounds) =\t");
4392 for c in cipher1.clone()
4393 { print!("{:02X} ", c); }
4394 println!();
4395 let mut txt = String::new();
4396 for c in cipher1.clone()
4397 { write!(txt, "{:02X} ", c); }
4398 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4399 print!("D (0 rounds) =\t");
4400 for c in cipher2.clone()
4401 { print!("{:02X} ", c); }
4402 println!();
4403 let mut txt = String::new();
4404 for c in cipher2.clone()
4405 { write!(txt, "{:02X} ", c); }
4406 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4407
4408 let mut recovered1 = Vec::<u8>::new();
4409 let mut recovered2 = Vec::<u8>::new();
4410 c_des.decrypt_vec_into_vec(&cipher1, &mut recovered1);
4411 d_des.decrypt_vec_into_vec(&cipher2, &mut recovered2);
4412 print!("B1a (0 rounds) =\t");
4413 for b in recovered1.clone()
4414 { print!("{:02X} ", b); }
4415 println!();
4416 let mut txt = String::new();
4417 for c in recovered1.clone()
4418 { write!(txt, "{:02X} ", c); }
4419 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4420 print!("B2a (0 rounds) =\t");
4421 for b in recovered2.clone()
4422 { print!("{:02X} ", b); }
4423 println!();
4424 let mut txt = String::new();
4425 for c in recovered2.clone()
4426 { write!(txt, "{:02X} ", c); }
4427 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4428
4429 let mut converted1 = String::new();
4430 let mut converted2 = String::new();
4431 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4432 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4433
4434 println!("B1b (0 rounds) =\t{}", converted1);
4435 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4436 assert_eq!(converted1, message);
4437 println!("B2b (0 rounds) =\t{}", converted2);
4438 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4439 assert_eq!(converted2, message);
4440 assert_eq!(converted1, converted1);
4441 println!();
4442
4443 // Normal case for the message of 0 bytes
4444 let key = 0x_1234567890ABCDEF_u64;
4445 println!("K =\t{:#016X}", key);
4446 let mut a_des = DES::new_with_key_u64(key);
4447
4448 let message = "";
4449 println!("M =\t{}", message);
4450 let mut cipher = Vec::<u8>::new();
4451 a_des.encrypt_str_into_vec(&message, &mut cipher);
4452 print!("C =\t");
4453 for c in cipher.clone()
4454 { print!("{:02X} ", c); }
4455 println!();
4456 let mut txt = String::new();
4457 for c in cipher.clone()
4458 { write!(txt, "{:02X} ", c); }
4459 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4460
4461 let mut recovered = Vec::<u8>::new();
4462 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4463 print!("Ba =\t");
4464 for b in recovered.clone()
4465 { print!("{:02X} ", b); }
4466 println!();
4467 let mut txt = String::new();
4468 for c in recovered.clone()
4469 { write!(txt, "{:02X} ", c); }
4470 assert_eq!(txt, "");
4471
4472 let mut converted = String::new();
4473 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4474
4475 println!("Bb =\t{}", converted);
4476 assert_eq!(converted, "");
4477 assert_eq!(converted, message);
4478 println!();
4479
4480 // Normal case for the message shorter than 8 bytes
4481 let key = 0x_1234567890ABCDEF_u64;
4482 println!("K =\t{:#016X}", key);
4483 let mut a_des = DES::new_with_key_u64(key);
4484
4485 let message = "7 bytes";
4486 println!("M =\t{}", message);
4487 let mut cipher = Vec::<u8>::new();
4488 a_des.encrypt_str_into_vec(&message, &mut cipher);
4489 print!("C =\t");
4490 for c in cipher.clone()
4491 { print!("{:02X} ", c); }
4492 println!();
4493 let mut txt = String::new();
4494 for c in cipher.clone()
4495 { write!(txt, "{:02X} ", c); }
4496 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4497
4498 let mut recovered = Vec::<u8>::new();
4499 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4500 print!("Ba =\t");
4501 for b in recovered.clone()
4502 { print!("{:02X} ", b); }
4503 println!();
4504 let mut txt = String::new();
4505 for c in recovered.clone()
4506 { write!(txt, "{:02X} ", c); }
4507 assert_eq!(txt, "37 20 62 79 74 65 73 ");
4508
4509 let mut converted = String::new();
4510 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4511
4512 println!("Bb =\t{}", converted);
4513 assert_eq!(converted, "7 bytes");
4514 assert_eq!(converted, message);
4515 println!();
4516
4517 // Normal case for the message of 8 bytes
4518 let key = 0x_1234567890ABCDEF_u64;
4519 println!("K =\t{:#016X}", key);
4520 let mut a_des = DES::new_with_key_u64(key);
4521
4522 let message = "I am OK.";
4523 println!("M =\t{}", message);
4524 let mut cipher = Vec::<u8>::new();
4525 a_des.encrypt_str_into_vec(&message, &mut cipher);
4526 print!("C =\t");
4527 for c in cipher.clone()
4528 { print!("{:02X} ", c); }
4529 println!();
4530 let mut txt = String::new();
4531 for c in cipher.clone()
4532 { write!(txt, "{:02X} ", c); }
4533 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4534
4535 let mut recovered = Vec::<u8>::new();
4536 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4537 print!("Ba =\t");
4538 for b in recovered.clone()
4539 { print!("{:02X} ", b); }
4540 println!();
4541 let mut txt = String::new();
4542 for c in recovered.clone()
4543 { write!(txt, "{:02X} ", c); }
4544 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4545
4546 let mut converted = String::new();
4547 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4548
4549 println!("Bb =\t{}", converted);
4550 assert_eq!(converted, "I am OK.");
4551 assert_eq!(converted, message);
4552 println!();
4553
4554 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4555 let key = 0x_1234567890ABCDEF_u64;
4556 println!("K =\t{:#016X}", key);
4557 let mut a_des = DES::new_with_key_u64(key);
4558
4559 let message = "PARK Youngho";
4560 println!("M =\t{}", message);
4561 let mut cipher = Vec::<u8>::new();
4562 a_des.encrypt_str_into_vec(&message, &mut cipher);
4563 print!("C =\t");
4564 for c in cipher.clone()
4565 { print!("{:02X} ", c); }
4566 println!();
4567 let mut txt = String::new();
4568 for c in cipher.clone()
4569 { write!(txt, "{:02X} ", c); }
4570 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4571
4572 let mut recovered = Vec::<u8>::new();
4573 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4574 print!("Ba =\t");
4575 for b in recovered.clone()
4576 { print!("{:02X} ", b); }
4577 println!();
4578 let mut txt = String::new();
4579 for c in recovered.clone()
4580 { write!(txt, "{:02X} ", c); }
4581 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4582
4583 let mut converted = String::new();
4584 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4585
4586 println!("Bb =\t{}", converted);
4587 assert_eq!(converted, "PARK Youngho");
4588 assert_eq!(converted, message);
4589 println!();
4590
4591 // Normal case for the message of 16 bytes
4592 let key = 0x_1234567890ABCDEF_u64;
4593 println!("K =\t{:#016X}", key);
4594 let mut a_des = DES::new_with_key_u64(key);
4595
4596 let message = "고맙습니다.";
4597 println!("M =\t{}", message);
4598 let mut cipher = Vec::<u8>::new();
4599 a_des.encrypt_str_into_vec(&message, &mut cipher);
4600 print!("C =\t");
4601 for c in cipher.clone()
4602 { print!("{:02X} ", c); }
4603 println!();
4604 let mut txt = String::new();
4605 for c in cipher.clone()
4606 { write!(txt, "{:02X} ", c); }
4607 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4608
4609 let mut recovered = Vec::<u8>::new();
4610 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4611 print!("Ba =\t");
4612 for b in recovered.clone()
4613 { print!("{:02X} ", b); }
4614 println!();
4615 let mut txt = String::new();
4616 for c in recovered.clone()
4617 { write!(txt, "{:02X} ", c); }
4618 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4619
4620 let mut converted = String::new();
4621 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4622
4623 println!("Bb =\t{}", converted);
4624 assert_eq!(converted, "고맙습니다.");
4625 assert_eq!(converted, message);
4626 println!("-------------------------------");
4627}
4628
4629fn des_decrypt_vec_with_padding_iso_ecb_into_array()
4630{
4631 println!("des_decrypt_vec_with_padding_iso_ecb_into_array()");
4632 use std::io::Write;
4633 use std::fmt::Write as _;
4634 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4635
4636 // Normal case
4637 let key = 0x_1234567890ABCDEF_u64;
4638 println!("K =\t{:#016X}", key);
4639 let mut a_des = DES::new_with_key_u64(key);
4640
4641 let message = "In the beginning God created the heavens and the earth.";
4642 println!("M =\t{}", message);
4643 let mut cipher = Vec::<u8>::new();
4644 a_des.encrypt_str_into_vec(&message, &mut cipher);
4645 print!("C (16 rounds) =\t");
4646 for c in cipher.clone()
4647 { print!("{:02X} ", c); }
4648 println!();
4649 let mut txt = String::new();
4650 for c in cipher.clone()
4651 { write!(txt, "{:02X} ", c); }
4652 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4653
4654 let mut recovered = [0u8; 56];
4655 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4656 print!("Ba (16 rounds) =\t");
4657 for b in recovered.clone()
4658 { print!("{:02X} ", b); }
4659 println!();
4660 let mut txt = String::new();
4661 for c in recovered.clone()
4662 { write!(txt, "{:02X} ", c); }
4663 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4664
4665 let mut converted = String::new();
4666 unsafe { converted.as_mut_vec() }.write(&recovered);
4667 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4668 println!("Bb (16 rounds) =\t{}", converted);
4669 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4670 assert_eq!(converted, message);
4671 println!();
4672
4673 // Expanded case for 128 rounds
4674 let key = 0x_1234567890ABCDEF_u64;
4675 println!("K =\t{:#016X}", key);
4676 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4677
4678 let message = "In the beginning God created the heavens and the earth.";
4679 println!("M =\t{}", message);
4680 let mut cipher = Vec::<u8>::new();
4681 a_des.encrypt_str_into_vec(&message, &mut cipher);
4682 print!("C (128 rounds) =\t");
4683 for c in cipher.clone()
4684 { print!("{:02X} ", c); }
4685 println!();
4686 let mut txt = String::new();
4687 for c in cipher.clone()
4688 { write!(txt, "{:02X} ", c); }
4689 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
4690
4691 let mut recovered = [0u8; 56];
4692 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4693 print!("Ba (16 rounds) =\t");
4694 for b in recovered.clone()
4695 { print!("{:02X} ", b); }
4696 println!();
4697 let mut txt = String::new();
4698 for c in recovered.clone()
4699 { write!(txt, "{:02X} ", c); }
4700 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4701
4702 let mut converted = String::new();
4703 unsafe { converted.as_mut_vec() }.write(&recovered);
4704 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4705 println!("Bb (16 rounds) =\t{}", converted);
4706 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4707 assert_eq!(converted, message);
4708 println!();
4709
4710 // Expanded case for 0 rounds which means that key is meaningless
4711 let key1 = 0x_1234567890ABCDEF_u64;
4712 let key2 = 0_u64;
4713 println!("K =\t{:#016X}", key);
4714 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4715 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4716
4717 let message = "In the beginning God created the heavens and the earth.";
4718 println!("M =\t{}", message);
4719 let mut cipher1 = Vec::<u8>::new();
4720 let mut cipher2 = Vec::<u8>::new();
4721 c_des.encrypt_str_into_vec(&message, &mut cipher1);
4722 d_des.encrypt_str_into_vec(&message, &mut cipher2);
4723 print!("C (0 rounds) =\t");
4724 for c in cipher1.clone()
4725 { print!("{:02X} ", c); }
4726 println!();
4727 let mut txt = String::new();
4728 for c in cipher1.clone()
4729 { write!(txt, "{:02X} ", c); }
4730 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4731 print!("D (0 rounds) =\t");
4732 for c in cipher2.clone()
4733 { print!("{:02X} ", c); }
4734 println!();
4735 let mut txt = String::new();
4736 for c in cipher2.clone()
4737 { write!(txt, "{:02X} ", c); }
4738 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
4739
4740 let mut recovered1 = [0u8; 56];
4741 let mut recovered2 = [0u8; 56];
4742 let len1 = c_des.decrypt_vec_into_array(&cipher1, &mut recovered1);
4743 let len2 = d_des.decrypt_vec_into_array(&cipher2, &mut recovered2);
4744 print!("B1a (0 rounds) =\t");
4745 for b in recovered1.clone()
4746 { print!("{:02X} ", b); }
4747 println!();
4748 let mut txt = String::new();
4749 for c in recovered1.clone()
4750 { write!(txt, "{:02X} ", c); }
4751 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4752 print!("B2a (0 rounds) =\t");
4753 for b in recovered2.clone()
4754 { print!("{:02X} ", b); }
4755 println!();
4756 let mut txt = String::new();
4757 for c in recovered.clone()
4758 { write!(txt, "{:02X} ", c); }
4759 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4760
4761 let mut converted1 = String::new();
4762 let mut converted2 = String::new();
4763 unsafe { converted1.as_mut_vec() }.write(&recovered1);
4764 unsafe { converted2.as_mut_vec() }.write(&recovered2);
4765 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
4766 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
4767 println!("B1b (0 rounds) =\t{}", converted1);
4768 println!("B2b (0 rounds) =\t{}", converted2);
4769 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4770 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4771 assert_eq!(converted1, message);
4772 assert_eq!(converted2, message);
4773 assert_eq!(converted1, converted2);
4774 println!();
4775
4776 // Normal case for the message of 0 bytes
4777 let key = 0x_1234567890ABCDEF_u64;
4778 println!("K =\t{:#016X}", key);
4779 let mut a_des = DES::new_with_key_u64(key);
4780
4781 let message = "";
4782 println!("M =\t{}", message);
4783 let mut cipher = Vec::<u8>::new();
4784 a_des.encrypt_str_into_vec(&message, &mut cipher);
4785 print!("C =\t");
4786 for c in cipher.clone()
4787 { print!("{:02X} ", c); }
4788 println!();
4789 let mut txt = String::new();
4790 for c in cipher.clone()
4791 { write!(txt, "{:02X} ", c); }
4792 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
4793
4794 let mut recovered = [0u8; 8];
4795 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4796
4797 print!("Ba =\t");
4798 for b in recovered.clone()
4799 { print!("{:02X} ", b); }
4800 println!();
4801 let mut txt = String::new();
4802 for c in recovered.clone()
4803 { write!(txt, "{:02X} ", c); }
4804 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4805
4806 let mut converted = String::new();
4807 unsafe { converted.as_mut_vec() }.write(&recovered);
4808 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4809 println!("Bb =\t{}", converted);
4810 assert_eq!(converted, "");
4811 assert_eq!(converted, message);
4812 println!();
4813
4814 // Normal case for the message shorter than 8 bytes
4815 let key = 0x_1234567890ABCDEF_u64;
4816 println!("K =\t{:#016X}", key);
4817 let mut a_des = DES::new_with_key_u64(key);
4818
4819 let message = "7 bytes";
4820 println!("M =\t{}", message);
4821 let mut cipher = Vec::<u8>::new();
4822 a_des.encrypt_str_into_vec(&message, &mut cipher);
4823 print!("C =\t");
4824 for c in cipher.clone()
4825 { print!("{:02X} ", c); }
4826 println!();
4827 let mut txt = String::new();
4828 for c in cipher.clone()
4829 { write!(txt, "{:02X} ", c); }
4830 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
4831
4832 let mut recovered = [0u8; 8];
4833 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4834
4835 print!("Ba =\t");
4836 for b in recovered.clone()
4837 { print!("{:02X} ", b); }
4838 println!();
4839 let mut txt = String::new();
4840 for c in recovered.clone()
4841 { write!(txt, "{:02X} ", c); }
4842 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4843
4844 let mut converted = String::new();
4845 unsafe { converted.as_mut_vec() }.write(&recovered);
4846 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4847 println!("Bb =\t{}", converted);
4848 assert_eq!(converted, "7 bytes");
4849 assert_eq!(converted, message);
4850 println!();
4851
4852 // Normal case for the message of 8 bytes
4853 let key = 0x_1234567890ABCDEF_u64;
4854 println!("K =\t{:#016X}", key);
4855 let mut a_des = DES::new_with_key_u64(key);
4856
4857 let message = "I am OK.";
4858 println!("M =\t{}", message);
4859 let mut cipher = Vec::<u8>::new();
4860 a_des.encrypt_str_into_vec(&message, &mut cipher);
4861 print!("C =\t");
4862 for c in cipher.clone()
4863 { print!("{:02X} ", c); }
4864 println!();
4865 let mut txt = String::new();
4866 for c in cipher.clone()
4867 { write!(txt, "{:02X} ", c); }
4868 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
4869
4870 let mut recovered = [0u8; 16];
4871 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4872
4873 print!("Ba =\t");
4874 for b in recovered.clone()
4875 { print!("{:02X} ", b); }
4876 println!();
4877 let mut txt = String::new();
4878 for c in recovered.clone()
4879 { write!(txt, "{:02X} ", c); }
4880 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4881
4882 let mut converted = String::new();
4883 unsafe { converted.as_mut_vec() }.write(&recovered);
4884 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4885 println!("Bb =\t{}", converted);
4886 assert_eq!(converted, "I am OK.");
4887 assert_eq!(converted, message);
4888 println!();
4889
4890 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4891 let key = 0x_1234567890ABCDEF_u64;
4892 println!("K =\t{:#016X}", key);
4893 let mut a_des = DES::new_with_key_u64(key);
4894
4895 let message = "PARK Youngho";
4896 println!("M =\t{}", message);
4897 let mut cipher = Vec::<u8>::new();
4898 a_des.encrypt_str_into_vec(&message, &mut cipher);
4899 print!("C =\t");
4900 for c in cipher.clone()
4901 { print!("{:02X} ", c); }
4902 println!();
4903 let mut txt = String::new();
4904 for c in cipher.clone()
4905 { write!(txt, "{:02X} ", c); }
4906 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
4907
4908 let mut recovered = [0u8; 16];
4909 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4910
4911 print!("Ba =\t");
4912 for b in recovered.clone()
4913 { print!("{:02X} ", b); }
4914 println!();
4915 let mut txt = String::new();
4916 for c in recovered.clone()
4917 { write!(txt, "{:02X} ", c); }
4918 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4919
4920 let mut converted = String::new();
4921 unsafe { converted.as_mut_vec() }.write(&recovered);
4922 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4923 println!("Bb =\t{}", converted);
4924 assert_eq!(converted, "PARK Youngho");
4925 assert_eq!(converted, message);
4926 println!();
4927
4928 // Normal case for the message of 16 bytes
4929 let key = 0x_1234567890ABCDEF_u64;
4930 println!("K =\t{:#016X}", key);
4931 let mut a_des = DES::new_with_key_u64(key);
4932
4933 let message = "고맙습니다.";
4934 println!("M =\t{}", message);
4935 let mut cipher = Vec::<u8>::new();
4936 a_des.encrypt_str_into_vec(&message, &mut cipher);
4937 print!("C =\t");
4938 for c in cipher.clone()
4939 { print!("{:02X} ", c); }
4940 println!();
4941 let mut txt = String::new();
4942 for c in cipher.clone()
4943 { write!(txt, "{:02X} ", c); }
4944 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
4945
4946 let mut recovered = [0u8; 24];
4947 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4948
4949 print!("Ba =\t");
4950 for b in recovered.clone()
4951 { print!("{:02X} ", b); }
4952 println!();
4953 let mut txt = String::new();
4954 for c in recovered.clone()
4955 { write!(txt, "{:02X} ", c); }
4956 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4957
4958 let mut converted = String::new();
4959 unsafe { converted.as_mut_vec() }.write(&recovered);
4960 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4961 println!("Bb =\t{}", converted);
4962 assert_eq!(converted, "고맙습니다.");
4963 assert_eq!(converted, message);
4964 println!("-------------------------------");
4965}
4966
4967fn des_decrypt_vec_with_padding_iso_ecb_into_string()
4968{
4969 println!("des_decrypt_vec_with_padding_iso_ecb_into_string()");
4970 use std::io::Write;
4971 use std::fmt::Write as _;
4972 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
4973
4974 // Normal case
4975 let key = 0x_1234567890ABCDEF_u64;
4976 println!("K =\t{:#016X}", key);
4977 let mut a_des = DES::new_with_key_u64(key);
4978
4979 let message = "In the beginning God created the heavens and the earth.";
4980 println!("M =\t{}", message);
4981 let mut cipher = Vec::<u8>::new();
4982 a_des.encrypt_str_into_vec(&message, &mut cipher);
4983 print!("C (16 rounds) =\t");
4984 for c in cipher.clone()
4985 { print!("{:02X} ", c); }
4986 println!();
4987 let mut txt = String::new();
4988 for c in cipher.clone()
4989 { write!(txt, "{:02X} ", c); }
4990 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
4991
4992 let mut recovered = String::new();
4993 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
4994 println!("B (16 rounds) =\t{}", recovered);
4995 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4996 assert_eq!(recovered, message);
4997 println!();
4998
4999 // Expanded case for 128 rounds
5000 let key = 0x_1234567890ABCDEF_u64;
5001 println!("K =\t{:#016X}", key);
5002 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5003
5004 let message = "In the beginning God created the heavens and the earth.";
5005 println!("M =\t{}", message);
5006 let mut cipher = Vec::<u8>::new();
5007 a_des.encrypt_str_into_vec(&message, &mut cipher);
5008 print!("C (128 rounds) =\t");
5009 for c in cipher.clone()
5010 { print!("{:02X} ", c); }
5011 println!();
5012 let mut txt = String::new();
5013 for c in cipher.clone()
5014 { write!(txt, "{:02X} ", c); }
5015 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5016
5017 let mut recovered = String::new();
5018 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5019 println!("B (128 rounds) =\t{}", recovered);
5020 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5021 assert_eq!(recovered, message);
5022 println!();
5023
5024 // Expanded case for 0 rounds which means that key is meaningless
5025 let key1 = 0x_1234567890ABCDEF_u64;
5026 let key2 = 0_u64;
5027 println!("K =\t{:#016X}", key);
5028 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5029 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5030
5031 let message = "In the beginning God created the heavens and the earth.";
5032 println!("M =\t{}", message);
5033 let mut cipher1 = Vec::<u8>::new();
5034 let mut cipher2 = Vec::<u8>::new();
5035 c_des.encrypt_str_into_vec(&message, &mut cipher1);
5036 d_des.encrypt_str_into_vec(&message, &mut cipher2);
5037 print!("C (0 rounds) =\t");
5038 for c in cipher1.clone()
5039 { print!("{:02X} ", c); }
5040 println!();
5041 let mut txt = String::new();
5042 for c in cipher1.clone()
5043 { write!(txt, "{:02X} ", c); }
5044 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5045 print!("D (0 rounds) =\t");
5046 for c in cipher2.clone()
5047 { print!("{:02X} ", c); }
5048 println!();
5049 let mut txt = String::new();
5050 for c in cipher2.clone()
5051 { write!(txt, "{:02X} ", c); }
5052 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5053
5054 let mut recovered1 = String::new();
5055 let mut recovered2 = String::new();
5056 c_des.decrypt_vec_into_string(&cipher1, &mut recovered1);
5057 d_des.decrypt_vec_into_string(&cipher2, &mut recovered2);
5058 println!("B1 (0 rounds) =\t{}", recovered1);
5059 println!("B2 (0 rounds) =\t{}", recovered2);
5060 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5061 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5062 assert_eq!(recovered1, message);
5063 assert_eq!(recovered2, message);
5064 assert_eq!(recovered1, recovered2);
5065 println!();
5066
5067 // Normal case for the message of 0 bytes
5068 let key = 0x_1234567890ABCDEF_u64;
5069 println!("K =\t{:#016X}", key);
5070 let mut a_des = DES::new_with_key_u64(key);
5071
5072 let message = "";
5073 println!("M =\t{}", message);
5074 let mut cipher = Vec::<u8>::new();
5075 a_des.encrypt_str_into_vec(&message, &mut cipher);
5076 print!("C =\t");
5077 for c in cipher.clone()
5078 { print!("{:02X} ", c); }
5079 println!();
5080 let mut txt = String::new();
5081 for c in cipher.clone()
5082 { write!(txt, "{:02X} ", c); }
5083 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5084
5085 let mut recovered = String::new();
5086 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5087 println!("B =\t{}", recovered);
5088 assert_eq!(recovered, "");
5089 assert_eq!(recovered, message);
5090 println!();
5091
5092 // Normal case for the message shorter than 8 bytes
5093 let key = 0x_1234567890ABCDEF_u64;
5094 println!("K =\t{:#016X}", key);
5095 let mut a_des = DES::new_with_key_u64(key);
5096
5097 let message = "7 bytes";
5098 println!("M =\t{}", message);
5099 let mut cipher = Vec::<u8>::new();
5100 a_des.encrypt_str_into_vec(&message, &mut cipher);
5101 print!("C =\t");
5102 for c in cipher.clone()
5103 { print!("{:02X} ", c); }
5104 println!();
5105 let mut txt = String::new();
5106 for c in cipher.clone()
5107 { write!(txt, "{:02X} ", c); }
5108 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5109
5110 let mut recovered = String::new();
5111 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5112 println!("B =\t{}", recovered);
5113 assert_eq!(recovered, "7 bytes");
5114 assert_eq!(recovered, message);
5115 println!();
5116
5117 // Normal case for the message of 8 bytes
5118 let key = 0x_1234567890ABCDEF_u64;
5119 println!("K =\t{:#016X}", key);
5120 let mut a_des = DES::new_with_key_u64(key);
5121
5122 let message = "I am OK.";
5123 println!("M =\t{}", message);
5124 let mut cipher = Vec::<u8>::new();
5125 a_des.encrypt_str_into_vec(&message, &mut cipher);
5126 print!("C =\t");
5127 for c in cipher.clone()
5128 { print!("{:02X} ", c); }
5129 println!();
5130 let mut txt = String::new();
5131 for c in cipher.clone()
5132 { write!(txt, "{:02X} ", c); }
5133 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5134
5135 let mut recovered = String::new();
5136 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5137 println!("B =\t{}", recovered);
5138 assert_eq!(recovered, "I am OK.");
5139 assert_eq!(recovered, message);
5140 println!();
5141
5142 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5143 let key = 0x_1234567890ABCDEF_u64;
5144 println!("K =\t{:#016X}", key);
5145 let mut a_des = DES::new_with_key_u64(key);
5146
5147 let message = "PARK Youngho";
5148 println!("M =\t{}", message);
5149 let mut cipher = Vec::<u8>::new();
5150 a_des.encrypt_str_into_vec(&message, &mut cipher);
5151 print!("C =\t");
5152 for c in cipher.clone()
5153 { print!("{:02X} ", c); }
5154 println!();
5155 let mut txt = String::new();
5156 for c in cipher.clone()
5157 { write!(txt, "{:02X} ", c); }
5158 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5159
5160 let mut recovered = String::new();
5161 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5162 println!("B =\t{}", recovered);
5163 assert_eq!(recovered, "PARK Youngho");
5164 assert_eq!(recovered, message);
5165 println!();
5166
5167 // Normal case for the message of 16 bytes
5168 let key = 0x_1234567890ABCDEF_u64;
5169 println!("K =\t{:#016X}", key);
5170 let mut a_des = DES::new_with_key_u64(key);
5171
5172 let message = "고맙습니다.";
5173 println!("M =\t{}", message);
5174 let mut cipher = Vec::<u8>::new();
5175 a_des.encrypt_str_into_vec(&message, &mut cipher);
5176 print!("C =\t");
5177 for c in cipher.clone()
5178 { print!("{:02X} ", c); }
5179 println!();
5180 let mut txt = String::new();
5181 for c in cipher.clone()
5182 { write!(txt, "{:02X} ", c); }
5183 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5184
5185 let mut recovered = String::new();
5186 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5187 println!("B =\t{}", recovered);
5188 assert_eq!(recovered, "고맙습니다.");
5189 assert_eq!(recovered, message);
5190 println!("-------------------------------");
5191}
5192
5193fn des_decrypt_array_with_padding_iso_ecb()
5194{
5195 println!("des_decrypt_array_with_padding_iso_ecb()");
5196 use std::io::Write;
5197 use std::fmt::Write as _;
5198 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5199
5200 // Normal case
5201 let key = 0x_1234567890ABCDEF_u64;
5202 println!("K =\t{:#016X}", key);
5203 let mut a_des = DES::new_with_key_u64(key);
5204
5205 let message = "In the beginning God created the heavens and the earth.";
5206 println!("M =\t{}", message);
5207 let mut cipher = [0_u8; 56];
5208 a_des.encrypt_str_into_array(&message, &mut cipher);
5209 print!("C (16 rounds) =\t");
5210 for c in cipher.clone()
5211 { print!("{:02X} ", c); }
5212 println!();
5213 let mut txt = String::new();
5214 for c in cipher.clone()
5215 { write!(txt, "{:02X} ", c); }
5216 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5217
5218 let mut recovered = vec![0; 55];
5219 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5220 recovered.truncate(len as usize);
5221 print!("Ba (16 rounds) =\t");
5222 for b in recovered.clone()
5223 { print!("{:02X} ", b); }
5224 println!();
5225 let mut txt = String::new();
5226 for c in recovered.clone()
5227 { write!(txt, "{:02X} ", c); }
5228 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5229
5230 let mut converted = String::new();
5231 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5232
5233 println!("Bb (16 rounds) =\t{}", converted);
5234 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5235 assert_eq!(converted, message);
5236 println!();
5237
5238 // Expanded case for 128 rounds
5239 let key = 0x_1234567890ABCDEF_u64;
5240 println!("K =\t{:#016X}", key);
5241 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5242
5243 let message = "In the beginning God created the heavens and the earth.";
5244 println!("M =\t{}", message);
5245 let mut cipher = [0_u8; 56];
5246 a_des.encrypt_str_into_array(&message, &mut cipher);
5247 print!("C (128 rounds) =\t");
5248 for c in cipher.clone()
5249 { print!("{:02X} ", c); }
5250 println!();
5251 let mut txt = String::new();
5252 for c in cipher.clone()
5253 { write!(txt, "{:02X} ", c); }
5254 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5255
5256 let mut recovered = vec![0; 55];
5257 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5258 recovered.truncate(len as usize);
5259 print!("Ba (128 rounds) =\t");
5260 for b in recovered.clone()
5261 { print!("{:02X} ", b); }
5262 println!();
5263 let mut txt = String::new();
5264 for c in recovered.clone()
5265 { write!(txt, "{:02X} ", c); }
5266 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5267
5268 let mut converted = String::new();
5269 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5270
5271 println!("Bb (128 rounds) =\t{}", converted);
5272 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5273 assert_eq!(converted, message);
5274 println!();
5275
5276 // Expanded case for 0 rounds which means that key is meaningless
5277 let key1 = 0x_1234567890ABCDEF_u64;
5278 let key2 = 0_u64;
5279 println!("K =\t{:#016X}", key);
5280 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5281 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5282
5283 let message = "In the beginning God created the heavens and the earth.";
5284 println!("M =\t{}", message);
5285 let mut cipher1 = [0_u8; 56];
5286 let mut cipher2 = [0_u8; 56];
5287 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5288 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5289 print!("C (0 rounds) =\t");
5290 for c in cipher1.clone()
5291 { print!("{:02X} ", c); }
5292 println!();
5293 let mut txt = String::new();
5294 for c in cipher1.clone()
5295 { write!(txt, "{:02X} ", c); }
5296 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5297 print!("D (0 rounds) =\t");
5298 for c in cipher2.clone()
5299 { print!("{:02X} ", c); }
5300 println!();
5301 let mut txt = String::new();
5302 for c in cipher2.clone()
5303 { write!(txt, "{:02X} ", c); }
5304 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5305
5306 let mut recovered1 = vec![0; 55];
5307 let mut recovered2 = vec![0; 55];
5308 let len1 = c_des.decrypt_array(&cipher1, recovered1.as_mut_ptr());
5309 let len2 = d_des.decrypt_array(&cipher2, recovered2.as_mut_ptr());
5310 recovered1.truncate(len1 as usize);
5311 recovered2.truncate(len2 as usize);
5312
5313 print!("B1a (0 rounds) =\t");
5314 for b in recovered1.clone()
5315 { print!("{:02X} ", b); }
5316 println!();
5317 let mut txt = String::new();
5318 for c in recovered1.clone()
5319 { write!(txt, "{:02X} ", c); }
5320 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5321 print!("B2a (0 rounds) =\t");
5322 for b in recovered2.clone()
5323 { print!("{:02X} ", b); }
5324 println!();
5325 let mut txt = String::new();
5326 for c in recovered2.clone()
5327 { write!(txt, "{:02X} ", c); }
5328 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5329
5330 let mut converted1 = String::new();
5331 let mut converted2 = String::new();
5332 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5333 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5334
5335 println!("B1b (0 rounds) =\t{}", converted1);
5336 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5337 assert_eq!(converted1, message);
5338 println!("B2b (0 rounds) =\t{}", converted2);
5339 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5340 assert_eq!(converted2, message);
5341 assert_eq!(converted1, converted1);
5342 println!();
5343
5344 // Normal case for the message of 0 bytes
5345 let key = 0x_1234567890ABCDEF_u64;
5346 println!("K =\t{:#016X}", key);
5347 let mut a_des = DES::new_with_key_u64(key);
5348
5349 let message = "";
5350 println!("M =\t{}", message);
5351 let mut cipher = [0_u8; 8];
5352 a_des.encrypt_str_into_array(&message, &mut cipher);
5353 print!("C =\t");
5354 for c in cipher.clone()
5355 { print!("{:02X} ", c); }
5356 println!();
5357 let mut txt = String::new();
5358 for c in cipher.clone()
5359 { write!(txt, "{:02X} ", c); }
5360 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5361
5362 let mut recovered = vec![0; 8];
5363 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5364 recovered.truncate(len as usize);
5365
5366 print!("Ba =\t");
5367 for b in recovered.clone()
5368 { print!("{:02X} ", b); }
5369 println!();
5370 let mut txt = String::new();
5371 for c in recovered.clone()
5372 { write!(txt, "{:02X} ", c); }
5373 assert_eq!(txt, "");
5374
5375 let mut converted = String::new();
5376 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5377
5378 println!("Bb =\t{}", converted);
5379 assert_eq!(converted, "");
5380 assert_eq!(converted, message);
5381 println!();
5382
5383 // Normal case for the message shorter than 8 bytes
5384 let key = 0x_1234567890ABCDEF_u64;
5385 println!("K =\t{:#016X}", key);
5386 let mut a_des = DES::new_with_key_u64(key);
5387
5388 let message = "7 bytes";
5389 println!("M =\t{}", message);
5390 let mut cipher = [0_u8; 8];
5391 a_des.encrypt_str_into_array(&message, &mut cipher);
5392 print!("C =\t");
5393 for c in cipher.clone()
5394 { print!("{:02X} ", c); }
5395 println!();
5396 let mut txt = String::new();
5397 for c in cipher.clone()
5398 { write!(txt, "{:02X} ", c); }
5399 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5400
5401 let mut recovered = vec![0; 8];
5402 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5403 recovered.truncate(len as usize);
5404
5405 print!("Ba =\t");
5406 for b in recovered.clone()
5407 { print!("{:02X} ", b); }
5408 println!();
5409 let mut txt = String::new();
5410 for c in recovered.clone()
5411 { write!(txt, "{:02X} ", c); }
5412 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5413
5414 let mut converted = String::new();
5415 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5416
5417 println!("Bb =\t{}", converted);
5418 assert_eq!(converted, "7 bytes");
5419 assert_eq!(converted, message);
5420 println!();
5421
5422 // Normal case for the message of 8 bytes
5423 let key = 0x_1234567890ABCDEF_u64;
5424 println!("K =\t{:#016X}", key);
5425 let mut a_des = DES::new_with_key_u64(key);
5426
5427 let message = "I am OK.";
5428 println!("M =\t{}", message);
5429 let mut cipher = [0_u8; 16];
5430 a_des.encrypt_str_into_array(&message, &mut cipher);
5431 print!("C =\t");
5432 for c in cipher.clone()
5433 { print!("{:02X} ", c); }
5434 println!();
5435 let mut txt = String::new();
5436 for c in cipher.clone()
5437 { write!(txt, "{:02X} ", c); }
5438 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5439
5440 let mut recovered = vec![0; 16];
5441 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5442 recovered.truncate(len as usize);
5443
5444 print!("Ba =\t");
5445 for b in recovered.clone()
5446 { print!("{:02X} ", b); }
5447 println!();
5448 let mut txt = String::new();
5449 for c in recovered.clone()
5450 { write!(txt, "{:02X} ", c); }
5451 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5452
5453 let mut converted = String::new();
5454 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5455
5456 println!("Bb =\t{}", converted);
5457 assert_eq!(converted, "I am OK.");
5458 assert_eq!(converted, message);
5459 println!();
5460
5461 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5462 let key = 0x_1234567890ABCDEF_u64;
5463 println!("K =\t{:#016X}", key);
5464 let mut a_des = DES::new_with_key_u64(key);
5465
5466 let message = "PARK Youngho";
5467 println!("M =\t{}", message);
5468 let mut cipher = [0_u8; 16];
5469 a_des.encrypt_str_into_array(&message, &mut cipher);
5470 print!("C =\t");
5471 for c in cipher.clone()
5472 { print!("{:02X} ", c); }
5473 println!();
5474 let mut txt = String::new();
5475 for c in cipher.clone()
5476 { write!(txt, "{:02X} ", c); }
5477 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5478
5479 let mut recovered = vec![0; 16];
5480 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5481 recovered.truncate(len as usize);
5482 print!("Ba =\t");
5483 for b in recovered.clone()
5484 { print!("{:02X} ", b); }
5485 println!();
5486 let mut txt = String::new();
5487 for c in recovered.clone()
5488 { write!(txt, "{:02X} ", c); }
5489 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5490
5491 let mut converted = String::new();
5492 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5493
5494 println!("Bb =\t{}", converted);
5495 assert_eq!(converted, "PARK Youngho");
5496 assert_eq!(converted, message);
5497 println!();
5498
5499 // Normal case for the message of 16 bytes
5500 let key = 0x_1234567890ABCDEF_u64;
5501 println!("K =\t{:#016X}", key);
5502 let mut a_des = DES::new_with_key_u64(key);
5503
5504 let message = "고맙습니다.";
5505 println!("M =\t{}", message);
5506 let mut cipher = [0_u8; 24];
5507 a_des.encrypt_str_into_array(&message, &mut cipher);
5508 print!("C =\t");
5509 for c in cipher.clone()
5510 { print!("{:02X} ", c); }
5511 println!();
5512 let mut txt = String::new();
5513 for c in cipher.clone()
5514 { write!(txt, "{:02X} ", c); }
5515 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5516
5517 let mut recovered = vec![0; 24];
5518 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5519 recovered.truncate(len as usize);
5520
5521 print!("Ba =\t");
5522 for b in recovered.clone()
5523 { print!("{:02X} ", b); }
5524 println!();
5525 let mut txt = String::new();
5526 for c in recovered.clone()
5527 { write!(txt, "{:02X} ", c); }
5528 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5529
5530 let mut converted = String::new();
5531 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5532
5533 println!("Bb =\t{}", converted);
5534 assert_eq!(converted, "고맙습니다.");
5535 assert_eq!(converted, message);
5536 println!("-------------------------------");
5537}
5538
5539fn des_decrypt_array_with_padding_iso_ecb_into_vec()
5540{
5541 println!("des_decrypt_array_with_padding_iso_ecb_into_vec()");
5542 use std::io::Write;
5543 use std::fmt::Write as _;
5544 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5545
5546 // Normal case
5547 let key = 0x_1234567890ABCDEF_u64;
5548 println!("K =\t{:#016X}", key);
5549 let mut a_des = DES::new_with_key_u64(key);
5550
5551 let message = "In the beginning God created the heavens and the earth.";
5552 println!("M =\t{}", message);
5553 let mut cipher = [0_u8; 56];
5554 a_des.encrypt_str_into_array(&message, &mut cipher);
5555 print!("C (16 rounds) =\t");
5556 for c in cipher.clone()
5557 { print!("{:02X} ", c); }
5558 println!();
5559 let mut txt = String::new();
5560 for c in cipher.clone()
5561 { write!(txt, "{:02X} ", c); }
5562 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5563
5564 let mut recovered = Vec::<u8>::new();
5565 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5566 print!("Ba (16 rounds) =\t");
5567 for b in recovered.clone()
5568 { print!("{:02X} ", b); }
5569 println!();
5570 let mut txt = String::new();
5571 for c in recovered.clone()
5572 { write!(txt, "{:02X} ", c); }
5573 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5574
5575 let mut converted = String::new();
5576 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5577
5578 println!("Bb (16 rounds) =\t{}", converted);
5579 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5580 assert_eq!(converted, message);
5581 println!();
5582
5583 // Expanded case for 128 rounds
5584 let key = 0x_1234567890ABCDEF_u64;
5585 println!("K =\t{:#016X}", key);
5586 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5587
5588 let message = "In the beginning God created the heavens and the earth.";
5589 println!("M =\t{}", message);
5590 let mut cipher = [0_u8; 56];
5591 a_des.encrypt_str_into_array(&message, &mut cipher);
5592 print!("C (128 rounds) =\t");
5593 for c in cipher.clone()
5594 { print!("{:02X} ", c); }
5595 println!();
5596 let mut txt = String::new();
5597 for c in cipher.clone()
5598 { write!(txt, "{:02X} ", c); }
5599 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5600
5601 let mut recovered = Vec::<u8>::new();
5602 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5603 print!("Ba (128 rounds) =\t");
5604 for b in recovered.clone()
5605 { print!("{:02X} ", b); }
5606 println!();
5607 let mut txt = String::new();
5608 for c in recovered.clone()
5609 { write!(txt, "{:02X} ", c); }
5610 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5611
5612 let mut converted = String::new();
5613 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5614
5615 println!("Bb (128 rounds) =\t{}", converted);
5616 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5617 assert_eq!(converted, message);
5618 println!();
5619
5620 // Expanded case for 0 rounds which means that key is meaningless
5621 let key1 = 0x_1234567890ABCDEF_u64;
5622 let key2 = 0_u64;
5623 println!("K =\t{:#016X}", key);
5624 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5625 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5626
5627 let message = "In the beginning God created the heavens and the earth.";
5628 println!("M =\t{}", message);
5629 let mut cipher1 = [0_u8; 56];
5630 let mut cipher2 = [0_u8; 56];
5631 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5632 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5633 print!("C (0 rounds) =\t");
5634 for c in cipher1.clone()
5635 { print!("{:02X} ", c); }
5636 println!();
5637 let mut txt = String::new();
5638 for c in cipher1.clone()
5639 { write!(txt, "{:02X} ", c); }
5640 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5641 print!("D (0 rounds) =\t");
5642 for c in cipher2.clone()
5643 { print!("{:02X} ", c); }
5644 println!();
5645 let mut txt = String::new();
5646 for c in cipher2.clone()
5647 { write!(txt, "{:02X} ", c); }
5648 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5649
5650 let mut recovered1 = Vec::<u8>::new();
5651 let mut recovered2 = Vec::<u8>::new();
5652 c_des.decrypt_array_into_vec(&cipher1, &mut recovered1);
5653 d_des.decrypt_array_into_vec(&cipher2, &mut recovered2);
5654 print!("B1a (0 rounds) =\t");
5655 for b in recovered1.clone()
5656 { print!("{:02X} ", b); }
5657 println!();
5658 let mut txt = String::new();
5659 for c in recovered1.clone()
5660 { write!(txt, "{:02X} ", c); }
5661 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5662 print!("B2a (0 rounds) =\t");
5663 for b in recovered2.clone()
5664 { print!("{:02X} ", b); }
5665 println!();
5666 let mut txt = String::new();
5667 for c in recovered2.clone()
5668 { write!(txt, "{:02X} ", c); }
5669 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5670
5671 let mut converted1 = String::new();
5672 let mut converted2 = String::new();
5673 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5674 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5675
5676 println!("B1b (0 rounds) =\t{}", converted1);
5677 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5678 assert_eq!(converted1, message);
5679 println!("B2b (0 rounds) =\t{}", converted2);
5680 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5681 assert_eq!(converted2, message);
5682 assert_eq!(converted1, converted1);
5683 println!();
5684
5685 // Normal case for the message of 0 bytes
5686 let key = 0x_1234567890ABCDEF_u64;
5687 println!("K =\t{:#016X}", key);
5688 let mut a_des = DES::new_with_key_u64(key);
5689
5690 let message = "";
5691 println!("M =\t{}", message);
5692 let mut cipher = [0_u8; 8];
5693 a_des.encrypt_str_into_array(&message, &mut cipher);
5694 print!("C =\t");
5695 for c in cipher.clone()
5696 { print!("{:02X} ", c); }
5697 println!();
5698 let mut txt = String::new();
5699 for c in cipher.clone()
5700 { write!(txt, "{:02X} ", c); }
5701 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
5702
5703 let mut recovered = Vec::<u8>::new();
5704 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5705 print!("Ba =\t");
5706 for b in recovered.clone()
5707 { print!("{:02X} ", b); }
5708 println!();
5709 let mut txt = String::new();
5710 for c in recovered.clone()
5711 { write!(txt, "{:02X} ", c); }
5712 assert_eq!(txt, "");
5713
5714 let mut converted = String::new();
5715 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5716
5717 println!("Bb =\t{}", converted);
5718 assert_eq!(converted, "");
5719 assert_eq!(converted, message);
5720 println!();
5721
5722 // Normal case for the message shorter than 8 bytes
5723 let key = 0x_1234567890ABCDEF_u64;
5724 println!("K =\t{:#016X}", key);
5725 let mut a_des = DES::new_with_key_u64(key);
5726
5727 let message = "7 bytes";
5728 println!("M =\t{}", message);
5729 let mut cipher = [0_u8; 8];
5730 a_des.encrypt_str_into_array(&message, &mut cipher);
5731 print!("C =\t");
5732 for c in cipher.clone()
5733 { print!("{:02X} ", c); }
5734 println!();
5735 let mut txt = String::new();
5736 for c in cipher.clone()
5737 { write!(txt, "{:02X} ", c); }
5738 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
5739
5740 let mut recovered = Vec::<u8>::new();
5741 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5742 print!("Ba =\t");
5743 for b in recovered.clone()
5744 { print!("{:02X} ", b); }
5745 println!();
5746 let mut txt = String::new();
5747 for c in recovered.clone()
5748 { write!(txt, "{:02X} ", c); }
5749 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5750
5751 let mut converted = String::new();
5752 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5753
5754 println!("Bb =\t{}", converted);
5755 assert_eq!(converted, "7 bytes");
5756 assert_eq!(converted, message);
5757 println!();
5758
5759 // Normal case for the message of 8 bytes
5760 let key = 0x_1234567890ABCDEF_u64;
5761 println!("K =\t{:#016X}", key);
5762 let mut a_des = DES::new_with_key_u64(key);
5763
5764 let message = "I am OK.";
5765 println!("M =\t{}", message);
5766 let mut cipher = [0_u8; 16];
5767 a_des.encrypt_str_into_array(&message, &mut cipher);
5768 print!("C =\t");
5769 for c in cipher.clone()
5770 { print!("{:02X} ", c); }
5771 println!();
5772 let mut txt = String::new();
5773 for c in cipher.clone()
5774 { write!(txt, "{:02X} ", c); }
5775 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
5776
5777 let mut recovered = Vec::<u8>::new();
5778 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5779 print!("Ba =\t");
5780 for b in recovered.clone()
5781 { print!("{:02X} ", b); }
5782 println!();
5783 let mut txt = String::new();
5784 for c in recovered.clone()
5785 { write!(txt, "{:02X} ", c); }
5786 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5787
5788 let mut converted = String::new();
5789 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5790
5791 println!("Bb =\t{}", converted);
5792 assert_eq!(converted, "I am OK.");
5793 assert_eq!(converted, message);
5794 println!();
5795
5796 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5797 let key = 0x_1234567890ABCDEF_u64;
5798 println!("K =\t{:#016X}", key);
5799 let mut a_des = DES::new_with_key_u64(key);
5800
5801 let message = "PARK Youngho";
5802 println!("M =\t{}", message);
5803 let mut cipher = [0_u8; 16];
5804 a_des.encrypt_str_into_array(&message, &mut cipher);
5805 print!("C =\t");
5806 for c in cipher.clone()
5807 { print!("{:02X} ", c); }
5808 println!();
5809 let mut txt = String::new();
5810 for c in cipher.clone()
5811 { write!(txt, "{:02X} ", c); }
5812 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
5813
5814 let mut recovered = Vec::<u8>::new();
5815 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5816 print!("Ba =\t");
5817 for b in recovered.clone()
5818 { print!("{:02X} ", b); }
5819 println!();
5820 let mut txt = String::new();
5821 for c in recovered.clone()
5822 { write!(txt, "{:02X} ", c); }
5823 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5824
5825 let mut converted = String::new();
5826 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5827
5828 println!("Bb =\t{}", converted);
5829 assert_eq!(converted, "PARK Youngho");
5830 assert_eq!(converted, message);
5831 println!();
5832
5833 // Normal case for the message of 16 bytes
5834 let key = 0x_1234567890ABCDEF_u64;
5835 println!("K =\t{:#016X}", key);
5836 let mut a_des = DES::new_with_key_u64(key);
5837
5838 let message = "고맙습니다.";
5839 println!("M =\t{}", message);
5840 let mut cipher = [0_u8; 24];
5841 a_des.encrypt_str_into_array(&message, &mut cipher);
5842 print!("C =\t");
5843 for c in cipher.clone()
5844 { print!("{:02X} ", c); }
5845 println!();
5846 let mut txt = String::new();
5847 for c in cipher.clone()
5848 { write!(txt, "{:02X} ", c); }
5849 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
5850
5851 let mut recovered = Vec::<u8>::new();
5852 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5853 print!("Ba =\t");
5854 for b in recovered.clone()
5855 { print!("{:02X} ", b); }
5856 println!();
5857 let mut txt = String::new();
5858 for c in recovered.clone()
5859 { write!(txt, "{:02X} ", c); }
5860 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5861
5862 let mut converted = String::new();
5863 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5864
5865 println!("Bb =\t{}", converted);
5866 assert_eq!(converted, "고맙습니다.");
5867 assert_eq!(converted, message);
5868 println!("-------------------------------");
5869}
5870
5871fn des_decrypt_array_with_padding_iso_ecb_into_array()
5872{
5873 println!("des_decrypt_array_with_padding_iso_ecb_into_array()");
5874 use std::io::Write;
5875 use std::fmt::Write as _;
5876 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
5877
5878 // Normal case
5879 let key = 0x_1234567890ABCDEF_u64;
5880 println!("K =\t{:#016X}", key);
5881 let mut a_des = DES::new_with_key_u64(key);
5882
5883 let message = "In the beginning God created the heavens and the earth.";
5884 println!("M =\t{}", message);
5885 let mut cipher = [0_u8; 56];
5886 a_des.encrypt_str_into_array(&message, &mut cipher);
5887 print!("C (16 rounds) =\t");
5888 for c in cipher.clone()
5889 { print!("{:02X} ", c); }
5890 println!();
5891 let mut txt = String::new();
5892 for c in cipher.clone()
5893 { write!(txt, "{:02X} ", c); }
5894 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
5895
5896 let mut recovered = [0u8; 56];
5897 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5898 print!("Ba (16 rounds) =\t");
5899 for b in recovered.clone()
5900 { print!("{:02X} ", b); }
5901 println!();
5902 let mut txt = String::new();
5903 for c in recovered.clone()
5904 { write!(txt, "{:02X} ", c); }
5905 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5906
5907 let mut converted = String::new();
5908 unsafe { converted.as_mut_vec() }.write(&recovered);
5909 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5910 println!("Bb (16 rounds) =\t{}", converted);
5911 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5912 assert_eq!(converted, message);
5913 println!();
5914
5915 // Expanded case for 128 rounds
5916 let key = 0x_1234567890ABCDEF_u64;
5917 println!("K =\t{:#016X}", key);
5918 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5919
5920 let message = "In the beginning God created the heavens and the earth.";
5921 println!("M =\t{}", message);
5922 let mut cipher = [0_u8; 56];
5923 a_des.encrypt_str_into_array(&message, &mut cipher);
5924 print!("C (128 rounds) =\t");
5925 for c in cipher.clone()
5926 { print!("{:02X} ", c); }
5927 println!();
5928 let mut txt = String::new();
5929 for c in cipher.clone()
5930 { write!(txt, "{:02X} ", c); }
5931 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
5932
5933 let mut recovered = [0u8; 56];
5934 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5935 print!("Ba (16 rounds) =\t");
5936 for b in recovered.clone()
5937 { print!("{:02X} ", b); }
5938 println!();
5939 let mut txt = String::new();
5940 for c in recovered.clone()
5941 { write!(txt, "{:02X} ", c); }
5942 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5943
5944 let mut converted = String::new();
5945 unsafe { converted.as_mut_vec() }.write(&recovered);
5946 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5947 println!("Bb (16 rounds) =\t{}", converted);
5948 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5949 assert_eq!(converted, message);
5950 println!();
5951
5952 // Expanded case for 0 rounds which means that key is meaningless
5953 let key1 = 0x_1234567890ABCDEF_u64;
5954 let key2 = 0_u64;
5955 println!("K =\t{:#016X}", key);
5956 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5957 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5958
5959 let message = "In the beginning God created the heavens and the earth.";
5960 println!("M =\t{}", message);
5961 let mut cipher1 = [0_u8; 56];
5962 let mut cipher2 = [0_u8; 56];
5963 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5964 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5965 print!("C (0 rounds) =\t");
5966 for c in cipher1.clone()
5967 { print!("{:02X} ", c); }
5968 println!();
5969 let mut txt = String::new();
5970 for c in cipher1.clone()
5971 { write!(txt, "{:02X} ", c); }
5972 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5973 print!("D (0 rounds) =\t");
5974 for c in cipher2.clone()
5975 { print!("{:02X} ", c); }
5976 println!();
5977 let mut txt = String::new();
5978 for c in cipher2.clone()
5979 { write!(txt, "{:02X} ", c); }
5980 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
5981
5982 let mut recovered1 = [0u8; 56];
5983 let mut recovered2 = [0u8; 56];
5984 let len1 = c_des.decrypt_array_into_array(&cipher1, &mut recovered1);
5985 let len2 = d_des.decrypt_array_into_array(&cipher2, &mut recovered2);
5986 print!("B1a (0 rounds) =\t");
5987 for b in recovered1.clone()
5988 { print!("{:02X} ", b); }
5989 println!();
5990 let mut txt = String::new();
5991 for c in recovered1.clone()
5992 { write!(txt, "{:02X} ", c); }
5993 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5994 print!("B2a (0 rounds) =\t");
5995 for b in recovered2.clone()
5996 { print!("{:02X} ", b); }
5997 println!();
5998 let mut txt = String::new();
5999 for c in recovered.clone()
6000 { write!(txt, "{:02X} ", c); }
6001 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6002
6003 let mut converted1 = String::new();
6004 let mut converted2 = String::new();
6005 unsafe { converted1.as_mut_vec() }.write(&recovered1);
6006 unsafe { converted2.as_mut_vec() }.write(&recovered2);
6007 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6008 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6009 println!("B1b (0 rounds) =\t{}", converted1);
6010 println!("B2b (0 rounds) =\t{}", converted2);
6011 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6012 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6013 assert_eq!(converted1, message);
6014 assert_eq!(converted2, message);
6015 assert_eq!(converted1, converted2);
6016 println!();
6017
6018 // Normal case for the message of 0 bytes
6019 let key = 0x_1234567890ABCDEF_u64;
6020 println!("K =\t{:#016X}", key);
6021 let mut a_des = DES::new_with_key_u64(key);
6022
6023 let message = "";
6024 println!("M =\t{}", message);
6025 let mut cipher = [0_u8; 8];
6026 a_des.encrypt_str_into_array(&message, &mut cipher);
6027 print!("C =\t");
6028 for c in cipher.clone()
6029 { print!("{:02X} ", c); }
6030 println!();
6031 let mut txt = String::new();
6032 for c in cipher.clone()
6033 { write!(txt, "{:02X} ", c); }
6034 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
6035
6036 let mut recovered = [0u8; 8];
6037 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6038
6039 print!("Ba =\t");
6040 for b in recovered.clone()
6041 { print!("{:02X} ", b); }
6042 println!();
6043 let mut txt = String::new();
6044 for c in recovered.clone()
6045 { write!(txt, "{:02X} ", c); }
6046 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6047
6048 let mut converted = String::new();
6049 unsafe { converted.as_mut_vec() }.write(&recovered);
6050 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6051 println!("Bb =\t{}", converted);
6052 assert_eq!(converted, "");
6053 assert_eq!(converted, message);
6054 println!();
6055
6056 // Normal case for the message shorter than 8 bytes
6057 let key = 0x_1234567890ABCDEF_u64;
6058 println!("K =\t{:#016X}", key);
6059 let mut a_des = DES::new_with_key_u64(key);
6060
6061 let message = "7 bytes";
6062 println!("M =\t{}", message);
6063 let mut cipher = [0_u8; 8];
6064 a_des.encrypt_str_into_array(&message, &mut cipher);
6065 print!("C =\t");
6066 for c in cipher.clone()
6067 { print!("{:02X} ", c); }
6068 println!();
6069 let mut txt = String::new();
6070 for c in cipher.clone()
6071 { write!(txt, "{:02X} ", c); }
6072 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
6073
6074 let mut recovered = [0u8; 8];
6075 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6076
6077 print!("Ba =\t");
6078 for b in recovered.clone()
6079 { print!("{:02X} ", b); }
6080 println!();
6081 let mut txt = String::new();
6082 for c in recovered.clone()
6083 { write!(txt, "{:02X} ", c); }
6084 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6085
6086 let mut converted = String::new();
6087 unsafe { converted.as_mut_vec() }.write(&recovered);
6088 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6089 println!("Bb =\t{}", converted);
6090 assert_eq!(converted, "7 bytes");
6091 assert_eq!(converted, message);
6092 println!();
6093
6094 // Normal case for the message of 8 bytes
6095 let key = 0x_1234567890ABCDEF_u64;
6096 println!("K =\t{:#016X}", key);
6097 let mut a_des = DES::new_with_key_u64(key);
6098
6099 let message = "I am OK.";
6100 println!("M =\t{}", message);
6101 let mut cipher = [0_u8; 16];
6102 a_des.encrypt_str_into_array(&message, &mut cipher);
6103 print!("C =\t");
6104 for c in cipher.clone()
6105 { print!("{:02X} ", c); }
6106 println!();
6107 let mut txt = String::new();
6108 for c in cipher.clone()
6109 { write!(txt, "{:02X} ", c); }
6110 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
6111
6112 let mut recovered = [0u8; 16];
6113 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6114
6115 print!("Ba =\t");
6116 for b in recovered.clone()
6117 { print!("{:02X} ", b); }
6118 println!();
6119 let mut txt = String::new();
6120 for c in recovered.clone()
6121 { write!(txt, "{:02X} ", c); }
6122 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6123
6124 let mut converted = String::new();
6125 unsafe { converted.as_mut_vec() }.write(&recovered);
6126 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6127 println!("Bb =\t{}", converted);
6128 assert_eq!(converted, "I am OK.");
6129 assert_eq!(converted, message);
6130 println!();
6131
6132 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6133 let key = 0x_1234567890ABCDEF_u64;
6134 println!("K =\t{:#016X}", key);
6135 let mut a_des = DES::new_with_key_u64(key);
6136
6137 let message = "PARK Youngho";
6138 println!("M =\t{}", message);
6139 let mut cipher = [0_u8; 16];
6140 a_des.encrypt_str_into_array(&message, &mut cipher);
6141 print!("C =\t");
6142 for c in cipher.clone()
6143 { print!("{:02X} ", c); }
6144 println!();
6145 let mut txt = String::new();
6146 for c in cipher.clone()
6147 { write!(txt, "{:02X} ", c); }
6148 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
6149
6150 let mut recovered = [0u8; 16];
6151 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6152
6153 print!("Ba =\t");
6154 for b in recovered.clone()
6155 { print!("{:02X} ", b); }
6156 println!();
6157 let mut txt = String::new();
6158 for c in recovered.clone()
6159 { write!(txt, "{:02X} ", c); }
6160 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6161
6162 let mut converted = String::new();
6163 unsafe { converted.as_mut_vec() }.write(&recovered);
6164 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6165 println!("Bb =\t{}", converted);
6166 assert_eq!(converted, "PARK Youngho");
6167 assert_eq!(converted, message);
6168 println!();
6169
6170 // Normal case for the message of 16 bytes
6171 let key = 0x_1234567890ABCDEF_u64;
6172 println!("K =\t{:#016X}", key);
6173 let mut a_des = DES::new_with_key_u64(key);
6174
6175 let message = "고맙습니다.";
6176 println!("M =\t{}", message);
6177 let mut cipher = [0_u8; 24];
6178 a_des.encrypt_str_into_array(&message, &mut cipher);
6179 print!("C =\t");
6180 for c in cipher.clone()
6181 { print!("{:02X} ", c); }
6182 println!();
6183 let mut txt = String::new();
6184 for c in cipher.clone()
6185 { write!(txt, "{:02X} ", c); }
6186 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
6187
6188 let mut recovered = [0u8; 24];
6189 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6190
6191 print!("Ba =\t");
6192 for b in recovered.clone()
6193 { print!("{:02X} ", b); }
6194 println!();
6195 let mut txt = String::new();
6196 for c in recovered.clone()
6197 { write!(txt, "{:02X} ", c); }
6198 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6199
6200 let mut converted = String::new();
6201 unsafe { converted.as_mut_vec() }.write(&recovered);
6202 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6203 println!("Bb =\t{}", converted);
6204 assert_eq!(converted, "고맙습니다.");
6205 assert_eq!(converted, message);
6206 println!("-------------------------------");
6207}
6208
6209fn des_decrypt_array_with_padding_iso_ecb_into_string()
6210{
6211 println!("des_decrypt_array_with_padding_iso_ecb_into_string()");
6212 use std::io::Write;
6213 use std::fmt::Write as _;
6214 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_ISO };
6215
6216 // Normal case
6217 let key = 0x_1234567890ABCDEF_u64;
6218 println!("K =\t{:#016X}", key);
6219 let mut a_des = DES::new_with_key_u64(key);
6220
6221 let message = "In the beginning God created the heavens and the earth.";
6222 println!("M =\t{}", message);
6223 let mut cipher = [0_u8; 56];
6224 a_des.encrypt_str_into_array(&message, &mut cipher);
6225 print!("C (16 rounds) =\t");
6226 for c in cipher.clone()
6227 { print!("{:02X} ", c); }
6228 println!();
6229 let mut txt = String::new();
6230 for c in cipher.clone()
6231 { write!(txt, "{:02X} ", c); }
6232 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 F4 BE 6B A5 C5 7D F6 5D ");
6233
6234 let mut recovered = String::new();
6235 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6236 println!("B (16 rounds) =\t{}", recovered);
6237 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6238 assert_eq!(recovered, message);
6239 println!();
6240
6241 // Expanded case for 128 rounds
6242 let key = 0x_1234567890ABCDEF_u64;
6243 println!("K =\t{:#016X}", key);
6244 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6245
6246 let message = "In the beginning God created the heavens and the earth.";
6247 println!("M =\t{}", message);
6248 let mut cipher = [0_u8; 56];
6249 a_des.encrypt_str_into_array(&message, &mut cipher);
6250 print!("C (128 rounds) =\t");
6251 for c in cipher.clone()
6252 { print!("{:02X} ", c); }
6253 println!();
6254 let mut txt = String::new();
6255 for c in cipher.clone()
6256 { write!(txt, "{:02X} ", c); }
6257 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 22 62 41 CF 85 0E E5 3F ");
6258
6259 let mut recovered = String::new();
6260 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6261 println!("B (128 rounds) =\t{}", recovered);
6262 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6263 assert_eq!(recovered, message);
6264 println!();
6265
6266 // Expanded case for 0 rounds which means that key is meaningless
6267 let key1 = 0x_1234567890ABCDEF_u64;
6268 let key2 = 0_u64;
6269 println!("K =\t{:#016X}", key);
6270 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6271 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6272
6273 let message = "In the beginning God created the heavens and the earth.";
6274 println!("M =\t{}", message);
6275 let mut cipher1 = [0_u8; 56];
6276 let mut cipher2 = [0_u8; 56];
6277 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
6278 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
6279 print!("C (0 rounds) =\t");
6280 for c in cipher1.clone()
6281 { print!("{:02X} ", c); }
6282 println!();
6283 let mut txt = String::new();
6284 for c in cipher1.clone()
6285 { write!(txt, "{:02X} ", c); }
6286 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
6287 print!("D (0 rounds) =\t");
6288 for c in cipher2.clone()
6289 { print!("{:02X} ", c); }
6290 println!();
6291 let mut txt = String::new();
6292 for c in cipher2.clone()
6293 { write!(txt, "{:02X} ", c); }
6294 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 40 ");
6295
6296 let mut recovered1 = String::new();
6297 let mut recovered2 = String::new();
6298 c_des.decrypt_array_into_string(&cipher1, &mut recovered1);
6299 d_des.decrypt_array_into_string(&cipher2, &mut recovered2);
6300 println!("B1 (0 rounds) =\t{}", recovered1);
6301 println!("B2 (0 rounds) =\t{}", recovered2);
6302 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6303 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6304 assert_eq!(recovered1, message);
6305 assert_eq!(recovered2, message);
6306 assert_eq!(recovered1, recovered2);
6307 println!();
6308
6309 // Normal case for the message of 0 bytes
6310 let key = 0x_1234567890ABCDEF_u64;
6311 println!("K =\t{:#016X}", key);
6312 let mut a_des = DES::new_with_key_u64(key);
6313
6314 let message = "";
6315 println!("M =\t{}", message);
6316 let mut cipher = [0_u8; 8];
6317 a_des.encrypt_str_into_array(&message, &mut cipher);
6318 print!("C =\t");
6319 for c in cipher.clone()
6320 { print!("{:02X} ", c); }
6321 println!();
6322 let mut txt = String::new();
6323 for c in cipher.clone()
6324 { write!(txt, "{:02X} ", c); }
6325 assert_eq!(txt, "E2 22 32 FE 87 E8 0A 93 ");
6326
6327 let mut recovered = String::new();
6328 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6329 println!("B =\t{}", recovered);
6330 assert_eq!(recovered, "");
6331 assert_eq!(recovered, message);
6332 println!();
6333
6334 // Normal case for the message shorter than 8 bytes
6335 let key = 0x_1234567890ABCDEF_u64;
6336 println!("K =\t{:#016X}", key);
6337 let mut a_des = DES::new_with_key_u64(key);
6338
6339 let message = "7 bytes";
6340 println!("M =\t{}", message);
6341 let mut cipher = [0_u8; 8];
6342 a_des.encrypt_str_into_array(&message, &mut cipher);
6343 print!("C =\t");
6344 for c in cipher.clone()
6345 { print!("{:02X} ", c); }
6346 println!();
6347 let mut txt = String::new();
6348 for c in cipher.clone()
6349 { write!(txt, "{:02X} ", c); }
6350 assert_eq!(txt, "ED 30 F1 06 B7 E3 E7 07 ");
6351
6352 let mut recovered = String::new();
6353 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6354 println!("B =\t{}", recovered);
6355 assert_eq!(recovered, "7 bytes");
6356 assert_eq!(recovered, message);
6357 println!();
6358
6359 // Normal case for the message of 8 bytes
6360 let key = 0x_1234567890ABCDEF_u64;
6361 println!("K =\t{:#016X}", key);
6362 let mut a_des = DES::new_with_key_u64(key);
6363
6364 let message = "I am OK.";
6365 println!("M =\t{}", message);
6366 let mut cipher = [0_u8; 16];
6367 a_des.encrypt_str_into_array(&message, &mut cipher);
6368 print!("C =\t");
6369 for c in cipher.clone()
6370 { print!("{:02X} ", c); }
6371 println!();
6372 let mut txt = String::new();
6373 for c in cipher.clone()
6374 { write!(txt, "{:02X} ", c); }
6375 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 E2 22 32 FE 87 E8 0A 93 ");
6376
6377 let mut recovered = String::new();
6378 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6379 println!("B =\t{}", recovered);
6380 assert_eq!(recovered, "I am OK.");
6381 assert_eq!(recovered, message);
6382 println!();
6383
6384 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6385 let key = 0x_1234567890ABCDEF_u64;
6386 println!("K =\t{:#016X}", key);
6387 let mut a_des = DES::new_with_key_u64(key);
6388
6389 let message = "PARK Youngho";
6390 println!("M =\t{}", message);
6391 let mut cipher = [0_u8; 16];
6392 a_des.encrypt_str_into_array(&message, &mut cipher);
6393 print!("C =\t");
6394 for c in cipher.clone()
6395 { print!("{:02X} ", c); }
6396 println!();
6397 let mut txt = String::new();
6398 for c in cipher.clone()
6399 { write!(txt, "{:02X} ", c); }
6400 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 BB 55 6A 78 71 84 72 58 ");
6401
6402 let mut recovered = String::new();
6403 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6404 println!("B =\t{}", recovered);
6405 assert_eq!(recovered, "PARK Youngho");
6406 assert_eq!(recovered, message);
6407 println!();
6408
6409 // Normal case for the message of 16 bytes
6410 let key = 0x_1234567890ABCDEF_u64;
6411 println!("K =\t{:#016X}", key);
6412 let mut a_des = DES::new_with_key_u64(key);
6413
6414 let message = "고맙습니다.";
6415 println!("M =\t{}", message);
6416 let mut cipher = [0_u8; 24];
6417 a_des.encrypt_str_into_array(&message, &mut cipher);
6418 print!("C =\t");
6419 for c in cipher.clone()
6420 { print!("{:02X} ", c); }
6421 println!();
6422 let mut txt = String::new();
6423 for c in cipher.clone()
6424 { write!(txt, "{:02X} ", c); }
6425 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 E2 22 32 FE 87 E8 0A 93 ");
6426
6427 let mut recovered = String::new();
6428 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6429 println!("B =\t{}", recovered);
6430 assert_eq!(recovered, "고맙습니다.");
6431 assert_eq!(recovered, message);
6432 println!("-------------------------------");
6433}54fn des_encrypt_with_padding_pkcs7_ecb()
55{
56 println!("des_encrypt_with_padding_pkcs7_ecb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
60
61 // Normal case
62 let key = 0x_1234567890ABCDEF_u64;
63 println!("K =\t{:#016X}", key);
64 let mut a_des = DES::new_with_key_u64(key);
65
66 let message = "In the beginning God created the heavens and the earth.";
67 println!("M =\t{}", message);
68 let mut cipher = [0_u8; 56];
69 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
70 print!("C (16 rounds) =\t");
71 for c in cipher.clone()
72 { print!("{:02X} ", c); }
73 println!();
74 let mut txt = String::new();
75 for c in cipher.clone()
76 { write!(txt, "{:02X} ", c); }
77 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
78 println!();
79
80 // Expanded case for 128 rounds
81 let key = 0x_1234567890ABCDEF_u64;
82 println!("K =\t{:#016X}", key);
83 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
84
85 let message = "In the beginning God created the heavens and the earth.";
86 println!("M =\t{}", message);
87 let mut cipher = [0_u8; 56];
88 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
89 print!("C (128 rounds) =\t");
90 for c in cipher.clone()
91 { print!("{:02X} ", c); }
92 println!();
93 let mut txt = String::new();
94 for c in cipher.clone()
95 { write!(txt, "{:02X} ", c); }
96 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
97 println!();
98
99 // Expanded case for 0 rounds which means that key is meaningless
100 let key1 = 0x_1234567890ABCDEF_u64;
101 let key2 = 0_u64;
102 println!("K =\t{:#016X}", key);
103 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
104 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
105
106 let message = "In the beginning God created the heavens and the earth.";
107 println!("M =\t{}", message);
108 let mut cipher1 = [0_u8; 56];
109 let mut cipher2 = [0_u8; 56];
110 c_des.encrypt(message.as_ptr(), message.len() as u64, cipher1.as_mut_ptr());
111 d_des.encrypt(message.as_ptr(), message.len() as u64, cipher2.as_mut_ptr());
112 print!("C (0 rounds) =\t");
113 for c in cipher1.clone()
114 { print!("{:02X} ", c); }
115 println!();
116 let mut txt = String::new();
117 for c in cipher1.clone()
118 { write!(txt, "{:02X} ", c); }
119 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
120 print!("D (0 rounds) =\t");
121 for c in cipher2.clone()
122 { print!("{:02X} ", c); }
123 println!();
124 let mut txt = String::new();
125 for c in cipher2.clone()
126 { write!(txt, "{:02X} ", c); }
127 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
128 println!();
129
130 // Normal case for the message of 0 bytes
131 let key = 0x_1234567890ABCDEF_u64;
132 println!("K =\t{:#016X}", key);
133 let mut a_des = DES::new_with_key_u64(key);
134
135 let message = "";
136 println!("M =\t{}", message);
137 let mut cipher = [0_u8; 8];
138 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
139 print!("C =\t");
140 for c in cipher.clone()
141 { print!("{:02X} ", c); }
142 println!();
143 let mut txt = String::new();
144 for c in cipher.clone()
145 { write!(txt, "{:02X} ", c); }
146 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
147 println!();
148
149 // Normal case for the message shorter than 8 bytes
150 let key = 0x_1234567890ABCDEF_u64;
151 println!("K =\t{:#016X}", key);
152 let mut a_des = DES::new_with_key_u64(key);
153
154 let message = "7 bytes";
155 println!("M =\t{}", message);
156 let mut cipher = [0_u8; 8];
157 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
158 print!("C =\t");
159 for c in cipher.clone()
160 { print!("{:02X} ", c); }
161 println!();
162 let mut txt = String::new();
163 for c in cipher.clone()
164 { write!(txt, "{:02X} ", c); }
165 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
166 println!();
167
168 // Normal case for the message of 8 bytes
169 let key = 0x_1234567890ABCDEF_u64;
170 println!("K =\t{:#016X}", key);
171 let mut a_des = DES::new_with_key_u64(key);
172
173 let message = "I am OK.";
174 println!("M =\t{}", message);
175 let mut cipher = [0_u8; 16];
176 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
177 print!("C =\t");
178 for c in cipher.clone()
179 { print!("{:02X} ", c); }
180 println!();
181 let mut txt = String::new();
182 for c in cipher.clone()
183 { write!(txt, "{:02X} ", c); }
184 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
185 println!();
186
187 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
188 let key = 0x_1234567890ABCDEF_u64;
189 println!("K =\t{:#016X}", key);
190 let mut a_des = DES::new_with_key_u64(key);
191
192 let message = "PARK Youngho";
193 println!("M =\t{}", message);
194 let mut cipher = [0_u8; 16];
195 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
196 print!("C =\t");
197 for c in cipher.clone()
198 { print!("{:02X} ", c); }
199 println!();
200 let mut txt = String::new();
201 for c in cipher.clone()
202 { write!(txt, "{:02X} ", c); }
203 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
204 println!();
205
206
207 // Normal case for the message of 16 bytes
208 let key = 0x_1234567890ABCDEF_u64;
209 println!("K =\t{:#016X}", key);
210 let mut a_des = DES::new_with_key_u64(key);
211
212 let message = "고맙습니다.";
213 println!("M =\t{}", message);
214 let mut cipher = [0_u8; 24];
215 a_des.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
216 print!("C =\t");
217 for c in cipher.clone()
218 { print!("{:02X} ", c); }
219 println!();
220 let mut txt = String::new();
221 for c in cipher.clone()
222 { write!(txt, "{:02X} ", c); }
223 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
224 println!("-------------------------------");
225}
226
227fn des_encrypt_with_padding_pkcs7_ecb_into_vec()
228{
229 println!("des_encrypt_with_padding_pkcs7_ecb_into_vec()");
230 use std::io::Write;
231 use std::fmt::Write as _;
232 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
233
234 // Normal case
235 let key = 0x_1234567890ABCDEF_u64;
236 println!("K =\t{:#016X}", key);
237 let mut a_des = DES::new_with_key_u64(key);
238
239 let message = "In the beginning God created the heavens and the earth.";
240 println!("M =\t{}", message);
241 let mut cipher = Vec::<u8>::new();
242 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
243 print!("C (16 rounds) =\t");
244 for c in cipher.clone()
245 { print!("{:02X} ", c); }
246 println!();
247 let mut txt = String::new();
248 for c in cipher.clone()
249 { write!(txt, "{:02X} ", c); }
250 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
251 println!();
252
253 // Expanded case for 128 rounds
254 let key = 0x_1234567890ABCDEF_u64;
255 println!("K =\t{:#016X}", key);
256 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
257
258 let message = "In the beginning God created the heavens and the earth.";
259 println!("M =\t{}", message);
260 let mut cipher = Vec::<u8>::new();
261 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
262 print!("C (128 rounds) =\t");
263 for c in cipher.clone()
264 { print!("{:02X} ", c); }
265 println!();
266 let mut txt = String::new();
267 for c in cipher.clone()
268 { write!(txt, "{:02X} ", c); }
269 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
270 println!();
271
272 // Expanded case for 0 rounds which means that key is meaningless
273 let key1 = 0x_1234567890ABCDEF_u64;
274 let key2 = 0_u64;
275 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
276 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
277 println!("K =\t{:#016X}", key);
278
279 let message = "In the beginning God created the heavens and the earth.";
280 println!("M =\t{}", message);
281 let mut cipher1 = Vec::<u8>::new();
282 let mut cipher2 = Vec::<u8>::new();
283 c_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher1);
284 d_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher2);
285 print!("C (0 rounds) =\t");
286 for c in cipher1.clone()
287 { print!("{:02X} ", c); }
288 println!();
289 let mut txt = String::new();
290 for c in cipher1.clone()
291 { write!(txt, "{:02X} ", c); }
292 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
293 print!("D (0 rounds) =\t");
294 for c in cipher2.clone()
295 { print!("{:02X} ", c); }
296 println!();
297 let mut txt = String::new();
298 for c in cipher2.clone()
299 { write!(txt, "{:02X} ", c); }
300 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
301 println!();
302
303 // Normal case for the message of 0 bytes
304 let key = 0x_1234567890ABCDEF_u64;
305 println!("K =\t{:#016X}", key);
306 let mut a_des = DES::new_with_key_u64(key);
307
308 let message = "";
309 println!("M =\t{}", message);
310 let mut cipher = Vec::<u8>::new();
311 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
312 print!("C =\t");
313 for c in cipher.clone()
314 { print!("{:02X} ", c); }
315 println!();
316 let mut txt = String::new();
317 for c in cipher.clone()
318 { write!(txt, "{:02X} ", c); }
319 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
320 println!();
321
322 // Normal case for the message shorter than 8 bytes
323 let key = 0x_1234567890ABCDEF_u64;
324 println!("K =\t{:#016X}", key);
325 let mut a_des = DES::new_with_key_u64(key);
326
327 let message = "7 bytes";
328 println!("M =\t{}", message);
329 let mut cipher = Vec::<u8>::new();
330 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
331 print!("C =\t");
332 for c in cipher.clone()
333 { print!("{:02X} ", c); }
334 println!();
335 let mut txt = String::new();
336 for c in cipher.clone()
337 { write!(txt, "{:02X} ", c); }
338 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
339 println!();
340
341 // Normal case for the message of 8 bytes
342 let key = 0x_1234567890ABCDEF_u64;
343 println!("K =\t{:#016X}", key);
344 let mut a_des = DES::new_with_key_u64(key);
345
346 let message = "I am OK.";
347 println!("M =\t{}", message);
348 let mut cipher = Vec::<u8>::new();
349 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
350 print!("C =\t");
351 for c in cipher.clone()
352 { print!("{:02X} ", c); }
353 println!();
354 let mut txt = String::new();
355 for c in cipher.clone()
356 { write!(txt, "{:02X} ", c); }
357 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
358 println!();
359
360 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
361 let key = 0x_1234567890ABCDEF_u64;
362 println!("K =\t{:#016X}", key);
363 let mut a_des = DES::new_with_key_u64(key);
364
365 let message = "PARK Youngho";
366 println!("M =\t{}", message);
367 let mut cipher = Vec::<u8>::new();
368 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
369 print!("C =\t");
370 for c in cipher.clone()
371 { print!("{:02X} ", c); }
372 println!();
373 let mut txt = String::new();
374 for c in cipher.clone()
375 { write!(txt, "{:02X} ", c); }
376 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
377 println!();
378
379 // Normal case for the message of 16 bytes
380 let key = 0x_1234567890ABCDEF_u64;
381 println!("K =\t{:#016X}", key);
382 let mut a_des = DES::new_with_key_u64(key);
383
384 let message = "고맙습니다.";
385 println!("M =\t{}", message);
386 let mut cipher = Vec::<u8>::new();
387 a_des.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
388 print!("C =\t");
389 for c in cipher.clone()
390 { print!("{:02X} ", c); }
391 println!();
392 let mut txt = String::new();
393 for c in cipher.clone()
394 { write!(txt, "{:02X} ", c); }
395 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
396 println!("-------------------------------");
397}
398
399fn des_encrypt_with_padding_pkcs7_ecb_into_array()
400{
401 println!("des_encrypt_with_padding_pkcs7_ecb_into_array()");
402 use std::io::Write;
403 use std::fmt::Write as _;
404 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
405
406 // Normal case
407 let key = 0x_1234567890ABCDEF_u64;
408 println!("K =\t{:#016X}", key);
409 let mut a_des = DES::new_with_key_u64(key);
410
411 let message = "In the beginning God created the heavens and the earth.";
412 println!("M =\t{}", message);
413 let mut cipher = [0_u8; 56];
414 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
415 print!("C (16 rounds) =\t");
416 for c in cipher.clone()
417 { print!("{:02X} ", c); }
418 println!();
419 let mut txt = String::new();
420 for c in cipher.clone()
421 { write!(txt, "{:02X} ", c); }
422 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
423 println!();
424
425 // Expanded case for 128 rounds
426 let key = 0x_1234567890ABCDEF_u64;
427 println!("K =\t{:#016X}", key);
428 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
429
430 let message = "In the beginning God created the heavens and the earth.";
431 println!("M =\t{}", message);
432 let mut cipher = [0_u8; 56];
433 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
434 print!("C (128 rounds) =\t");
435 for c in cipher.clone()
436 { print!("{:02X} ", c); }
437 println!();
438 let mut txt = String::new();
439 for c in cipher.clone()
440 { write!(txt, "{:02X} ", c); }
441 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
442 println!();
443
444 // Expanded case for 0 rounds which means that key is meaningless
445 let key1 = 0x_1234567890ABCDEF_u64;
446 let key2 = 0_u64;
447 println!("K =\t{:#016X}", key);
448 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
449 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
450
451 let message = "In the beginning God created the heavens and the earth.";
452 println!("M =\t{}", message);
453 let mut cipher1 = [0_u8; 56];
454 let mut cipher2 = [0_u8; 56];
455 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
456 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
457 print!("C (0 rounds) =\t");
458 for c in cipher1.clone()
459 { print!("{:02X} ", c); }
460 println!();
461 let mut txt = String::new();
462 for c in cipher1.clone()
463 { write!(txt, "{:02X} ", c); }
464 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
465 print!("D (0 rounds) =\t");
466 for c in cipher2.clone()
467 { print!("{:02X} ", c); }
468 println!();
469 let mut txt = String::new();
470 for c in cipher2.clone()
471 { write!(txt, "{:02X} ", c); }
472 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
473 println!();
474
475 // Normal case for the message of 0 bytes
476 let key = 0x_1234567890ABCDEF_u64;
477 println!("K =\t{:#016X}", key);
478 let mut a_des = DES::new_with_key_u64(key);
479
480 let message = "";
481 println!("M =\t{}", message);
482 let mut cipher = [0_u8; 8];
483 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
484 print!("C =\t");
485 for c in cipher.clone()
486 { print!("{:02X} ", c); }
487 println!();
488 let mut txt = String::new();
489 for c in cipher.clone()
490 { write!(txt, "{:02X} ", c); }
491 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
492 println!();
493
494 // Normal case for the message shorter than 8 bytes
495 let key = 0x_1234567890ABCDEF_u64;
496 println!("K =\t{:#016X}", key);
497 let mut a_des = DES::new_with_key_u64(key);
498
499 let message = "7 bytes";
500 println!("M =\t{}", message);
501 let mut cipher = [0_u8; 8];
502 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
503 print!("C =\t");
504 for c in cipher.clone()
505 { print!("{:02X} ", c); }
506 println!();
507 let mut txt = String::new();
508 for c in cipher.clone()
509 { write!(txt, "{:02X} ", c); }
510 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
511 println!();
512
513 // Normal case for the message of 8 bytes
514 let key = 0x_1234567890ABCDEF_u64;
515 println!("K =\t{:#016X}", key);
516 let mut a_des = DES::new_with_key_u64(key);
517
518 let message = "I am OK.";
519 println!("M =\t{}", message);
520 let mut cipher = [0_u8; 16];
521 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
522 print!("C =\t");
523 for c in cipher.clone()
524 { print!("{:02X} ", c); }
525 println!();
526 let mut txt = String::new();
527 for c in cipher.clone()
528 { write!(txt, "{:02X} ", c); }
529 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
530 println!();
531
532 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
533 let key = 0x_1234567890ABCDEF_u64;
534 println!("K =\t{:#016X}", key);
535 let mut a_des = DES::new_with_key_u64(key);
536
537 let message = "PARK Youngho";
538 println!("M =\t{}", message);
539 let mut cipher = [0_u8; 16];
540 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
541 print!("C =\t");
542 for c in cipher.clone()
543 { print!("{:02X} ", c); }
544 println!();
545 let mut txt = String::new();
546 for c in cipher.clone()
547 { write!(txt, "{:02X} ", c); }
548 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
549 println!();
550
551
552 // Normal case for the message of 16 bytes
553 let key = 0x_1234567890ABCDEF_u64;
554 println!("K =\t{:#016X}", key);
555 let mut a_des = DES::new_with_key_u64(key);
556
557 let message = "고맙습니다.";
558 println!("M =\t{}", message);
559 let mut cipher = [0_u8; 24];
560 a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
561 print!("C =\t");
562 for c in cipher.clone()
563 { print!("{:02X} ", c); }
564 println!();
565 let mut txt = String::new();
566 for c in cipher.clone()
567 { write!(txt, "{:02X} ", c); }
568 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
569 println!("-------------------------------");
570}
571
572fn des_encrypt_str_with_padding_pkcs7_ecb()
573{
574 println!("des_encrypt_str_with_padding_pkcs7_ecb()");
575 use std::io::Write;
576 use std::fmt::Write as _;
577 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
578
579 // Normal case
580 let key = 0x_1234567890ABCDEF_u64;
581 println!("K =\t{:#016X}", key);
582 let mut a_des = DES::new_with_key_u64(key);
583
584 let message = "In the beginning God created the heavens and the earth.";
585 println!("M =\t{}", message);
586 let mut cipher = [0_u8; 56];
587 a_des.encrypt_str(&message, cipher.as_mut_ptr());
588 print!("C (16 rounds) =\t");
589 for c in cipher.clone()
590 { print!("{:02X} ", c); }
591 println!();
592 let mut txt = String::new();
593 for c in cipher.clone()
594 { write!(txt, "{:02X} ", c); }
595 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
596 println!();
597
598 // Expanded case for 128 rounds
599 let key = 0x_1234567890ABCDEF_u64;
600 println!("K =\t{:#016X}", key);
601 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
602
603 let message = "In the beginning God created the heavens and the earth.";
604 println!("M =\t{}", message);
605 let mut cipher = [0_u8; 56];
606 a_des.encrypt_str(&message, cipher.as_mut_ptr());
607 print!("C (128 rounds) =\t");
608 for c in cipher.clone()
609 { print!("{:02X} ", c); }
610 println!();
611 let mut txt = String::new();
612 for c in cipher.clone()
613 { write!(txt, "{:02X} ", c); }
614 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
615 println!();
616
617 // Expanded case for 0 rounds which means that key is meaningless
618 let key1 = 0x_1234567890ABCDEF_u64;
619 let key2 = 0_u64;
620 println!("K =\t{:#016X}", key);
621 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
622 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
623
624 let message = "In the beginning God created the heavens and the earth.";
625 println!("M =\t{}", message);
626 let mut cipher1 = [0_u8; 56];
627 let mut cipher2 = [0_u8; 56];
628 c_des.encrypt_str(&message, cipher1.as_mut_ptr());
629 d_des.encrypt_str(&message, cipher2.as_mut_ptr());
630 print!("C (0 rounds) =\t");
631 for c in cipher1.clone()
632 { print!("{:02X} ", c); }
633 println!();
634 let mut txt = String::new();
635 for c in cipher1.clone()
636 { write!(txt, "{:02X} ", c); }
637 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
638 print!("D (0 rounds) =\t");
639 for c in cipher2.clone()
640 { print!("{:02X} ", c); }
641 println!();
642 let mut txt = String::new();
643 for c in cipher2.clone()
644 { write!(txt, "{:02X} ", c); }
645 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
646 println!();
647
648 // Normal case for the message of 0 bytes
649 let key = 0x_1234567890ABCDEF_u64;
650 println!("K =\t{:#016X}", key);
651 let mut a_des = DES::new_with_key_u64(key);
652
653 let message = "";
654 println!("M =\t{}", message);
655 let mut cipher = [0_u8; 8];
656 a_des.encrypt_str(&message, cipher.as_mut_ptr());
657 print!("C =\t");
658 for c in cipher.clone()
659 { print!("{:02X} ", c); }
660 println!();
661 let mut txt = String::new();
662 for c in cipher.clone()
663 { write!(txt, "{:02X} ", c); }
664 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
665 println!();
666
667 // Normal case for the message shorter than 8 bytes
668 let key = 0x_1234567890ABCDEF_u64;
669 println!("K =\t{:#016X}", key);
670 let mut a_des = DES::new_with_key_u64(key);
671
672 let message = "7 bytes";
673 println!("M =\t{}", message);
674 let mut cipher = [0_u8; 8];
675 a_des.encrypt_str(&message, cipher.as_mut_ptr());
676 print!("C =\t");
677 for c in cipher.clone()
678 { print!("{:02X} ", c); }
679 println!();
680 let mut txt = String::new();
681 for c in cipher.clone()
682 { write!(txt, "{:02X} ", c); }
683 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
684 println!();
685
686 // Normal case for the message of 8 bytes
687 let key = 0x_1234567890ABCDEF_u64;
688 println!("K =\t{:#016X}", key);
689 let mut a_des = DES::new_with_key_u64(key);
690
691 let message = "I am OK.";
692 println!("M =\t{}", message);
693 let mut cipher = [0_u8; 16];
694 a_des.encrypt_str(&message, cipher.as_mut_ptr());
695 print!("C =\t");
696 for c in cipher.clone()
697 { print!("{:02X} ", c); }
698 println!();
699 let mut txt = String::new();
700 for c in cipher.clone()
701 { write!(txt, "{:02X} ", c); }
702 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
703 println!();
704
705 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
706 let key = 0x_1234567890ABCDEF_u64;
707 println!("K =\t{:#016X}", key);
708 let mut a_des = DES::new_with_key_u64(key);
709
710 let message = "PARK Youngho";
711 println!("M =\t{}", message);
712 let mut cipher = [0_u8; 16];
713 a_des.encrypt_str(&message, cipher.as_mut_ptr());
714 print!("C =\t");
715 for c in cipher.clone()
716 { print!("{:02X} ", c); }
717 println!();
718 let mut txt = String::new();
719 for c in cipher.clone()
720 { write!(txt, "{:02X} ", c); }
721 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
722 println!();
723
724
725 // Normal case for the message of 16 bytes
726 let key = 0x_1234567890ABCDEF_u64;
727 println!("K =\t{:#016X}", key);
728 let mut a_des = DES::new_with_key_u64(key);
729
730 let message = "고맙습니다.";
731 println!("M =\t{}", message);
732 let mut cipher = [0_u8; 24];
733 a_des.encrypt_str(&message, cipher.as_mut_ptr());
734 print!("C =\t");
735 for c in cipher.clone()
736 { print!("{:02X} ", c); }
737 println!();
738 let mut txt = String::new();
739 for c in cipher.clone()
740 { write!(txt, "{:02X} ", c); }
741 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
742 println!("-------------------------------");
743}
744
745fn des_encrypt_str_with_padding_pkcs7_ecb_into_vec()
746{
747 println!("des_encrypt_str_with_padding_pkcs7_ecb_into_vec()");
748 use std::io::Write;
749 use std::fmt::Write as _;
750 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
751
752 // Normal case
753 let key = 0x_1234567890ABCDEF_u64;
754 println!("K =\t{:#016X}", key);
755 let mut a_des = DES::new_with_key_u64(key);
756
757 let message = "In the beginning God created the heavens and the earth.";
758 println!("M =\t{}", message);
759 let mut cipher = Vec::<u8>::new();
760 a_des.encrypt_str_into_vec(&message, &mut cipher);
761 print!("C (16 rounds) =\t");
762 for c in cipher.clone()
763 { print!("{:02X} ", c); }
764 println!();
765 let mut txt = String::new();
766 for c in cipher.clone()
767 { write!(txt, "{:02X} ", c); }
768 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
769 println!();
770
771 // Expanded case for 128 rounds
772 let key = 0x_1234567890ABCDEF_u64;
773 println!("K =\t{:#016X}", key);
774 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
775
776 let message = "In the beginning God created the heavens and the earth.";
777 println!("M =\t{}", message);
778 let mut cipher = Vec::<u8>::new();
779 a_des.encrypt_str_into_vec(&message, &mut cipher);
780 print!("C (128 rounds) =\t");
781 for c in cipher.clone()
782 { print!("{:02X} ", c); }
783 println!();
784 let mut txt = String::new();
785 for c in cipher.clone()
786 { write!(txt, "{:02X} ", c); }
787 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
788 println!();
789
790 // Expanded case for 0 rounds which means that key is meaningless
791 let key1 = 0x_1234567890ABCDEF_u64;
792 let key2 = 0_u64;
793 println!("K =\t{:#016X}", key);
794 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
795 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
796
797 let message = "In the beginning God created the heavens and the earth.";
798 println!("M =\t{}", message);
799 let mut cipher1 = Vec::<u8>::new();
800 let mut cipher2 = Vec::<u8>::new();
801 c_des.encrypt_str_into_vec(&message, &mut cipher1);
802 d_des.encrypt_str_into_vec(&message, &mut cipher2);
803 print!("C (0 rounds) =\t");
804 for c in cipher1.clone()
805 { print!("{:02X} ", c); }
806 println!();
807 let mut txt = String::new();
808 for c in cipher1.clone()
809 { write!(txt, "{:02X} ", c); }
810 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
811 print!("D (0 rounds) =\t");
812 for c in cipher2.clone()
813 { print!("{:02X} ", c); }
814 println!();
815 let mut txt = String::new();
816 for c in cipher2.clone()
817 { write!(txt, "{:02X} ", c); }
818 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
819 println!();
820
821 // Normal case for the message of 0 bytes
822 let key = 0x_1234567890ABCDEF_u64;
823 println!("K =\t{:#016X}", key);
824 let mut a_des = DES::new_with_key_u64(key);
825
826 let message = "";
827 println!("M =\t{}", message);
828 let mut cipher = Vec::<u8>::new();
829 a_des.encrypt_str_into_vec(&message, &mut cipher);
830 print!("C =\t");
831 for c in cipher.clone()
832 { print!("{:02X} ", c); }
833 println!();
834 let mut txt = String::new();
835 for c in cipher.clone()
836 { write!(txt, "{:02X} ", c); }
837 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
838 println!();
839
840 // Normal case for the message shorter than 8 bytes
841 let key = 0x_1234567890ABCDEF_u64;
842 println!("K =\t{:#016X}", key);
843 let mut a_des = DES::new_with_key_u64(key);
844
845 let message = "7 bytes";
846 println!("M =\t{}", message);
847 let mut cipher = Vec::<u8>::new();
848 a_des.encrypt_str_into_vec(&message, &mut cipher);
849 print!("C =\t");
850 for c in cipher.clone()
851 { print!("{:02X} ", c); }
852 println!();
853 let mut txt = String::new();
854 for c in cipher.clone()
855 { write!(txt, "{:02X} ", c); }
856 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
857 println!();
858
859 // Normal case for the message of 8 bytes
860 let key = 0x_1234567890ABCDEF_u64;
861 println!("K =\t{:#016X}", key);
862 let mut a_des = DES::new_with_key_u64(key);
863
864 let message = "I am OK.";
865 println!("M =\t{}", message);
866 let mut cipher = Vec::<u8>::new();
867 a_des.encrypt_str_into_vec(&message, &mut cipher);
868 print!("C =\t");
869 for c in cipher.clone()
870 { print!("{:02X} ", c); }
871 println!();
872 let mut txt = String::new();
873 for c in cipher.clone()
874 { write!(txt, "{:02X} ", c); }
875 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
876 println!();
877
878 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
879 let key = 0x_1234567890ABCDEF_u64;
880 println!("K =\t{:#016X}", key);
881 let mut a_des = DES::new_with_key_u64(key);
882
883 let message = "PARK Youngho";
884 println!("M =\t{}", message);
885 let mut cipher = Vec::<u8>::new();
886 a_des.encrypt_str_into_vec(&message, &mut cipher);
887 print!("C =\t");
888 for c in cipher.clone()
889 { print!("{:02X} ", c); }
890 println!();
891 let mut txt = String::new();
892 for c in cipher.clone()
893 { write!(txt, "{:02X} ", c); }
894 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
895 println!();
896
897
898 // Normal case for the message of 16 bytes
899 let key = 0x_1234567890ABCDEF_u64;
900 println!("K =\t{:#016X}", key);
901 let mut a_des = DES::new_with_key_u64(key);
902
903 let message = "고맙습니다.";
904 println!("M =\t{}", message);
905 let mut cipher = Vec::<u8>::new();
906 a_des.encrypt_str_into_vec(&message, &mut cipher);
907 print!("C =\t");
908 for c in cipher.clone()
909 { print!("{:02X} ", c); }
910 println!();
911 let mut txt = String::new();
912 for c in cipher.clone()
913 { write!(txt, "{:02X} ", c); }
914 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
915 println!("-------------------------------");
916}
917
918fn des_encrypt_str_with_padding_pkcs7_ecb_into_array()
919{
920 println!("des_encrypt_str_with_padding_pkcs7_ecb_into_array()");
921 use std::io::Write;
922 use std::fmt::Write as _;
923 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
924
925 // Normal case
926 let key = 0x_1234567890ABCDEF_u64;
927 println!("K =\t{:#016X}", key);
928 let mut a_des = DES::new_with_key_u64(key);
929
930 let message = "In the beginning God created the heavens and the earth.";
931 println!("M =\t{}", message);
932 let mut cipher = [0_u8; 56];
933 a_des.encrypt_str_into_array(&message, &mut cipher);
934 print!("C (16 rounds) =\t");
935 for c in cipher.clone()
936 { print!("{:02X} ", c); }
937 println!();
938 let mut txt = String::new();
939 for c in cipher.clone()
940 { write!(txt, "{:02X} ", c); }
941 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
942 println!();
943
944 // Expanded case for 128 rounds
945 let key = 0x_1234567890ABCDEF_u64;
946 println!("K =\t{:#016X}", key);
947 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
948
949 let message = "In the beginning God created the heavens and the earth.";
950 println!("M =\t{}", message);
951 let mut cipher = [0_u8; 56];
952 a_des.encrypt_str_into_array(&message, &mut cipher);
953 print!("C (128 rounds) =\t");
954 for c in cipher.clone()
955 { print!("{:02X} ", c); }
956 println!();
957 let mut txt = String::new();
958 for c in cipher.clone()
959 { write!(txt, "{:02X} ", c); }
960 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
961 println!();
962
963 // Expanded case for 0 rounds which means that key is meaningless
964 let key1 = 0x_1234567890ABCDEF_u64;
965 let key2 = 0_u64;
966 println!("K =\t{:#016X}", key);
967 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
968 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
969
970 let message = "In the beginning God created the heavens and the earth.";
971 println!("M =\t{}", message);
972 let mut cipher1 = [0_u8; 56];
973 let mut cipher2 = [0_u8; 56];
974 c_des.encrypt_str_into_array(&message, &mut cipher1);
975 d_des.encrypt_str_into_array(&message, &mut cipher2);
976 print!("C (0 rounds) =\t");
977 for c in cipher1.clone()
978 { print!("{:02X} ", c); }
979 println!();
980 let mut txt = String::new();
981 for c in cipher1.clone()
982 { write!(txt, "{:02X} ", c); }
983 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
984 print!("D (0 rounds) =\t");
985 for c in cipher2.clone()
986 { print!("{:02X} ", c); }
987 println!();
988 let mut txt = String::new();
989 for c in cipher2.clone()
990 { write!(txt, "{:02X} ", c); }
991 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
992 println!();
993
994 // Normal case for the message of 0 bytes
995 let key = 0x_1234567890ABCDEF_u64;
996 println!("K =\t{:#016X}", key);
997 let mut a_des = DES::new_with_key_u64(key);
998
999 let message = "";
1000 println!("M =\t{}", message);
1001 let mut cipher = [0_u8; 8];
1002 a_des.encrypt_str_into_array(&message, &mut cipher);
1003 print!("C =\t");
1004 for c in cipher.clone()
1005 { print!("{:02X} ", c); }
1006 println!();
1007 let mut txt = String::new();
1008 for c in cipher.clone()
1009 { write!(txt, "{:02X} ", c); }
1010 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
1011 println!();
1012
1013 // Normal case for the message shorter than 8 bytes
1014 let key = 0x_1234567890ABCDEF_u64;
1015 println!("K =\t{:#016X}", key);
1016 let mut a_des = DES::new_with_key_u64(key);
1017
1018 let message = "7 bytes";
1019 println!("M =\t{}", message);
1020 let mut cipher = [0_u8; 8];
1021 a_des.encrypt_str_into_array(&message, &mut cipher);
1022 print!("C =\t");
1023 for c in cipher.clone()
1024 { print!("{:02X} ", c); }
1025 println!();
1026 let mut txt = String::new();
1027 for c in cipher.clone()
1028 { write!(txt, "{:02X} ", c); }
1029 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
1030 println!();
1031
1032 // Normal case for the message of 8 bytes
1033 let key = 0x_1234567890ABCDEF_u64;
1034 println!("K =\t{:#016X}", key);
1035 let mut a_des = DES::new_with_key_u64(key);
1036
1037 let message = "I am OK.";
1038 println!("M =\t{}", message);
1039 let mut cipher = [0_u8; 16];
1040 a_des.encrypt_str_into_array(&message, &mut cipher);
1041 print!("C =\t");
1042 for c in cipher.clone()
1043 { print!("{:02X} ", c); }
1044 println!();
1045 let mut txt = String::new();
1046 for c in cipher.clone()
1047 { write!(txt, "{:02X} ", c); }
1048 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
1049 println!();
1050
1051 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1052 let key = 0x_1234567890ABCDEF_u64;
1053 println!("K =\t{:#016X}", key);
1054 let mut a_des = DES::new_with_key_u64(key);
1055
1056 let message = "PARK Youngho";
1057 println!("M =\t{}", message);
1058 let mut cipher = [0_u8; 16];
1059 a_des.encrypt_str_into_array(&message, &mut cipher);
1060 print!("C =\t");
1061 for c in cipher.clone()
1062 { print!("{:02X} ", c); }
1063 println!();
1064 let mut txt = String::new();
1065 for c in cipher.clone()
1066 { write!(txt, "{:02X} ", c); }
1067 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
1068 println!();
1069
1070
1071 // Normal case for the message of 16 bytes
1072 let key = 0x_1234567890ABCDEF_u64;
1073 println!("K =\t{:#016X}", key);
1074 let mut a_des = DES::new_with_key_u64(key);
1075
1076 let message = "고맙습니다.";
1077 println!("M =\t{}", message);
1078 let mut cipher = [0_u8; 24];
1079 a_des.encrypt_str_into_array(&message, &mut cipher);
1080 print!("C =\t");
1081 for c in cipher.clone()
1082 { print!("{:02X} ", c); }
1083 println!();
1084 let mut txt = String::new();
1085 for c in cipher.clone()
1086 { write!(txt, "{:02X} ", c); }
1087 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
1088 println!("-------------------------------");
1089}
1090
1091fn des_encrypt_string_with_padding_pkcs7_ecb()
1092{
1093 println!("des_encrypt_string_with_padding_pkcs7_ecb()");
1094 use std::io::Write;
1095 use std::fmt::Write as _;
1096 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
1097
1098 // Normal case
1099 let key = 0x_1234567890ABCDEF_u64;
1100 println!("K =\t{:#016X}", key);
1101 let mut a_des = DES::new_with_key_u64(key);
1102
1103 let message = "In the beginning God created the heavens and the earth.".to_string();
1104 println!("M =\t{}", message);
1105 let mut cipher = [0_u8; 56];
1106 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1107 print!("C (16 rounds) =\t");
1108 for c in cipher.clone()
1109 { print!("{:02X} ", c); }
1110 println!();
1111 let mut txt = String::new();
1112 for c in cipher.clone()
1113 { write!(txt, "{:02X} ", c); }
1114 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
1115 println!();
1116
1117 // Expanded case for 128 rounds
1118 let key = 0x_1234567890ABCDEF_u64;
1119 println!("K =\t{:#016X}", key);
1120 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1121
1122 let message = "In the beginning God created the heavens and the earth.".to_string();
1123 println!("M =\t{}", message);
1124 let mut cipher = [0_u8; 56];
1125 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1126 print!("C (128 rounds) =\t");
1127 for c in cipher.clone()
1128 { print!("{:02X} ", c); }
1129 println!();
1130 let mut txt = String::new();
1131 for c in cipher.clone()
1132 { write!(txt, "{:02X} ", c); }
1133 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
1134 println!();
1135
1136 // Expanded case for 0 rounds which means that key is meaningless
1137 let key1 = 0x_1234567890ABCDEF_u64;
1138 let key2 = 0_u64;
1139 println!("K =\t{:#016X}", key);
1140 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1141 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1142
1143 let message = "In the beginning God created the heavens and the earth.".to_string();
1144 println!("M =\t{}", message);
1145 let mut cipher1 = [0_u8; 56];
1146 let mut cipher2 = [0_u8; 56];
1147 c_des.encrypt_string(&message, cipher1.as_mut_ptr());
1148 d_des.encrypt_string(&message, cipher2.as_mut_ptr());
1149 print!("C (0 rounds) =\t");
1150 for c in cipher1.clone()
1151 { print!("{:02X} ", c); }
1152 println!();
1153 let mut txt = String::new();
1154 for c in cipher1.clone()
1155 { write!(txt, "{:02X} ", c); }
1156 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1157 print!("D (0 rounds) =\t");
1158 for c in cipher2.clone()
1159 { print!("{:02X} ", c); }
1160 println!();
1161 let mut txt = String::new();
1162 for c in cipher2.clone()
1163 { write!(txt, "{:02X} ", c); }
1164 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1165 println!();
1166
1167 // Normal case for the message of 0 bytes
1168 let key = 0x_1234567890ABCDEF_u64;
1169 println!("K =\t{:#016X}", key);
1170 let mut a_des = DES::new_with_key_u64(key);
1171
1172 let message = "".to_string();
1173 println!("M =\t{}", message);
1174 let mut cipher = [0_u8; 8];
1175 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1176 print!("C =\t");
1177 for c in cipher.clone()
1178 { print!("{:02X} ", c); }
1179 println!();
1180 let mut txt = String::new();
1181 for c in cipher.clone()
1182 { write!(txt, "{:02X} ", c); }
1183 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
1184 println!();
1185
1186 // Normal case for the message shorter than 8 bytes
1187 let key = 0x_1234567890ABCDEF_u64;
1188 println!("K =\t{:#016X}", key);
1189 let mut a_des = DES::new_with_key_u64(key);
1190
1191 let message = "7 bytes".to_string();
1192 println!("M =\t{}", message);
1193 let mut cipher = [0_u8; 8];
1194 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1195 print!("C =\t");
1196 for c in cipher.clone()
1197 { print!("{:02X} ", c); }
1198 println!();
1199 let mut txt = String::new();
1200 for c in cipher.clone()
1201 { write!(txt, "{:02X} ", c); }
1202 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
1203 println!();
1204
1205 // Normal case for the message of 8 bytes
1206 let key = 0x_1234567890ABCDEF_u64;
1207 println!("K =\t{:#016X}", key);
1208 let mut a_des = DES::new_with_key_u64(key);
1209
1210 let message = "I am OK.".to_string();
1211 println!("M =\t{}", message);
1212 let mut cipher = [0_u8; 16];
1213 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1214 print!("C =\t");
1215 for c in cipher.clone()
1216 { print!("{:02X} ", c); }
1217 println!();
1218 let mut txt = String::new();
1219 for c in cipher.clone()
1220 { write!(txt, "{:02X} ", c); }
1221 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
1222 println!();
1223
1224 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1225 let key = 0x_1234567890ABCDEF_u64;
1226 println!("K =\t{:#016X}", key);
1227 let mut a_des = DES::new_with_key_u64(key);
1228
1229 let message = "PARK Youngho".to_string();
1230 println!("M =\t{}", message);
1231 let mut cipher = [0_u8; 16];
1232 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1233 print!("C =\t");
1234 for c in cipher.clone()
1235 { print!("{:02X} ", c); }
1236 println!();
1237 let mut txt = String::new();
1238 for c in cipher.clone()
1239 { write!(txt, "{:02X} ", c); }
1240 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
1241 println!();
1242
1243
1244 // Normal case for the message of 16 bytes
1245 let key = 0x_1234567890ABCDEF_u64;
1246 println!("K =\t{:#016X}", key);
1247 let mut a_des = DES::new_with_key_u64(key);
1248
1249 let message = "고맙습니다.".to_string();
1250 println!("M =\t{}", message);
1251 let mut cipher = [0_u8; 24];
1252 a_des.encrypt_string(&message, cipher.as_mut_ptr());
1253 print!("C =\t");
1254 for c in cipher.clone()
1255 { print!("{:02X} ", c); }
1256 println!();
1257 let mut txt = String::new();
1258 for c in cipher.clone()
1259 { write!(txt, "{:02X} ", c); }
1260 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
1261 println!("-------------------------------");
1262}
1263
1264fn des_encrypt_string_with_padding_pkcs7_ecb_into_vec()
1265{
1266 println!("des_encrypt_string_with_padding_pkcs7_ecb_into_vec()");
1267 use std::io::Write;
1268 use std::fmt::Write as _;
1269 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
1270
1271 // Normal case
1272 let key = 0x_1234567890ABCDEF_u64;
1273 println!("K =\t{:#016X}", key);
1274 let mut a_des = DES::new_with_key_u64(key);
1275
1276 let message = "In the beginning God created the heavens and the earth.".to_string();
1277 println!("M =\t{}", message);
1278 let mut cipher = Vec::<u8>::new();
1279 a_des.encrypt_string_into_vec(&message, &mut cipher);
1280 print!("C (16 rounds) =\t");
1281 for c in cipher.clone()
1282 { print!("{:02X} ", c); }
1283 println!();
1284 let mut txt = String::new();
1285 for c in cipher.clone()
1286 { write!(txt, "{:02X} ", c); }
1287 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
1288 println!();
1289
1290 // Expanded case for 128 rounds
1291 let key = 0x_1234567890ABCDEF_u64;
1292 println!("K =\t{:#016X}", key);
1293 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1294
1295 let message = "In the beginning God created the heavens and the earth.".to_string();
1296 println!("M =\t{}", message);
1297 let mut cipher = Vec::<u8>::new();
1298 a_des.encrypt_string_into_vec(&message, &mut cipher);
1299 print!("C (128 rounds) =\t");
1300 for c in cipher.clone()
1301 { print!("{:02X} ", c); }
1302 println!();
1303 let mut txt = String::new();
1304 for c in cipher.clone()
1305 { write!(txt, "{:02X} ", c); }
1306 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
1307 println!();
1308
1309 // Expanded case for 0 rounds which means that key is meaningless
1310 let key1 = 0x_1234567890ABCDEF_u64;
1311 let key2 = 0_u64;
1312 println!("K =\t{:#016X}", key);
1313 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1314 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1315
1316 let message = "In the beginning God created the heavens and the earth.".to_string();
1317 println!("M =\t{}", message);
1318 let mut cipher1 = Vec::<u8>::new();
1319 let mut cipher2 = Vec::<u8>::new();
1320 c_des.encrypt_string_into_vec(&message, &mut cipher1);
1321 d_des.encrypt_string_into_vec(&message, &mut cipher2);
1322 print!("C (0 rounds) =\t");
1323 for c in cipher1.clone()
1324 { print!("{:02X} ", c); }
1325 println!();
1326 let mut txt = String::new();
1327 for c in cipher1.clone()
1328 { write!(txt, "{:02X} ", c); }
1329 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1330 print!("D (0 rounds) =\t");
1331 for c in cipher2.clone()
1332 { print!("{:02X} ", c); }
1333 println!();
1334 let mut txt = String::new();
1335 for c in cipher2.clone()
1336 { write!(txt, "{:02X} ", c); }
1337 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1338 println!();
1339
1340 // Normal case for the message of 0 bytes
1341 let key = 0x_1234567890ABCDEF_u64;
1342 println!("K =\t{:#016X}", key);
1343 let mut a_des = DES::new_with_key_u64(key);
1344
1345 let message = "".to_string();
1346 println!("M =\t{}", message);
1347 let mut cipher = Vec::<u8>::new();
1348 a_des.encrypt_string_into_vec(&message, &mut cipher);
1349 print!("C =\t");
1350 for c in cipher.clone()
1351 { print!("{:02X} ", c); }
1352 println!();
1353 let mut txt = String::new();
1354 for c in cipher.clone()
1355 { write!(txt, "{:02X} ", c); }
1356 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
1357 println!();
1358
1359 // Normal case for the message shorter than 8 bytes
1360 let key = 0x_1234567890ABCDEF_u64;
1361 println!("K =\t{:#016X}", key);
1362 let mut a_des = DES::new_with_key_u64(key);
1363
1364 let message = "7 bytes".to_string();
1365 println!("M =\t{}", message);
1366 let mut cipher = Vec::<u8>::new();
1367 a_des.encrypt_string_into_vec(&message, &mut cipher);
1368 print!("C =\t");
1369 for c in cipher.clone()
1370 { print!("{:02X} ", c); }
1371 println!();
1372 let mut txt = String::new();
1373 for c in cipher.clone()
1374 { write!(txt, "{:02X} ", c); }
1375 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
1376 println!();
1377
1378 // Normal case for the message of 8 bytes
1379 let key = 0x_1234567890ABCDEF_u64;
1380 println!("K =\t{:#016X}", key);
1381 let mut a_des = DES::new_with_key_u64(key);
1382
1383 let message = "I am OK.".to_string();
1384 println!("M =\t{}", message);
1385 let mut cipher = Vec::<u8>::new();
1386 a_des.encrypt_string_into_vec(&message, &mut cipher);
1387 print!("C =\t");
1388 for c in cipher.clone()
1389 { print!("{:02X} ", c); }
1390 println!();
1391 let mut txt = String::new();
1392 for c in cipher.clone()
1393 { write!(txt, "{:02X} ", c); }
1394 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
1395 println!();
1396
1397 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1398 let key = 0x_1234567890ABCDEF_u64;
1399 println!("K =\t{:#016X}", key);
1400 let mut a_des = DES::new_with_key_u64(key);
1401
1402 let message = "PARK Youngho".to_string();
1403 println!("M =\t{}", message);
1404 let mut cipher = Vec::<u8>::new();
1405 a_des.encrypt_string_into_vec(&message, &mut cipher);
1406 print!("C =\t");
1407 for c in cipher.clone()
1408 { print!("{:02X} ", c); }
1409 println!();
1410 let mut txt = String::new();
1411 for c in cipher.clone()
1412 { write!(txt, "{:02X} ", c); }
1413 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
1414 println!();
1415
1416
1417 // Normal case for the message of 16 bytes
1418 let key = 0x_1234567890ABCDEF_u64;
1419 println!("K =\t{:#016X}", key);
1420 let mut a_des = DES::new_with_key_u64(key);
1421
1422 let message = "고맙습니다.".to_string();
1423 println!("M =\t{}", message);
1424 let mut cipher = Vec::<u8>::new();
1425 a_des.encrypt_string_into_vec(&message, &mut cipher);
1426 print!("C =\t");
1427 for c in cipher.clone()
1428 { print!("{:02X} ", c); }
1429 println!();
1430 let mut txt = String::new();
1431 for c in cipher.clone()
1432 { write!(txt, "{:02X} ", c); }
1433 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
1434 println!("-------------------------------");
1435}
1436
1437fn des_encrypt_string_with_padding_pkcs7_ecb_into_array()
1438{
1439 println!("des_encrypt_string_with_padding_pkcs7_ecb_into_array()");
1440 use std::io::Write;
1441 use std::fmt::Write as _;
1442 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
1443
1444 // Normal case
1445 let key = 0x_1234567890ABCDEF_u64;
1446 println!("K =\t{:#016X}", key);
1447 let mut a_des = DES::new_with_key_u64(key);
1448
1449 let message = "In the beginning God created the heavens and the earth.".to_string();
1450 println!("M =\t{}", message);
1451 let mut cipher = [0_u8; 56];
1452 a_des.encrypt_string_into_array(&message, &mut cipher);
1453 print!("C (16 rounds) =\t");
1454 for c in cipher.clone()
1455 { print!("{:02X} ", c); }
1456 println!();
1457 let mut txt = String::new();
1458 for c in cipher.clone()
1459 { write!(txt, "{:02X} ", c); }
1460 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
1461 println!();
1462
1463 // Expanded case for 128 rounds
1464 let key = 0x_1234567890ABCDEF_u64;
1465 println!("K =\t{:#016X}", key);
1466 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1467
1468 let message = "In the beginning God created the heavens and the earth.".to_string();
1469 println!("M =\t{}", message);
1470 let mut cipher = [0_u8; 56];
1471 a_des.encrypt_string_into_array(&message, &mut cipher);
1472 print!("C (128 rounds) =\t");
1473 for c in cipher.clone()
1474 { print!("{:02X} ", c); }
1475 println!();
1476 let mut txt = String::new();
1477 for c in cipher.clone()
1478 { write!(txt, "{:02X} ", c); }
1479 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
1480 println!();
1481
1482 // Expanded case for 0 rounds which means that key is meaningless
1483 let key1 = 0x_1234567890ABCDEF_u64;
1484 let key2 = 0_u64;
1485 println!("K =\t{:#016X}", key);
1486 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1487 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1488
1489 let message = "In the beginning God created the heavens and the earth.".to_string();
1490 println!("M =\t{}", message);
1491 let mut cipher1 = [0_u8; 56];
1492 let mut cipher2 = [0_u8; 56];
1493 c_des.encrypt_string_into_array(&message, &mut cipher1);
1494 d_des.encrypt_string_into_array(&message, &mut cipher2);
1495 print!("C (0 rounds) =\t");
1496 for c in cipher1.clone()
1497 { print!("{:02X} ", c); }
1498 println!();
1499 let mut txt = String::new();
1500 for c in cipher1.clone()
1501 { write!(txt, "{:02X} ", c); }
1502 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1503 print!("D (0 rounds) =\t");
1504 for c in cipher2.clone()
1505 { print!("{:02X} ", c); }
1506 println!();
1507 let mut txt = String::new();
1508 for c in cipher2.clone()
1509 { write!(txt, "{:02X} ", c); }
1510 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1511 println!();
1512
1513 // Normal case for the message of 0 bytes
1514 let key = 0x_1234567890ABCDEF_u64;
1515 println!("K =\t{:#016X}", key);
1516 let mut a_des = DES::new_with_key_u64(key);
1517
1518 let message = "".to_string();
1519 println!("M =\t{}", message);
1520 let mut cipher = [0_u8; 8];
1521 a_des.encrypt_string_into_array(&message, &mut cipher);
1522 print!("C =\t");
1523 for c in cipher.clone()
1524 { print!("{:02X} ", c); }
1525 println!();
1526 let mut txt = String::new();
1527 for c in cipher.clone()
1528 { write!(txt, "{:02X} ", c); }
1529 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
1530 println!();
1531
1532 // Normal case for the message shorter than 8 bytes
1533 let key = 0x_1234567890ABCDEF_u64;
1534 println!("K =\t{:#016X}", key);
1535 let mut a_des = DES::new_with_key_u64(key);
1536
1537 let message = "7 bytes".to_string();
1538 println!("M =\t{}", message);
1539 let mut cipher = [0_u8; 8];
1540 a_des.encrypt_string_into_array(&message, &mut cipher);
1541 print!("C =\t");
1542 for c in cipher.clone()
1543 { print!("{:02X} ", c); }
1544 println!();
1545 let mut txt = String::new();
1546 for c in cipher.clone()
1547 { write!(txt, "{:02X} ", c); }
1548 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
1549 println!();
1550
1551 // Normal case for the message of 8 bytes
1552 let key = 0x_1234567890ABCDEF_u64;
1553 println!("K =\t{:#016X}", key);
1554 let mut a_des = DES::new_with_key_u64(key);
1555
1556 let message = "I am OK.".to_string();
1557 println!("M =\t{}", message);
1558 let mut cipher = [0_u8; 16];
1559 a_des.encrypt_string_into_array(&message, &mut cipher);
1560 print!("C =\t");
1561 for c in cipher.clone()
1562 { print!("{:02X} ", c); }
1563 println!();
1564 let mut txt = String::new();
1565 for c in cipher.clone()
1566 { write!(txt, "{:02X} ", c); }
1567 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
1568 println!();
1569
1570 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1571 let key = 0x_1234567890ABCDEF_u64;
1572 println!("K =\t{:#016X}", key);
1573 let mut a_des = DES::new_with_key_u64(key);
1574
1575 let message = "PARK Youngho".to_string();
1576 println!("M =\t{}", message);
1577 let mut cipher = [0_u8; 16];
1578 a_des.encrypt_string_into_array(&message, &mut cipher);
1579 print!("C =\t");
1580 for c in cipher.clone()
1581 { print!("{:02X} ", c); }
1582 println!();
1583 let mut txt = String::new();
1584 for c in cipher.clone()
1585 { write!(txt, "{:02X} ", c); }
1586 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
1587 println!();
1588
1589 // Normal case for the message of 16 bytes
1590 let key = 0x_1234567890ABCDEF_u64;
1591 println!("K =\t{:#016X}", key);
1592 let mut a_des = DES::new_with_key_u64(key);
1593
1594 let message = "고맙습니다.".to_string();
1595 println!("M =\t{}", message);
1596 let mut cipher = [0_u8; 24];
1597 a_des.encrypt_string_into_array(&message, &mut cipher);
1598 print!("C =\t");
1599 for c in cipher.clone()
1600 { print!("{:02X} ", c); }
1601 println!();
1602 let mut txt = String::new();
1603 for c in cipher.clone()
1604 { write!(txt, "{:02X} ", c); }
1605 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
1606 println!("-------------------------------");
1607}
1608
1609fn des_encrypt_vec_with_padding_pkcs7_ecb()
1610{
1611 println!("des_encrypt_vec_with_padding_pkcs7_ecb()");
1612 use std::io::Write;
1613 use std::fmt::Write as _;
1614 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
1615
1616 // Normal case
1617 let key = 0x_1234567890ABCDEF_u64;
1618 println!("K =\t{:#016X}", key);
1619 let mut a_des = DES::new_with_key_u64(key);
1620
1621 let message = "In the beginning God created the heavens and the earth.";
1622 println!("M =\t{}", message);
1623 let message = unsafe { message.to_string().as_mut_vec().clone() };
1624 let mut cipher = [0_u8; 56];
1625 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1626 print!("C (16 rounds) =\t");
1627 for c in cipher.clone()
1628 { print!("{:02X} ", c); }
1629 println!();
1630 let mut txt = String::new();
1631 for c in cipher.clone()
1632 { write!(txt, "{:02X} ", c); }
1633 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
1634 println!();
1635
1636 // Expanded case for 128 rounds
1637 let key = 0x_1234567890ABCDEF_u64;
1638 println!("K =\t{:#016X}", key);
1639 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1640
1641 let message = "In the beginning God created the heavens and the earth.";
1642 println!("M =\t{}", message);
1643 let message = unsafe { message.to_string().as_mut_vec().clone() };
1644 let mut cipher = [0_u8; 56];
1645 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1646 print!("C (128 rounds) =\t");
1647 for c in cipher.clone()
1648 { print!("{:02X} ", c); }
1649 println!();
1650 let mut txt = String::new();
1651 for c in cipher.clone()
1652 { write!(txt, "{:02X} ", c); }
1653 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
1654 println!();
1655
1656 // Expanded case for 0 rounds which means that key is meaningless
1657 let key1 = 0x_1234567890ABCDEF_u64;
1658 let key2 = 0_u64;
1659 println!("K1 =\t{:#016X}", key1);
1660 println!("K2 =\t{:#016X}", key2);
1661 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1662 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1663
1664 let message = "In the beginning God created the heavens and the earth.";
1665 println!("M =\t{}", message);
1666 let message = unsafe { message.to_string().as_mut_vec().clone() };
1667 let mut cipher1 = [0_u8; 56];
1668 let mut cipher2 = [0_u8; 56];
1669 c_des.encrypt_vec(&message, cipher1.as_mut_ptr());
1670 d_des.encrypt_vec(&message, cipher2.as_mut_ptr());
1671 print!("C (0 rounds) =\t");
1672 for c in cipher1.clone()
1673 { print!("{:02X} ", c); }
1674 println!();
1675 let mut txt = String::new();
1676 for c in cipher1.clone()
1677 { write!(txt, "{:02X} ", c); }
1678 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1679 print!("D (0 rounds) =\t");
1680 for c in cipher2.clone()
1681 { print!("{:02X} ", c); }
1682 println!();
1683 let mut txt = String::new();
1684 for c in cipher2.clone()
1685 { write!(txt, "{:02X} ", c); }
1686 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1687 println!();
1688
1689 // Normal case for the message of 0 bytes
1690 let key = 0x_1234567890ABCDEF_u64;
1691 println!("K =\t{:#016X}", key);
1692 let mut a_des = DES::new_with_key_u64(key);
1693
1694 let message = "";
1695 println!("M =\t{}", message);
1696 let message = unsafe { message.to_string().as_mut_vec().clone() };
1697 let mut cipher = [0_u8; 8];
1698 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1699 print!("C =\t");
1700 for c in cipher.clone()
1701 { print!("{:02X} ", c); }
1702 println!();
1703 let mut txt = String::new();
1704 for c in cipher.clone()
1705 { write!(txt, "{:02X} ", c); }
1706 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
1707 println!();
1708
1709 // Normal case for the message shorter than 8 bytes
1710 let key = 0x_1234567890ABCDEF_u64;
1711 println!("K =\t{:#016X}", key);
1712 let mut a_des = DES::new_with_key_u64(key);
1713
1714 let message = "7 bytes";
1715 println!("M =\t{}", message);
1716 let message = unsafe { message.to_string().as_mut_vec().clone() };
1717 let mut cipher = [0_u8; 8];
1718 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1719 print!("C =\t");
1720 for c in cipher.clone()
1721 { print!("{:02X} ", c); }
1722 println!();
1723 let mut txt = String::new();
1724 for c in cipher.clone()
1725 { write!(txt, "{:02X} ", c); }
1726 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
1727 println!();
1728
1729 // Normal case for the message of 8 bytes
1730 let key = 0x_1234567890ABCDEF_u64;
1731 println!("K =\t{:#016X}", key);
1732 let mut a_des = DES::new_with_key_u64(key);
1733
1734 let message = "I am OK.";
1735 println!("M =\t{}", message);
1736 let message = unsafe { message.to_string().as_mut_vec().clone() };
1737 let mut cipher = [0_u8; 16];
1738 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1739 print!("C =\t");
1740 for c in cipher.clone()
1741 { print!("{:02X} ", c); }
1742 println!();
1743 let mut txt = String::new();
1744 for c in cipher.clone()
1745 { write!(txt, "{:02X} ", c); }
1746 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
1747 println!();
1748
1749 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1750 let key = 0x_1234567890ABCDEF_u64;
1751 println!("K =\t{:#016X}", key);
1752 let mut a_des = DES::new_with_key_u64(key);
1753
1754 let message = "PARK Youngho";
1755 println!("M =\t{}", message);
1756 let message = unsafe { message.to_string().as_mut_vec().clone() };
1757 let mut cipher = [0_u8; 16];
1758 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1759 print!("C =\t");
1760 for c in cipher.clone()
1761 { print!("{:02X} ", c); }
1762 println!();
1763 let mut txt = String::new();
1764 for c in cipher.clone()
1765 { write!(txt, "{:02X} ", c); }
1766 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
1767 println!();
1768
1769
1770 // Normal case for the message of 16 bytes
1771 let key = 0x_1234567890ABCDEF_u64;
1772 println!("K =\t{:#016X}", key);
1773 let mut a_des = DES::new_with_key_u64(key);
1774
1775 let message = "고맙습니다.";
1776 println!("M =\t{}", message);
1777 let message = unsafe { message.to_string().as_mut_vec().clone() };
1778 let mut cipher = [0_u8; 24];
1779 a_des.encrypt_vec(&message, cipher.as_mut_ptr());
1780 print!("C =\t");
1781 for c in cipher.clone()
1782 { print!("{:02X} ", c); }
1783 println!();
1784 let mut txt = String::new();
1785 for c in cipher.clone()
1786 { write!(txt, "{:02X} ", c); }
1787 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
1788 println!("-------------------------------");
1789}
1790
1791fn des_encrypt_vec_with_padding_pkcs7_ecb_into_vec()
1792{
1793 println!("des_encrypt_vec_with_padding_pkcs7_ecb_into_vec()");
1794 use std::io::Write;
1795 use std::fmt::Write as _;
1796 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
1797
1798 // Normal case
1799 let key = 0x_1234567890ABCDEF_u64;
1800 println!("K =\t{:#016X}", key);
1801 let mut a_des = DES::new_with_key_u64(key);
1802
1803 let message = "In the beginning God created the heavens and the earth.";
1804 println!("M =\t{}", message);
1805 let message = unsafe { message.to_string().as_mut_vec().clone() };
1806 let mut cipher = Vec::<u8>::new();
1807 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1808 print!("C (16 rounds) =\t");
1809 for c in cipher.clone()
1810 { print!("{:02X} ", c); }
1811 println!();
1812 let mut txt = String::new();
1813 for c in cipher.clone()
1814 { write!(txt, "{:02X} ", c); }
1815 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
1816 println!();
1817
1818 // Expanded case for 128 rounds
1819 let key = 0x_1234567890ABCDEF_u64;
1820 println!("K =\t{:#016X}", key);
1821 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1822
1823 let message = "In the beginning God created the heavens and the earth.";
1824 println!("M =\t{}", message);
1825 let message = unsafe { message.to_string().as_mut_vec().clone() };
1826 let mut cipher = Vec::<u8>::new();
1827 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1828 print!("C (128 rounds) =\t");
1829 for c in cipher.clone()
1830 { print!("{:02X} ", c); }
1831 println!();
1832 let mut txt = String::new();
1833 for c in cipher.clone()
1834 { write!(txt, "{:02X} ", c); }
1835 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
1836 println!();
1837
1838 // Expanded case for 0 rounds which means that key is meaningless
1839 let key1 = 0x_1234567890ABCDEF_u64;
1840 let key2 = 0_u64;
1841 println!("K1 =\t{:#016X}", key1);
1842 println!("K2 =\t{:#016X}", key2);
1843 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1844 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1845
1846 let message = "In the beginning God created the heavens and the earth.";
1847 println!("M =\t{}", message);
1848 let message = unsafe { message.to_string().as_mut_vec().clone() };
1849
1850 let mut cipher1 = Vec::<u8>::new();
1851 let mut cipher2 = Vec::<u8>::new();
1852 c_des.encrypt_vec_into_vec(&message, &mut cipher1);
1853 d_des.encrypt_vec_into_vec(&message, &mut cipher2);
1854 print!("C (0 rounds) =\t");
1855 for c in cipher1.clone()
1856 { print!("{:02X} ", c); }
1857 println!();
1858 let mut txt = String::new();
1859 for c in cipher1.clone()
1860 { write!(txt, "{:02X} ", c); }
1861 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1862 print!("D (0 rounds) =\t");
1863 for c in cipher2.clone()
1864 { print!("{:02X} ", c); }
1865 println!();
1866 let mut txt = String::new();
1867 for c in cipher2.clone()
1868 { write!(txt, "{:02X} ", c); }
1869 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
1870 println!();
1871
1872 // Normal case for the message of 0 bytes
1873 let key = 0x_1234567890ABCDEF_u64;
1874 println!("K =\t{:#016X}", key);
1875 let mut a_des = DES::new_with_key_u64(key);
1876
1877 let message = "";
1878 println!("M =\t{}", message);
1879 let message = unsafe { message.to_string().as_mut_vec().clone() };
1880 let mut cipher = Vec::<u8>::new();
1881 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1882 print!("C =\t");
1883 for c in cipher.clone()
1884 { print!("{:02X} ", c); }
1885 println!();
1886 let mut txt = String::new();
1887 for c in cipher.clone()
1888 { write!(txt, "{:02X} ", c); }
1889 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
1890 println!();
1891
1892 // Normal case for the message shorter than 8 bytes
1893 let key = 0x_1234567890ABCDEF_u64;
1894 println!("K =\t{:#016X}", key);
1895 let mut a_des = DES::new_with_key_u64(key);
1896
1897 let message = "7 bytes";
1898 println!("M =\t{}", message);
1899 let message = unsafe { message.to_string().as_mut_vec().clone() };
1900 let mut cipher = Vec::<u8>::new();
1901 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1902 print!("C =\t");
1903 for c in cipher.clone()
1904 { print!("{:02X} ", c); }
1905 println!();
1906 let mut txt = String::new();
1907 for c in cipher.clone()
1908 { write!(txt, "{:02X} ", c); }
1909 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
1910 println!();
1911
1912 // Normal case for the message of 8 bytes
1913 let key = 0x_1234567890ABCDEF_u64;
1914 println!("K =\t{:#016X}", key);
1915 let mut a_des = DES::new_with_key_u64(key);
1916
1917 let message = "I am OK.";
1918 println!("M =\t{}", message);
1919 let message = unsafe { message.to_string().as_mut_vec().clone() };
1920 let mut cipher = Vec::<u8>::new();
1921 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1922 print!("C =\t");
1923 for c in cipher.clone()
1924 { print!("{:02X} ", c); }
1925 println!();
1926 let mut txt = String::new();
1927 for c in cipher.clone()
1928 { write!(txt, "{:02X} ", c); }
1929 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
1930 println!();
1931
1932 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1933 let key = 0x_1234567890ABCDEF_u64;
1934 println!("K =\t{:#016X}", key);
1935 let mut a_des = DES::new_with_key_u64(key);
1936
1937 let message = "PARK Youngho";
1938 println!("M =\t{}", message);
1939 let message = unsafe { message.to_string().as_mut_vec().clone() };
1940 let mut cipher = Vec::<u8>::new();
1941 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1942 print!("C =\t");
1943 for c in cipher.clone()
1944 { print!("{:02X} ", c); }
1945 println!();
1946 let mut txt = String::new();
1947 for c in cipher.clone()
1948 { write!(txt, "{:02X} ", c); }
1949 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
1950 println!();
1951
1952
1953 // Normal case for the message of 16 bytes
1954 let key = 0x_1234567890ABCDEF_u64;
1955 println!("K =\t{:#016X}", key);
1956 let mut a_des = DES::new_with_key_u64(key);
1957
1958 let message = "고맙습니다.";
1959 println!("M =\t{}", message);
1960 let message = unsafe { message.to_string().as_mut_vec().clone() };
1961 let mut cipher = Vec::<u8>::new();
1962 a_des.encrypt_vec_into_vec(&message, &mut cipher);
1963 print!("C =\t");
1964 for c in cipher.clone()
1965 { print!("{:02X} ", c); }
1966 println!();
1967 let mut txt = String::new();
1968 for c in cipher.clone()
1969 { write!(txt, "{:02X} ", c); }
1970 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
1971 println!("-------------------------------");
1972}
1973
1974fn des_encrypt_vec_with_padding_pkcs7_ecb_into_array()
1975{
1976 println!("des_encrypt_vec_with_padding_pkcs7_ecb_into_array()");
1977 use std::io::Write;
1978 use std::fmt::Write as _;
1979 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
1980
1981 // Normal case
1982 let key = 0x_1234567890ABCDEF_u64;
1983 println!("K =\t{:#016X}", key);
1984 let mut a_des = DES::new_with_key_u64(key);
1985
1986 let message = "In the beginning God created the heavens and the earth.";
1987 println!("M =\t{}", message);
1988 let message = unsafe { message.to_string().as_mut_vec().clone() };
1989 let mut cipher = [0_u8; 56];
1990 a_des.encrypt_vec_into_array(&message, &mut cipher);
1991 print!("C (16 rounds) =\t");
1992 for c in cipher.clone()
1993 { print!("{:02X} ", c); }
1994 println!();
1995 let mut txt = String::new();
1996 for c in cipher.clone()
1997 { write!(txt, "{:02X} ", c); }
1998 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
1999 println!();
2000
2001 // Expanded case for 128 rounds
2002 let key = 0x_1234567890ABCDEF_u64;
2003 println!("K =\t{:#016X}", key);
2004 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2005
2006 let message = "In the beginning God created the heavens and the earth.";
2007 println!("M =\t{}", message);
2008 let message = unsafe { message.to_string().as_mut_vec().clone() };
2009 let mut cipher = [0_u8; 56];
2010 a_des.encrypt_vec_into_array(&message, &mut cipher);
2011 print!("C (128 rounds) =\t");
2012 for c in cipher.clone()
2013 { print!("{:02X} ", c); }
2014 println!();
2015 let mut txt = String::new();
2016 for c in cipher.clone()
2017 { write!(txt, "{:02X} ", c); }
2018 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
2019 println!();
2020
2021 // Expanded case for 0 rounds which means that key is meaningless
2022 let key1 = 0x_1234567890ABCDEF_u64;
2023 let key2 = 0_u64;
2024 println!("K1 =\t{:#016X}", key1);
2025 println!("K2 =\t{:#016X}", key2);
2026 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2027 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2028
2029 let message = "In the beginning God created the heavens and the earth.";
2030 println!("M =\t{}", message);
2031 let message = unsafe { message.to_string().as_mut_vec().clone() };
2032 let mut cipher1 = [0_u8; 56];
2033 let mut cipher2 = [0_u8; 56];
2034 c_des.encrypt_vec_into_array(&message, &mut cipher1);
2035 d_des.encrypt_vec_into_array(&message, &mut cipher2);
2036 print!("C (0 rounds) =\t");
2037 for c in cipher1.clone()
2038 { print!("{:02X} ", c); }
2039 println!();
2040 let mut txt = String::new();
2041 for c in cipher1.clone()
2042 { write!(txt, "{:02X} ", c); }
2043 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2044 print!("D (0 rounds) =\t");
2045 for c in cipher2.clone()
2046 { print!("{:02X} ", c); }
2047 println!();
2048 let mut txt = String::new();
2049 for c in cipher2.clone()
2050 { write!(txt, "{:02X} ", c); }
2051 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2052 println!();
2053
2054 // Normal case for the message of 0 bytes
2055 let key = 0x_1234567890ABCDEF_u64;
2056 println!("K =\t{:#016X}", key);
2057 let mut a_des = DES::new_with_key_u64(key);
2058
2059 let message = "";
2060 println!("M =\t{}", message);
2061 let message = unsafe { message.to_string().as_mut_vec().clone() };
2062 let mut cipher = [0_u8; 8];
2063 a_des.encrypt_vec_into_array(&message, &mut cipher);
2064 print!("C =\t");
2065 for c in cipher.clone()
2066 { print!("{:02X} ", c); }
2067 println!();
2068 let mut txt = String::new();
2069 for c in cipher.clone()
2070 { write!(txt, "{:02X} ", c); }
2071 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2072 println!();
2073
2074 // Normal case for the message shorter than 8 bytes
2075 let key = 0x_1234567890ABCDEF_u64;
2076 println!("K =\t{:#016X}", key);
2077 let mut a_des = DES::new_with_key_u64(key);
2078
2079 let message = "7 bytes";
2080 println!("M =\t{}", message);
2081 let message = unsafe { message.to_string().as_mut_vec().clone() };
2082 let mut cipher = [0_u8; 8];
2083 a_des.encrypt_vec_into_array(&message, &mut cipher);
2084 print!("C =\t");
2085 for c in cipher.clone()
2086 { print!("{:02X} ", c); }
2087 println!();
2088 let mut txt = String::new();
2089 for c in cipher.clone()
2090 { write!(txt, "{:02X} ", c); }
2091 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
2092 println!();
2093
2094 // Normal case for the message of 8 bytes
2095 let key = 0x_1234567890ABCDEF_u64;
2096 println!("K =\t{:#016X}", key);
2097 let mut a_des = DES::new_with_key_u64(key);
2098
2099 let message = "I am OK.";
2100 println!("M =\t{}", message);
2101 let message = unsafe { message.to_string().as_mut_vec().clone() };
2102 let mut cipher = [0_u8; 16];
2103 a_des.encrypt_vec_into_array(&message, &mut cipher);
2104 print!("C =\t");
2105 for c in cipher.clone()
2106 { print!("{:02X} ", c); }
2107 println!();
2108 let mut txt = String::new();
2109 for c in cipher.clone()
2110 { write!(txt, "{:02X} ", c); }
2111 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
2112 println!();
2113
2114 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2115 let key = 0x_1234567890ABCDEF_u64;
2116 println!("K =\t{:#016X}", key);
2117 let mut a_des = DES::new_with_key_u64(key);
2118
2119 let message = "PARK Youngho";
2120 println!("M =\t{}", message);
2121 let message = unsafe { message.to_string().as_mut_vec().clone() };
2122 let mut cipher = [0_u8; 16];
2123 a_des.encrypt_vec_into_array(&message, &mut cipher);
2124 print!("C =\t");
2125 for c in cipher.clone()
2126 { print!("{:02X} ", c); }
2127 println!();
2128 let mut txt = String::new();
2129 for c in cipher.clone()
2130 { write!(txt, "{:02X} ", c); }
2131 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
2132 println!();
2133
2134
2135 // Normal case for the message of 16 bytes
2136 let key = 0x_1234567890ABCDEF_u64;
2137 println!("K =\t{:#016X}", key);
2138 let mut a_des = DES::new_with_key_u64(key);
2139
2140 let message = "고맙습니다.";
2141 println!("M =\t{}", message);
2142 let message = unsafe { message.to_string().as_mut_vec().clone() };
2143 let mut cipher = [0_u8; 24];
2144 a_des.encrypt_vec_into_array(&message, &mut cipher);
2145 print!("C =\t");
2146 for c in cipher.clone()
2147 { print!("{:02X} ", c); }
2148 println!();
2149 let mut txt = String::new();
2150 for c in cipher.clone()
2151 { write!(txt, "{:02X} ", c); }
2152 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
2153 println!("-------------------------------");
2154}
2155
2156fn des_encrypt_array_with_padding_pkcs7_ecb()
2157{
2158 println!("des_encrypt_array_with_padding_pkcs7_ecb()");
2159 use std::io::Write;
2160 use std::fmt::Write as _;
2161 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
2162
2163 // Normal case
2164 let key = 0x_1234567890ABCDEF_u64;
2165 println!("K =\t{:#016X}", key);
2166 let mut a_des = DES::new_with_key_u64(key);
2167
2168 let mes = "In the beginning God created the heavens and the earth.";
2169 println!("M =\t{}", mes);
2170 let mut message = [0_u8; 55];
2171 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2172 let mut cipher = [0_u8; 56];
2173 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2174 print!("C (16 rounds) =\t");
2175 for c in cipher.clone()
2176 { print!("{:02X} ", c); }
2177 println!();
2178 let mut txt = String::new();
2179 for c in cipher.clone()
2180 { write!(txt, "{:02X} ", c); }
2181 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
2182 println!();
2183
2184 // Expanded case for 128 rounds
2185 let key = 0x_1234567890ABCDEF_u64;
2186 println!("K =\t{:#016X}", key);
2187 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2188
2189 let mes = "In the beginning God created the heavens and the earth.";
2190 println!("M =\t{}", mes);
2191 let mut message = [0_u8; 55];
2192 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2193 let mut cipher = [0_u8; 56];
2194 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2195 print!("C (128 rounds) =\t");
2196 for c in cipher.clone()
2197 { print!("{:02X} ", c); }
2198 println!();
2199 let mut txt = String::new();
2200 for c in cipher.clone()
2201 { write!(txt, "{:02X} ", c); }
2202 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
2203 println!();
2204
2205 // Expanded case for 0 rounds which means that key is meaningless
2206 let key1 = 0x_1234567890ABCDEF_u64;
2207 let key2 = 0_u64;
2208 println!("K1 =\t{:#016X}", key1);
2209 println!("K2 =\t{:#016X}", key2);
2210 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2211 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2212
2213 let mes = "In the beginning God created the heavens and the earth.";
2214 println!("M =\t{}", mes);
2215 let mut message = [0_u8; 55];
2216 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2217 let mut cipher1 = [0_u8; 56];
2218 let mut cipher2 = [0_u8; 56];
2219 c_des.encrypt_array(&message, cipher1.as_mut_ptr());
2220 d_des.encrypt_array(&message, cipher2.as_mut_ptr());
2221 print!("C (0 rounds) =\t");
2222 for c in cipher1.clone()
2223 { print!("{:02X} ", c); }
2224 println!();
2225 let mut txt = String::new();
2226 for c in cipher1.clone()
2227 { write!(txt, "{:02X} ", c); }
2228 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2229 print!("D (0 rounds) =\t");
2230 for c in cipher2.clone()
2231 { print!("{:02X} ", c); }
2232 println!();
2233 let mut txt = String::new();
2234 for c in cipher2.clone()
2235 { write!(txt, "{:02X} ", c); }
2236 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2237 println!();
2238
2239 // Normal case for the message of 0 bytes
2240 let key = 0x_1234567890ABCDEF_u64;
2241 println!("K =\t{:#016X}", key);
2242 let mut a_des = DES::new_with_key_u64(key);
2243
2244 let mes = "";
2245 println!("M =\t{}", mes);
2246 let mut message = [0_u8; 0];
2247 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2248 let mut cipher = [0_u8; 8];
2249 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2250 print!("C =\t");
2251 for c in cipher.clone()
2252 { print!("{:02X} ", c); }
2253 println!();
2254 let mut txt = String::new();
2255 for c in cipher.clone()
2256 { write!(txt, "{:02X} ", c); }
2257 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2258 println!();
2259
2260 // Normal case for the message shorter than 8 bytes
2261 let key = 0x_1234567890ABCDEF_u64;
2262 println!("K =\t{:#016X}", key);
2263 let mut a_des = DES::new_with_key_u64(key);
2264
2265 let mes = "7 bytes";
2266 println!("M =\t{}", mes);
2267 let mut message = [0_u8; 7];
2268 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2269 let mut cipher = [0_u8; 8];
2270 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2271 print!("C =\t");
2272 for c in cipher.clone()
2273 { print!("{:02X} ", c); }
2274 println!();
2275 let mut txt = String::new();
2276 for c in cipher.clone()
2277 { write!(txt, "{:02X} ", c); }
2278 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
2279 println!();
2280
2281 // Normal case for the message of 8 bytes
2282 let key = 0x_1234567890ABCDEF_u64;
2283 println!("K =\t{:#016X}", key);
2284 let mut a_des = DES::new_with_key_u64(key);
2285
2286 let mes = "I am OK.";
2287 println!("M =\t{}", mes);
2288 let mut message = [0_u8; 8];
2289 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2290 let mut cipher = [0_u8; 16];
2291 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2292 print!("C =\t");
2293 for c in cipher.clone()
2294 { print!("{:02X} ", c); }
2295 println!();
2296 let mut txt = String::new();
2297 for c in cipher.clone()
2298 { write!(txt, "{:02X} ", c); }
2299 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
2300 println!();
2301
2302 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2303 let key = 0x_1234567890ABCDEF_u64;
2304 println!("K =\t{:#016X}", key);
2305 let mut a_des = DES::new_with_key_u64(key);
2306
2307 let mes = "PARK Youngho";
2308 println!("M =\t{}", mes);
2309 let mut message = [0_u8; 12];
2310 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2311 let mut cipher = [0_u8; 16];
2312 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2313 print!("C =\t");
2314 for c in cipher.clone()
2315 { print!("{:02X} ", c); }
2316 println!();
2317 let mut txt = String::new();
2318 for c in cipher.clone()
2319 { write!(txt, "{:02X} ", c); }
2320 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
2321 println!();
2322
2323
2324 // Normal case for the message of 16 bytes
2325 let key = 0x_1234567890ABCDEF_u64;
2326 println!("K =\t{:#016X}", key);
2327 let mut a_des = DES::new_with_key_u64(key);
2328
2329 let mes = "고맙습니다.";
2330 println!("M =\t{}", mes);
2331 let mut message = [0_u8; 16];
2332 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2333 let mut cipher = [0_u8; 24];
2334 a_des.encrypt_array(&message, cipher.as_mut_ptr());
2335 print!("C =\t");
2336 for c in cipher.clone()
2337 { print!("{:02X} ", c); }
2338 println!();
2339 let mut txt = String::new();
2340 for c in cipher.clone()
2341 { write!(txt, "{:02X} ", c); }
2342 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
2343 println!("-------------------------------");
2344}
2345
2346fn des_encrypt_array_with_padding_pkcs7_ecb_into_vec()
2347{
2348 println!("des_encrypt_array_with_padding_pkcs7_ecb_into_vec()");
2349 use std::io::Write;
2350 use std::fmt::Write as _;
2351 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
2352
2353 // Normal case
2354 let key = 0x_1234567890ABCDEF_u64;
2355 println!("K =\t{:#016X}", key);
2356 let mut a_des = DES::new_with_key_u64(key);
2357
2358 let mes = "In the beginning God created the heavens and the earth.";
2359 println!("M =\t{}", mes);
2360 let mut message = [0_u8; 55];
2361 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2362 let mut cipher = Vec::<u8>::new();
2363 a_des.encrypt_array_into_vec(&message, &mut cipher);
2364 print!("C (16 rounds) =\t");
2365 for c in cipher.clone()
2366 { print!("{:02X} ", c); }
2367 println!();
2368 let mut txt = String::new();
2369 for c in cipher.clone()
2370 { write!(txt, "{:02X} ", c); }
2371 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
2372 println!();
2373
2374 // Expanded case for 128 rounds
2375 let key = 0x_1234567890ABCDEF_u64;
2376 println!("K =\t{:#016X}", key);
2377 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2378
2379 let mes = "In the beginning God created the heavens and the earth.";
2380 println!("M =\t{}", mes);
2381 let mut message = [0_u8; 55];
2382 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2383 let mut cipher = Vec::<u8>::new();
2384 a_des.encrypt_array_into_vec(&message, &mut cipher);
2385 print!("C (128 rounds) =\t");
2386 for c in cipher.clone()
2387 { print!("{:02X} ", c); }
2388 println!();
2389 let mut txt = String::new();
2390 for c in cipher.clone()
2391 { write!(txt, "{:02X} ", c); }
2392 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
2393 println!();
2394
2395 // Expanded case for 0 rounds which means that key is meaningless
2396 let key1 = 0x_1234567890ABCDEF_u64;
2397 let key2 = 0_u64;
2398 println!("K1 =\t{:#016X}", key1);
2399 println!("K2 =\t{:#016X}", key2);
2400 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2401 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2402
2403 let mes = "In the beginning God created the heavens and the earth.";
2404 println!("M =\t{}", mes);
2405 let mut message = [0_u8; 55];
2406 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2407
2408 let mut cipher1 = Vec::<u8>::new();
2409 let mut cipher2 = Vec::<u8>::new();
2410 c_des.encrypt_array_into_vec(&message, &mut cipher1);
2411 d_des.encrypt_array_into_vec(&message, &mut cipher2);
2412 print!("C (0 rounds) =\t");
2413 for c in cipher1.clone()
2414 { print!("{:02X} ", c); }
2415 println!();
2416 let mut txt = String::new();
2417 for c in cipher1.clone()
2418 { write!(txt, "{:02X} ", c); }
2419 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2420 print!("D (0 rounds) =\t");
2421 for c in cipher2.clone()
2422 { print!("{:02X} ", c); }
2423 println!();
2424 let mut txt = String::new();
2425 for c in cipher2.clone()
2426 { write!(txt, "{:02X} ", c); }
2427 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2428 println!();
2429
2430 // Normal case for the message of 0 bytes
2431 let key = 0x_1234567890ABCDEF_u64;
2432 println!("K =\t{:#016X}", key);
2433 let mut a_des = DES::new_with_key_u64(key);
2434
2435 let mes = "";
2436 println!("M =\t{}", mes);
2437 let mut message = [0_u8; 0];
2438 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2439 let mut cipher = Vec::<u8>::new();
2440 a_des.encrypt_array_into_vec(&message, &mut cipher);
2441 print!("C =\t");
2442 for c in cipher.clone()
2443 { print!("{:02X} ", c); }
2444 println!();
2445 let mut txt = String::new();
2446 for c in cipher.clone()
2447 { write!(txt, "{:02X} ", c); }
2448 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2449 println!();
2450
2451 // Normal case for the message shorter than 8 bytes
2452 let key = 0x_1234567890ABCDEF_u64;
2453 println!("K =\t{:#016X}", key);
2454 let mut a_des = DES::new_with_key_u64(key);
2455
2456 let mes = "7 bytes";
2457 println!("M =\t{}", mes);
2458 let mut message = [0_u8; 7];
2459 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460 let mut cipher = Vec::<u8>::new();
2461 a_des.encrypt_array_into_vec(&message, &mut cipher);
2462 print!("C =\t");
2463 for c in cipher.clone()
2464 { print!("{:02X} ", c); }
2465 println!();
2466 let mut txt = String::new();
2467 for c in cipher.clone()
2468 { write!(txt, "{:02X} ", c); }
2469 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
2470 println!();
2471
2472 // Normal case for the message of 8 bytes
2473 let key = 0x_1234567890ABCDEF_u64;
2474 println!("K =\t{:#016X}", key);
2475 let mut a_des = DES::new_with_key_u64(key);
2476
2477 let mes = "I am OK.";
2478 println!("M =\t{}", mes);
2479 let mut message = [0_u8; 8];
2480 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2481 let mut cipher = Vec::<u8>::new();
2482 a_des.encrypt_array_into_vec(&message, &mut cipher);
2483 print!("C =\t");
2484 for c in cipher.clone()
2485 { print!("{:02X} ", c); }
2486 println!();
2487 let mut txt = String::new();
2488 for c in cipher.clone()
2489 { write!(txt, "{:02X} ", c); }
2490 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
2491 println!();
2492
2493 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2494 let key = 0x_1234567890ABCDEF_u64;
2495 println!("K =\t{:#016X}", key);
2496 let mut a_des = DES::new_with_key_u64(key);
2497
2498 let mes = "PARK Youngho";
2499 println!("M =\t{}", mes);
2500 let mut message = [0_u8; 12];
2501 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2502 let mut cipher = Vec::<u8>::new();
2503 a_des.encrypt_array_into_vec(&message, &mut cipher);
2504 print!("C =\t");
2505 for c in cipher.clone()
2506 { print!("{:02X} ", c); }
2507 println!();
2508 let mut txt = String::new();
2509 for c in cipher.clone()
2510 { write!(txt, "{:02X} ", c); }
2511 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
2512 println!();
2513
2514
2515 // Normal case for the message of 16 bytes
2516 let key = 0x_1234567890ABCDEF_u64;
2517 println!("K =\t{:#016X}", key);
2518 let mut a_des = DES::new_with_key_u64(key);
2519
2520 let mes = "고맙습니다.";
2521 println!("M =\t{}", mes);
2522 let mut message = [0_u8; 16];
2523 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2524 let mut cipher = Vec::<u8>::new();
2525 a_des.encrypt_array_into_vec(&message, &mut cipher);
2526 print!("C =\t");
2527 for c in cipher.clone()
2528 { print!("{:02X} ", c); }
2529 println!();
2530 let mut txt = String::new();
2531 for c in cipher.clone()
2532 { write!(txt, "{:02X} ", c); }
2533 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
2534 println!("-------------------------------");
2535}
2536
2537fn des_encrypt_array_with_padding_pkcs7_ecb_into_array()
2538{
2539 println!("des_encrypt_array_with_padding_pkcs7_ecb_into_array()");
2540 use std::io::Write;
2541 use std::fmt::Write as _;
2542 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
2543
2544 // Normal case
2545 let key = 0x_1234567890ABCDEF_u64;
2546 println!("K =\t{:#016X}", key);
2547 let mut a_des = DES::new_with_key_u64(key);
2548
2549 let mes = "In the beginning God created the heavens and the earth.";
2550 println!("M =\t{}", mes);
2551 let mut message = [0_u8; 55];
2552 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2553 let mut cipher = [0_u8; 56];
2554 a_des.encrypt_array_into_array(&message, &mut cipher);
2555 print!("C (16 rounds) =\t");
2556 for c in cipher.clone()
2557 { print!("{:02X} ", c); }
2558 println!();
2559 let mut txt = String::new();
2560 for c in cipher.clone()
2561 { write!(txt, "{:02X} ", c); }
2562 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
2563 println!();
2564
2565 // Expanded case for 128 rounds
2566 let key = 0x_1234567890ABCDEF_u64;
2567 println!("K =\t{:#016X}", key);
2568 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2569
2570 let mes = "In the beginning God created the heavens and the earth.";
2571 println!("M =\t{}", mes);
2572 let mut message = [0_u8; 55];
2573 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2574 let mut cipher = [0_u8; 56];
2575 a_des.encrypt_array_into_array(&message, &mut cipher);
2576 print!("C (128 rounds) =\t");
2577 for c in cipher.clone()
2578 { print!("{:02X} ", c); }
2579 println!();
2580 let mut txt = String::new();
2581 for c in cipher.clone()
2582 { write!(txt, "{:02X} ", c); }
2583 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
2584 println!();
2585
2586 // Expanded case for 0 rounds which means that key is meaningless
2587 let key1 = 0x_1234567890ABCDEF_u64;
2588 let key2 = 0_u64;
2589 println!("K1 =\t{:#016X}", key1);
2590 println!("K2 =\t{:#016X}", key2);
2591 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2592 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2593
2594 let mes = "In the beginning God created the heavens and the earth.";
2595 println!("M =\t{}", mes);
2596 let mut message = [0_u8; 55];
2597 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2598 let mut cipher1 = [0_u8; 56];
2599 let mut cipher2 = [0_u8; 56];
2600 c_des.encrypt_array_into_array(&message, &mut cipher1);
2601 d_des.encrypt_array_into_array(&message, &mut cipher2);
2602 print!("C (0 rounds) =\t");
2603 for c in cipher1.clone()
2604 { print!("{:02X} ", c); }
2605 println!();
2606 let mut txt = String::new();
2607 for c in cipher1.clone()
2608 { write!(txt, "{:02X} ", c); }
2609 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2610 print!("D (0 rounds) =\t");
2611 for c in cipher2.clone()
2612 { print!("{:02X} ", c); }
2613 println!();
2614 let mut txt = String::new();
2615 for c in cipher2.clone()
2616 { write!(txt, "{:02X} ", c); }
2617 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2618 println!();
2619
2620 // Normal case for the message of 0 bytes
2621 let key = 0x_1234567890ABCDEF_u64;
2622 println!("K =\t{:#016X}", key);
2623 let mut a_des = DES::new_with_key_u64(key);
2624
2625 let mes = "";
2626 println!("M =\t{}", mes);
2627 let mut message = [0_u8; 0];
2628 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2629 let mut cipher = [0_u8; 8];
2630 a_des.encrypt_array_into_array(&message, &mut cipher);
2631 print!("C =\t");
2632 for c in cipher.clone()
2633 { print!("{:02X} ", c); }
2634 println!();
2635 let mut txt = String::new();
2636 for c in cipher.clone()
2637 { write!(txt, "{:02X} ", c); }
2638 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2639 println!();
2640
2641 // Normal case for the message shorter than 8 bytes
2642 let key = 0x_1234567890ABCDEF_u64;
2643 println!("K =\t{:#016X}", key);
2644 let mut a_des = DES::new_with_key_u64(key);
2645
2646 let mes = "7 bytes";
2647 println!("M =\t{}", mes);
2648 let mut message = [0_u8; 7];
2649 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2650 let mut cipher = [0_u8; 8];
2651 a_des.encrypt_array_into_array(&message, &mut cipher);
2652 print!("C =\t");
2653 for c in cipher.clone()
2654 { print!("{:02X} ", c); }
2655 println!();
2656 let mut txt = String::new();
2657 for c in cipher.clone()
2658 { write!(txt, "{:02X} ", c); }
2659 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
2660 println!();
2661
2662 // Normal case for the message of 8 bytes
2663 let key = 0x_1234567890ABCDEF_u64;
2664 println!("K =\t{:#016X}", key);
2665 let mut a_des = DES::new_with_key_u64(key);
2666
2667 let mes = "I am OK.";
2668 println!("M =\t{}", mes);
2669 let mut message = [0_u8; 8];
2670 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2671 let mut cipher = [0_u8; 16];
2672 a_des.encrypt_array_into_array(&message, &mut cipher);
2673 print!("C =\t");
2674 for c in cipher.clone()
2675 { print!("{:02X} ", c); }
2676 println!();
2677 let mut txt = String::new();
2678 for c in cipher.clone()
2679 { write!(txt, "{:02X} ", c); }
2680 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
2681 println!();
2682
2683 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2684 let key = 0x_1234567890ABCDEF_u64;
2685 println!("K =\t{:#016X}", key);
2686 let mut a_des = DES::new_with_key_u64(key);
2687
2688 let mes = "PARK Youngho";
2689 println!("M =\t{}", mes);
2690 let mut message = [0_u8; 12];
2691 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2692 let mut cipher = [0_u8; 16];
2693 a_des.encrypt_array_into_array(&message, &mut cipher);
2694 print!("C =\t");
2695 for c in cipher.clone()
2696 { print!("{:02X} ", c); }
2697 println!();
2698 let mut txt = String::new();
2699 for c in cipher.clone()
2700 { write!(txt, "{:02X} ", c); }
2701 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
2702 println!();
2703
2704
2705 // Normal case for the message of 16 bytes
2706 let key = 0x_1234567890ABCDEF_u64;
2707 println!("K =\t{:#016X}", key);
2708 let mut a_des = DES::new_with_key_u64(key);
2709
2710 let mes = "고맙습니다.";
2711 println!("M =\t{}", mes);
2712 let mut message = [0_u8; 16];
2713 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2714 let mut cipher = [0_u8; 24];
2715 a_des.encrypt_array_into_array(&message, &mut cipher);
2716 print!("C =\t");
2717 for c in cipher.clone()
2718 { print!("{:02X} ", c); }
2719 println!();
2720 let mut txt = String::new();
2721 for c in cipher.clone()
2722 { write!(txt, "{:02X} ", c); }
2723 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
2724 println!("-------------------------------");
2725}
2726
2727fn des_decrypt_with_padding_pkcs7_ecb()
2728{
2729 println!("des_decrypt_with_padding_pkcs7_ecb()");
2730 use std::io::Write;
2731 use std::fmt::Write as _;
2732 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
2733
2734 // Normal case
2735 let key = 0x_1234567890ABCDEF_u64;
2736 println!("K =\t{:#016X}", key);
2737 let mut a_des = DES::new_with_key_u64(key);
2738
2739 let message = "In the beginning God created the heavens and the earth.";
2740 println!("M =\t{}", message);
2741 let mut cipher = Vec::<u8>::new();
2742 a_des.encrypt_str_into_vec(&message, &mut cipher);
2743 print!("C (16 rounds) =\t");
2744 for c in cipher.clone()
2745 { print!("{:02X} ", c); }
2746 println!();
2747 let mut txt = String::new();
2748 for c in cipher.clone()
2749 { write!(txt, "{:02X} ", c); }
2750 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
2751
2752 let mut recovered = vec![0; 55];
2753 a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2754 print!("Ba (16 rounds) =\t");
2755 for b in recovered.clone()
2756 { print!("{:02X} ", b); }
2757 println!();
2758 let mut txt = String::new();
2759 for c in recovered.clone()
2760 { write!(txt, "{:02X} ", c); }
2761 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2762
2763 let mut converted = String::new();
2764 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2765
2766 println!("Bb (16 rounds) =\t{}", converted);
2767 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2768 assert_eq!(converted, message);
2769 println!();
2770
2771 // Expanded case for 128 rounds
2772 let key = 0x_1234567890ABCDEF_u64;
2773 println!("K =\t{:#016X}", key);
2774 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2775
2776 let message = "In the beginning God created the heavens and the earth.";
2777 println!("M =\t{}", message);
2778 let mut cipher = Vec::<u8>::new();
2779 a_des.encrypt_str_into_vec(&message, &mut cipher);
2780 print!("C (128 rounds) =\t");
2781 for c in cipher.clone()
2782 { print!("{:02X} ", c); }
2783 println!();
2784 let mut txt = String::new();
2785 for c in cipher.clone()
2786 { write!(txt, "{:02X} ", c); }
2787 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
2788
2789 let mut recovered = vec![0; 55];
2790 a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2791 print!("Ba (128 rounds) =\t");
2792 for b in recovered.clone()
2793 { print!("{:02X} ", b); }
2794 println!();
2795 let mut txt = String::new();
2796 for c in recovered.clone()
2797 { write!(txt, "{:02X} ", c); }
2798 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2799
2800 let mut converted = String::new();
2801 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2802
2803 println!("Bb (128 rounds) =\t{}", converted);
2804 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2805 assert_eq!(converted, message);
2806 println!();
2807
2808 // Expanded case for 0 rounds which means that key is meaningless
2809 let key1 = 0x_1234567890ABCDEF_u64;
2810 let key2 = 0_u64;
2811 println!("K =\t{:#016X}", key);
2812 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2813 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2814
2815 let message = "In the beginning God created the heavens and the earth.";
2816 println!("M =\t{}", message);
2817 let mut cipher1 = Vec::<u8>::new();
2818 let mut cipher2 = Vec::<u8>::new();
2819 c_des.encrypt_str_into_vec(&message, &mut cipher1);
2820 d_des.encrypt_str_into_vec(&message, &mut cipher2);
2821 print!("C (0 rounds) =\t");
2822 for c in cipher1.clone()
2823 { print!("{:02X} ", c); }
2824 println!();
2825 let mut txt = String::new();
2826 for c in cipher1.clone()
2827 { write!(txt, "{:02X} ", c); }
2828 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2829 print!("D (0 rounds) =\t");
2830 for c in cipher2.clone()
2831 { print!("{:02X} ", c); }
2832 println!();
2833 let mut txt = String::new();
2834 for c in cipher2.clone()
2835 { write!(txt, "{:02X} ", c); }
2836 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
2837
2838 let mut recovered1 = vec![0; 55];
2839 let mut recovered2 = vec![0; 55];
2840 c_des.decrypt(cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
2841 d_des.decrypt(cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
2842 print!("B1a (0 rounds) =\t");
2843 for b in recovered1.clone()
2844 { print!("{:02X} ", b); }
2845 println!();
2846 let mut txt = String::new();
2847 for c in recovered1.clone()
2848 { write!(txt, "{:02X} ", c); }
2849 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2850 print!("B2a (0 rounds) =\t");
2851 for b in recovered2.clone()
2852 { print!("{:02X} ", b); }
2853 println!();
2854 let mut txt = String::new();
2855 for c in recovered2.clone()
2856 { write!(txt, "{:02X} ", c); }
2857 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2858
2859 let mut converted1 = String::new();
2860 let mut converted2 = String::new();
2861 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
2862 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
2863
2864 println!("B1b (0 rounds) =\t{}", converted1);
2865 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
2866 assert_eq!(converted1, message);
2867 println!("B2b (0 rounds) =\t{}", converted2);
2868 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
2869 assert_eq!(converted2, message);
2870 assert_eq!(converted1, converted1);
2871 println!();
2872
2873 // Normal case for the message of 0 bytes
2874 let key = 0x_1234567890ABCDEF_u64;
2875 println!("K =\t{:#016X}", key);
2876 let mut a_des = DES::new_with_key_u64(key);
2877
2878 let message = "";
2879 println!("M =\t{}", message);
2880 let mut cipher = Vec::<u8>::new();
2881 a_des.encrypt_str_into_vec(&message, &mut cipher);
2882 print!("C =\t");
2883 for c in cipher.clone()
2884 { print!("{:02X} ", c); }
2885 println!();
2886 let mut txt = String::new();
2887 for c in cipher.clone()
2888 { write!(txt, "{:02X} ", c); }
2889 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2890
2891 let mut recovered = vec![0; 8];
2892 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2893 print!("Ba =\t");
2894 for b in recovered.clone()
2895 { print!("{:02X} ", b); }
2896 println!();
2897 let mut txt = String::new();
2898 for c in recovered.clone()
2899 { write!(txt, "{:02X} ", c); }
2900 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2901
2902 let mut converted = String::new();
2903 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2904 converted.truncate(len as usize);
2905
2906 println!("Bb =\t{}", converted);
2907 assert_eq!(converted, "");
2908 assert_eq!(converted, message);
2909 println!();
2910
2911 // Normal case for the message shorter than 8 bytes
2912 let key = 0x_1234567890ABCDEF_u64;
2913 println!("K =\t{:#016X}", key);
2914 let mut a_des = DES::new_with_key_u64(key);
2915
2916 let message = "7 bytes";
2917 println!("M =\t{}", message);
2918 let mut cipher = Vec::<u8>::new();
2919 a_des.encrypt_str_into_vec(&message, &mut cipher);
2920 print!("C =\t");
2921 for c in cipher.clone()
2922 { print!("{:02X} ", c); }
2923 println!();
2924 let mut txt = String::new();
2925 for c in cipher.clone()
2926 { write!(txt, "{:02X} ", c); }
2927 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
2928
2929 let mut recovered = vec![0; 8];
2930 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2931 print!("Ba =\t");
2932 for b in recovered.clone()
2933 { print!("{:02X} ", b); }
2934 println!();
2935 let mut txt = String::new();
2936 for c in recovered.clone()
2937 { write!(txt, "{:02X} ", c); }
2938 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
2939
2940 let mut converted = String::new();
2941 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2942 converted.truncate(len as usize);
2943
2944 println!("Bb =\t{}", converted);
2945 assert_eq!(converted, "7 bytes");
2946 assert_eq!(converted, message);
2947 println!();
2948
2949 // Normal case for the message of 8 bytes
2950 let key = 0x_1234567890ABCDEF_u64;
2951 println!("K =\t{:#016X}", key);
2952 let mut a_des = DES::new_with_key_u64(key);
2953
2954 let message = "I am OK.";
2955 println!("M =\t{}", message);
2956 let mut cipher = Vec::<u8>::new();
2957 a_des.encrypt_str_into_vec(&message, &mut cipher);
2958 print!("C =\t");
2959 for c in cipher.clone()
2960 { print!("{:02X} ", c); }
2961 println!();
2962 let mut txt = String::new();
2963 for c in cipher.clone()
2964 { write!(txt, "{:02X} ", c); }
2965 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
2966
2967 let mut recovered = vec![0; 16];
2968 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2969 print!("Ba =\t");
2970 for b in recovered.clone()
2971 { print!("{:02X} ", b); }
2972 println!();
2973 let mut txt = String::new();
2974 for c in recovered.clone()
2975 { write!(txt, "{:02X} ", c); }
2976 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
2977
2978 let mut converted = String::new();
2979 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2980 converted.truncate(len as usize);
2981
2982 println!("Bb =\t{}", converted);
2983 assert_eq!(converted, "I am OK.");
2984 assert_eq!(converted, message);
2985 println!();
2986
2987 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2988 let key = 0x_1234567890ABCDEF_u64;
2989 println!("K =\t{:#016X}", key);
2990 let mut a_des = DES::new_with_key_u64(key);
2991
2992 let message = "PARK Youngho";
2993 println!("M =\t{}", message);
2994 let mut cipher = Vec::<u8>::new();
2995 a_des.encrypt_str_into_vec(&message, &mut cipher);
2996 print!("C =\t");
2997 for c in cipher.clone()
2998 { print!("{:02X} ", c); }
2999 println!();
3000 let mut txt = String::new();
3001 for c in cipher.clone()
3002 { write!(txt, "{:02X} ", c); }
3003 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
3004
3005 let mut recovered = vec![0; 16];
3006 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3007 print!("Ba =\t");
3008 for b in recovered.clone()
3009 { print!("{:02X} ", b); }
3010 println!();
3011 let mut txt = String::new();
3012 for c in recovered.clone()
3013 { write!(txt, "{:02X} ", c); }
3014 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3015
3016 let mut converted = String::new();
3017 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3018 converted.truncate(len as usize);
3019
3020 println!("Bb =\t{}", converted);
3021 assert_eq!(converted, "PARK Youngho");
3022 assert_eq!(converted, message);
3023 println!();
3024
3025
3026 // Normal case for the message of 16 bytes
3027 let key = 0x_1234567890ABCDEF_u64;
3028 println!("K =\t{:#016X}", key);
3029 let mut a_des = DES::new_with_key_u64(key);
3030
3031 let message = "고맙습니다.";
3032 println!("M =\t{}", message);
3033 let mut cipher = Vec::<u8>::new();
3034 a_des.encrypt_str_into_vec(&message, &mut cipher);
3035 print!("C =\t");
3036 for c in cipher.clone()
3037 { print!("{:02X} ", c); }
3038 println!();
3039 let mut txt = String::new();
3040 for c in cipher.clone()
3041 { write!(txt, "{:02X} ", c); }
3042 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
3043
3044 let mut recovered = vec![0; 24];
3045 let len = a_des.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3046 print!("Ba =\t");
3047 for b in recovered.clone()
3048 { print!("{:02X} ", b); }
3049 println!();
3050 let mut txt = String::new();
3051 for c in recovered.clone()
3052 { write!(txt, "{:02X} ", c); }
3053 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3054
3055 let mut converted = String::new();
3056 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3057 converted.truncate(len as usize);
3058
3059 println!("Bb =\t{}", converted);
3060 assert_eq!(converted, "고맙습니다.");
3061 assert_eq!(converted, message);
3062 println!("-------------------------------");
3063}
3064
3065fn des_decrypt_with_padding_pkcs7_ecb_into_vec()
3066{
3067 println!("des_decrypt_with_padding_pkcs7_ecb_into_vec()");
3068 use std::io::Write;
3069 use std::fmt::Write as _;
3070 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
3071
3072 // Normal case
3073 let key = 0x_1234567890ABCDEF_u64;
3074 println!("K =\t{:#016X}", key);
3075 let mut a_des = DES::new_with_key_u64(key);
3076
3077 let message = "In the beginning God created the heavens and the earth.";
3078 println!("M =\t{}", message);
3079 let mut cipher = Vec::<u8>::new();
3080 a_des.encrypt_str_into_vec(&message, &mut cipher);
3081 print!("C (16 rounds) =\t");
3082 for c in cipher.clone()
3083 { print!("{:02X} ", c); }
3084 println!();
3085 let mut txt = String::new();
3086 for c in cipher.clone()
3087 { write!(txt, "{:02X} ", c); }
3088 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
3089
3090 let mut recovered = Vec::<u8>::new();
3091 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3092 print!("Ba (16 rounds) =\t");
3093 for b in recovered.clone()
3094 { print!("{:02X} ", b); }
3095 println!();
3096 let mut txt = String::new();
3097 for c in recovered.clone()
3098 { write!(txt, "{:02X} ", c); }
3099 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3100
3101 let mut converted = String::new();
3102 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3103
3104 println!("Bb (16 rounds) =\t{}", converted);
3105 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3106 assert_eq!(converted, message);
3107 println!();
3108
3109 // Expanded case for 128 rounds
3110 let key = 0x_1234567890ABCDEF_u64;
3111 println!("K =\t{:#016X}", key);
3112 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3113
3114 let message = "In the beginning God created the heavens and the earth.";
3115 println!("M =\t{}", message);
3116 let mut cipher = Vec::<u8>::new();
3117 a_des.encrypt_str_into_vec(&message, &mut cipher);
3118 print!("C (128 rounds) =\t");
3119 for c in cipher.clone()
3120 { print!("{:02X} ", c); }
3121 println!();
3122 let mut txt = String::new();
3123 for c in cipher.clone()
3124 { write!(txt, "{:02X} ", c); }
3125 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
3126
3127 let mut recovered = Vec::<u8>::new();
3128 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3129 print!("Ba (128 rounds) =\t");
3130 for b in recovered.clone()
3131 { print!("{:02X} ", b); }
3132 println!();
3133 let mut txt = String::new();
3134 for c in recovered.clone()
3135 { write!(txt, "{:02X} ", c); }
3136 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3137
3138 let mut converted = String::new();
3139 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3140
3141 println!("Bb (128 rounds) =\t{}", converted);
3142 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3143 assert_eq!(converted, message);
3144 println!();
3145
3146 // Expanded case for 0 rounds which means that key is meaningless
3147 let key1 = 0x_1234567890ABCDEF_u64;
3148 let key2 = 0_u64;
3149 println!("K =\t{:#016X}", key);
3150 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3151 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3152
3153 let message = "In the beginning God created the heavens and the earth.";
3154 println!("M =\t{}", message);
3155 let mut cipher1 = Vec::<u8>::new();
3156 let mut cipher2 = Vec::<u8>::new();
3157 c_des.encrypt_str_into_vec(&message, &mut cipher1);
3158 d_des.encrypt_str_into_vec(&message, &mut cipher2);
3159 print!("C (0 rounds) =\t");
3160 for c in cipher1.clone()
3161 { print!("{:02X} ", c); }
3162 println!();
3163 let mut txt = String::new();
3164 for c in cipher1.clone()
3165 { write!(txt, "{:02X} ", c); }
3166 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
3167 print!("D (0 rounds) =\t");
3168 for c in cipher2.clone()
3169 { print!("{:02X} ", c); }
3170 println!();
3171 let mut txt = String::new();
3172 for c in cipher2.clone()
3173 { write!(txt, "{:02X} ", c); }
3174 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
3175
3176 let mut recovered1 = Vec::<u8>::new();
3177 let mut recovered2 = Vec::<u8>::new();
3178 c_des.decrypt_into_vec(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3179 d_des.decrypt_into_vec(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3180 print!("B1a (0 rounds) =\t");
3181 for b in recovered1.clone()
3182 { print!("{:02X} ", b); }
3183 println!();
3184 let mut txt = String::new();
3185 for c in recovered1.clone()
3186 { write!(txt, "{:02X} ", c); }
3187 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3188 print!("B2a (0 rounds) =\t");
3189 for b in recovered2.clone()
3190 { print!("{:02X} ", b); }
3191 println!();
3192 let mut txt = String::new();
3193 for c in recovered2.clone()
3194 { write!(txt, "{:02X} ", c); }
3195 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3196
3197 let mut converted1 = String::new();
3198 let mut converted2 = String::new();
3199 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3200 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3201
3202 println!("B1b (0 rounds) =\t{}", converted1);
3203 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3204 assert_eq!(converted1, message);
3205 println!("B2b (0 rounds) =\t{}", converted2);
3206 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3207 assert_eq!(converted2, message);
3208 assert_eq!(converted1, converted1);
3209 println!();
3210
3211 // Normal case for the message of 0 bytes
3212 let key = 0x_1234567890ABCDEF_u64;
3213 println!("K =\t{:#016X}", key);
3214 let mut a_des = DES::new_with_key_u64(key);
3215
3216 let message = "";
3217 println!("M =\t{}", message);
3218 let mut cipher = Vec::<u8>::new();
3219 a_des.encrypt_str_into_vec(&message, &mut cipher);
3220 print!("C =\t");
3221 for c in cipher.clone()
3222 { print!("{:02X} ", c); }
3223 println!();
3224 let mut txt = String::new();
3225 for c in cipher.clone()
3226 { write!(txt, "{:02X} ", c); }
3227 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
3228
3229 let mut recovered = Vec::<u8>::new();
3230 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3231 print!("Ba =\t");
3232 for b in recovered.clone()
3233 { print!("{:02X} ", b); }
3234 println!();
3235 let mut txt = String::new();
3236 for c in recovered.clone()
3237 { write!(txt, "{:02X} ", c); }
3238 assert_eq!(txt, "");
3239
3240 let mut converted = String::new();
3241 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3242
3243 println!("Bb =\t{}", converted);
3244 assert_eq!(converted, "");
3245 assert_eq!(converted, message);
3246 println!();
3247
3248 // Normal case for the message shorter than 8 bytes
3249 let key = 0x_1234567890ABCDEF_u64;
3250 println!("K =\t{:#016X}", key);
3251 let mut a_des = DES::new_with_key_u64(key);
3252
3253 let message = "7 bytes";
3254 println!("M =\t{}", message);
3255 let mut cipher = Vec::<u8>::new();
3256 a_des.encrypt_str_into_vec(&message, &mut cipher);
3257 print!("C =\t");
3258 for c in cipher.clone()
3259 { print!("{:02X} ", c); }
3260 println!();
3261 let mut txt = String::new();
3262 for c in cipher.clone()
3263 { write!(txt, "{:02X} ", c); }
3264 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
3265
3266 let mut recovered = Vec::<u8>::new();
3267 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3268 print!("Ba =\t");
3269 for b in recovered.clone()
3270 { print!("{:02X} ", b); }
3271 println!();
3272 let mut txt = String::new();
3273 for c in recovered.clone()
3274 { write!(txt, "{:02X} ", c); }
3275 assert_eq!(txt, "37 20 62 79 74 65 73 ");
3276
3277 let mut converted = String::new();
3278 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3279
3280 println!("Bb =\t{}", converted);
3281 assert_eq!(converted, "7 bytes");
3282 assert_eq!(converted, message);
3283 println!();
3284
3285 // Normal case for the message of 8 bytes
3286 let key = 0x_1234567890ABCDEF_u64;
3287 println!("K =\t{:#016X}", key);
3288 let mut a_des = DES::new_with_key_u64(key);
3289
3290 let message = "I am OK.";
3291 println!("M =\t{}", message);
3292 let mut cipher = Vec::<u8>::new();
3293 a_des.encrypt_str_into_vec(&message, &mut cipher);
3294 print!("C =\t");
3295 for c in cipher.clone()
3296 { print!("{:02X} ", c); }
3297 println!();
3298 let mut txt = String::new();
3299 for c in cipher.clone()
3300 { write!(txt, "{:02X} ", c); }
3301 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
3302
3303 let mut recovered = Vec::<u8>::new();
3304 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3305 print!("Ba =\t");
3306 for b in recovered.clone()
3307 { print!("{:02X} ", b); }
3308 println!();
3309 let mut txt = String::new();
3310 for c in recovered.clone()
3311 { write!(txt, "{:02X} ", c); }
3312 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3313
3314 let mut converted = String::new();
3315 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3316
3317 println!("Bb =\t{}", converted);
3318 assert_eq!(converted, "I am OK.");
3319 assert_eq!(converted, message);
3320 println!();
3321
3322 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3323 let key = 0x_1234567890ABCDEF_u64;
3324 println!("K =\t{:#016X}", key);
3325 let mut a_des = DES::new_with_key_u64(key);
3326
3327 let message = "PARK Youngho";
3328 println!("M =\t{}", message);
3329 let mut cipher = Vec::<u8>::new();
3330 a_des.encrypt_str_into_vec(&message, &mut cipher);
3331 print!("C =\t");
3332 for c in cipher.clone()
3333 { print!("{:02X} ", c); }
3334 println!();
3335 let mut txt = String::new();
3336 for c in cipher.clone()
3337 { write!(txt, "{:02X} ", c); }
3338 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
3339
3340 let mut recovered = Vec::<u8>::new();
3341 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3342 print!("Ba =\t");
3343 for b in recovered.clone()
3344 { print!("{:02X} ", b); }
3345 println!();
3346 let mut txt = String::new();
3347 for c in recovered.clone()
3348 { write!(txt, "{:02X} ", c); }
3349 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3350
3351 let mut converted = String::new();
3352 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3353
3354 println!("Bb =\t{}", converted);
3355 assert_eq!(converted, "PARK Youngho");
3356 assert_eq!(converted, message);
3357 println!();
3358
3359 // Normal case for the message of 16 bytes
3360 let key = 0x_1234567890ABCDEF_u64;
3361 println!("K =\t{:#016X}", key);
3362 let mut a_des = DES::new_with_key_u64(key);
3363
3364 let message = "고맙습니다.";
3365 println!("M =\t{}", message);
3366 let mut cipher = Vec::<u8>::new();
3367 a_des.encrypt_str_into_vec(&message, &mut cipher);
3368 print!("C =\t");
3369 for c in cipher.clone()
3370 { print!("{:02X} ", c); }
3371 println!();
3372 let mut txt = String::new();
3373 for c in cipher.clone()
3374 { write!(txt, "{:02X} ", c); }
3375 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
3376
3377 let mut recovered = Vec::<u8>::new();
3378 a_des.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3379 print!("Ba =\t");
3380 for b in recovered.clone()
3381 { print!("{:02X} ", b); }
3382 println!();
3383 let mut txt = String::new();
3384 for c in recovered.clone()
3385 { write!(txt, "{:02X} ", c); }
3386 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3387
3388 let mut converted = String::new();
3389 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3390
3391 println!("Bb =\t{}", converted);
3392 assert_eq!(converted, "고맙습니다.");
3393 assert_eq!(converted, message);
3394 println!("-------------------------------");
3395}
3396
3397fn des_decrypt_with_padding_pkcs7_ecb_into_array()
3398{
3399 println!("des_decrypt_with_padding_pkcs7_ecb_into_array()");
3400 use std::io::Write;
3401 use std::fmt::Write as _;
3402 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
3403
3404 // Normal case
3405 let key = 0x_1234567890ABCDEF_u64;
3406 println!("K =\t{:#016X}", key);
3407 let mut a_des = DES::new_with_key_u64(key);
3408
3409 let message = "In the beginning God created the heavens and the earth.";
3410 println!("M =\t{}", message);
3411 let mut cipher = Vec::<u8>::new();
3412 a_des.encrypt_str_into_vec(&message, &mut cipher);
3413 print!("C (16 rounds) =\t");
3414 for c in cipher.clone()
3415 { print!("{:02X} ", c); }
3416 println!();
3417 let mut txt = String::new();
3418 for c in cipher.clone()
3419 { write!(txt, "{:02X} ", c); }
3420 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
3421
3422 let mut recovered = [0u8; 56];
3423 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3424 print!("Ba (16 rounds) =\t");
3425 for b in recovered.clone()
3426 { print!("{:02X} ", b); }
3427 println!();
3428 let mut txt = String::new();
3429 for c in recovered.clone()
3430 { write!(txt, "{:02X} ", c); }
3431 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3432
3433 let mut converted = String::new();
3434 unsafe { converted.as_mut_vec() }.write(&recovered);
3435 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3436 println!("Bb (16 rounds) =\t{}", converted);
3437 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3438 assert_eq!(converted, message);
3439 println!();
3440
3441 // Expanded case for 128 rounds
3442 let key = 0x_1234567890ABCDEF_u64;
3443 println!("K =\t{:#016X}", key);
3444 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3445
3446 let message = "In the beginning God created the heavens and the earth.";
3447 println!("M =\t{}", message);
3448 let mut cipher = Vec::<u8>::new();
3449 a_des.encrypt_str_into_vec(&message, &mut cipher);
3450 print!("C (128 rounds) =\t");
3451 for c in cipher.clone()
3452 { print!("{:02X} ", c); }
3453 println!();
3454 let mut txt = String::new();
3455 for c in cipher.clone()
3456 { write!(txt, "{:02X} ", c); }
3457 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
3458
3459 let mut recovered = [0u8; 56];
3460 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3461 print!("Ba (16 rounds) =\t");
3462 for b in recovered.clone()
3463 { print!("{:02X} ", b); }
3464 println!();
3465 let mut txt = String::new();
3466 for c in recovered.clone()
3467 { write!(txt, "{:02X} ", c); }
3468 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3469
3470 let mut converted = String::new();
3471 unsafe { converted.as_mut_vec() }.write(&recovered);
3472 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3473 println!("Bb (16 rounds) =\t{}", converted);
3474 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3475 assert_eq!(converted, message);
3476 println!();
3477
3478 // Expanded case for 0 rounds which means that key is meaningless
3479 let key1 = 0x_1234567890ABCDEF_u64;
3480 let key2 = 0_u64;
3481 println!("K =\t{:#016X}", key);
3482 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3483 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3484
3485 let message = "In the beginning God created the heavens and the earth.";
3486 println!("M =\t{}", message);
3487 let mut cipher1 = Vec::<u8>::new();
3488 let mut cipher2 = Vec::<u8>::new();
3489 c_des.encrypt_str_into_vec(&message, &mut cipher1);
3490 d_des.encrypt_str_into_vec(&message, &mut cipher2);
3491 print!("C (0 rounds) =\t");
3492 for c in cipher1.clone()
3493 { print!("{:02X} ", c); }
3494 println!();
3495 let mut txt = String::new();
3496 for c in cipher1.clone()
3497 { write!(txt, "{:02X} ", c); }
3498 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
3499 print!("D (0 rounds) =\t");
3500 for c in cipher2.clone()
3501 { print!("{:02X} ", c); }
3502 println!();
3503 let mut txt = String::new();
3504 for c in cipher2.clone()
3505 { write!(txt, "{:02X} ", c); }
3506 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
3507
3508 let mut recovered1 = [0u8; 56];
3509 let mut recovered2 = [0u8; 56];
3510 let len1 = c_des.decrypt_into_array(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3511 let len2 = d_des.decrypt_into_array(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3512 print!("B1a (0 rounds) =\t");
3513 for b in recovered1.clone()
3514 { print!("{:02X} ", b); }
3515 println!();
3516 let mut txt = String::new();
3517 for c in recovered1.clone()
3518 { write!(txt, "{:02X} ", c); }
3519 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3520 print!("B2a (0 rounds) =\t");
3521 for b in recovered2.clone()
3522 { print!("{:02X} ", b); }
3523 println!();
3524 let mut txt = String::new();
3525 for c in recovered.clone()
3526 { write!(txt, "{:02X} ", c); }
3527 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3528
3529 let mut converted1 = String::new();
3530 let mut converted2 = String::new();
3531 unsafe { converted1.as_mut_vec() }.write(&recovered1);
3532 unsafe { converted2.as_mut_vec() }.write(&recovered2);
3533 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3534 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3535 println!("B1b (0 rounds) =\t{}", converted1);
3536 println!("B2b (0 rounds) =\t{}", converted2);
3537 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3538 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3539 assert_eq!(converted1, message);
3540 assert_eq!(converted2, message);
3541 assert_eq!(converted1, converted2);
3542 println!();
3543
3544 // Normal case for the message of 0 bytes
3545 let key = 0x_1234567890ABCDEF_u64;
3546 println!("K =\t{:#016X}", key);
3547 let mut a_des = DES::new_with_key_u64(key);
3548
3549 let message = "";
3550 println!("M =\t{}", message);
3551 let mut cipher = Vec::<u8>::new();
3552 a_des.encrypt_str_into_vec(&message, &mut cipher);
3553 print!("C =\t");
3554 for c in cipher.clone()
3555 { print!("{:02X} ", c); }
3556 println!();
3557 let mut txt = String::new();
3558 for c in cipher.clone()
3559 { write!(txt, "{:02X} ", c); }
3560 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
3561
3562 let mut recovered = [0u8; 8];
3563 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3564
3565 print!("Ba =\t");
3566 for b in recovered.clone()
3567 { print!("{:02X} ", b); }
3568 println!();
3569 let mut txt = String::new();
3570 for c in recovered.clone()
3571 { write!(txt, "{:02X} ", c); }
3572 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3573
3574 let mut converted = String::new();
3575 unsafe { converted.as_mut_vec() }.write(&recovered);
3576 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3577 println!("Bb =\t{}", converted);
3578 assert_eq!(converted, "");
3579 assert_eq!(converted, message);
3580 println!();
3581
3582 // Normal case for the message shorter than 8 bytes
3583 let key = 0x_1234567890ABCDEF_u64;
3584 println!("K =\t{:#016X}", key);
3585 let mut a_des = DES::new_with_key_u64(key);
3586
3587 let message = "7 bytes";
3588 println!("M =\t{}", message);
3589 let mut cipher = Vec::<u8>::new();
3590 a_des.encrypt_str_into_vec(&message, &mut cipher);
3591 print!("C =\t");
3592 for c in cipher.clone()
3593 { print!("{:02X} ", c); }
3594 println!();
3595 let mut txt = String::new();
3596 for c in cipher.clone()
3597 { write!(txt, "{:02X} ", c); }
3598 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
3599
3600 let mut recovered = [0u8; 8];
3601 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3602
3603 print!("Ba =\t");
3604 for b in recovered.clone()
3605 { print!("{:02X} ", b); }
3606 println!();
3607 let mut txt = String::new();
3608 for c in recovered.clone()
3609 { write!(txt, "{:02X} ", c); }
3610 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3611
3612 let mut converted = String::new();
3613 unsafe { converted.as_mut_vec() }.write(&recovered);
3614 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3615 println!("Bb =\t{}", converted);
3616 assert_eq!(converted, "7 bytes");
3617 assert_eq!(converted, message);
3618 println!();
3619
3620 // Normal case for the message of 8 bytes
3621 let key = 0x_1234567890ABCDEF_u64;
3622 println!("K =\t{:#016X}", key);
3623 let mut a_des = DES::new_with_key_u64(key);
3624
3625 let message = "I am OK.";
3626 println!("M =\t{}", message);
3627 let mut cipher = Vec::<u8>::new();
3628 a_des.encrypt_str_into_vec(&message, &mut cipher);
3629 print!("C =\t");
3630 for c in cipher.clone()
3631 { print!("{:02X} ", c); }
3632 println!();
3633 let mut txt = String::new();
3634 for c in cipher.clone()
3635 { write!(txt, "{:02X} ", c); }
3636 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
3637
3638 let mut recovered = [0u8; 16];
3639 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3640
3641 print!("Ba =\t");
3642 for b in recovered.clone()
3643 { print!("{:02X} ", b); }
3644 println!();
3645 let mut txt = String::new();
3646 for c in recovered.clone()
3647 { write!(txt, "{:02X} ", c); }
3648 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3649
3650 let mut converted = String::new();
3651 unsafe { converted.as_mut_vec() }.write(&recovered);
3652 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3653 println!("Bb =\t{}", converted);
3654 assert_eq!(converted, "I am OK.");
3655 assert_eq!(converted, message);
3656 println!();
3657
3658 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3659 let key = 0x_1234567890ABCDEF_u64;
3660 println!("K =\t{:#016X}", key);
3661 let mut a_des = DES::new_with_key_u64(key);
3662
3663 let message = "PARK Youngho";
3664 println!("M =\t{}", message);
3665 let mut cipher = Vec::<u8>::new();
3666 a_des.encrypt_str_into_vec(&message, &mut cipher);
3667 print!("C =\t");
3668 for c in cipher.clone()
3669 { print!("{:02X} ", c); }
3670 println!();
3671 let mut txt = String::new();
3672 for c in cipher.clone()
3673 { write!(txt, "{:02X} ", c); }
3674 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
3675
3676 let mut recovered = [0u8; 16];
3677 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3678
3679 print!("Ba =\t");
3680 for b in recovered.clone()
3681 { print!("{:02X} ", b); }
3682 println!();
3683 let mut txt = String::new();
3684 for c in recovered.clone()
3685 { write!(txt, "{:02X} ", c); }
3686 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3687
3688 let mut converted = String::new();
3689 unsafe { converted.as_mut_vec() }.write(&recovered);
3690 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3691 println!("Bb =\t{}", converted);
3692 assert_eq!(converted, "PARK Youngho");
3693 assert_eq!(converted, message);
3694 println!();
3695
3696 // Normal case for the message of 16 bytes
3697 let key = 0x_1234567890ABCDEF_u64;
3698 println!("K =\t{:#016X}", key);
3699 let mut a_des = DES::new_with_key_u64(key);
3700
3701 let message = "고맙습니다.";
3702 println!("M =\t{}", message);
3703 let mut cipher = Vec::<u8>::new();
3704 a_des.encrypt_str_into_vec(&message, &mut cipher);
3705 print!("C =\t");
3706 for c in cipher.clone()
3707 { print!("{:02X} ", c); }
3708 println!();
3709 let mut txt = String::new();
3710 for c in cipher.clone()
3711 { write!(txt, "{:02X} ", c); }
3712 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
3713
3714 let mut recovered = [0u8; 24];
3715 let len = a_des.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3716
3717 print!("Ba =\t");
3718 for b in recovered.clone()
3719 { print!("{:02X} ", b); }
3720 println!();
3721 let mut txt = String::new();
3722 for c in recovered.clone()
3723 { write!(txt, "{:02X} ", c); }
3724 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3725
3726 let mut converted = String::new();
3727 unsafe { converted.as_mut_vec() }.write(&recovered);
3728 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3729 println!("Bb =\t{}", converted);
3730 assert_eq!(converted, "고맙습니다.");
3731 assert_eq!(converted, message);
3732 println!("-------------------------------");
3733}
3734
3735fn des_decrypt_with_padding_pkcs7_ecb_into_string()
3736{
3737 println!("des_decrypt_with_padding_pkcs7_ecb_into_string()");
3738 use std::io::Write;
3739 use std::fmt::Write as _;
3740 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
3741
3742 // Normal case
3743 let key = 0x_1234567890ABCDEF_u64;
3744 println!("K =\t{:#016X}", key);
3745 let mut a_des = DES::new_with_key_u64(key);
3746
3747 let message = "In the beginning God created the heavens and the earth.";
3748 println!("M =\t{}", message);
3749 let mut cipher = Vec::<u8>::new();
3750 a_des.encrypt_str_into_vec(&message, &mut cipher);
3751 print!("C (16 rounds) =\t");
3752 for c in cipher.clone()
3753 { print!("{:02X} ", c); }
3754 println!();
3755 let mut txt = String::new();
3756 for c in cipher.clone()
3757 { write!(txt, "{:02X} ", c); }
3758 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
3759
3760 let mut recovered = String::new();
3761 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3762 println!("B (16 rounds) =\t{}", recovered);
3763 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3764 assert_eq!(recovered, message);
3765 println!();
3766
3767 // Expanded case for 128 rounds
3768 let key = 0x_1234567890ABCDEF_u64;
3769 println!("K =\t{:#016X}", key);
3770 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3771
3772 let message = "In the beginning God created the heavens and the earth.";
3773 println!("M =\t{}", message);
3774 let mut cipher = Vec::<u8>::new();
3775 a_des.encrypt_str_into_vec(&message, &mut cipher);
3776 print!("C (128 rounds) =\t");
3777 for c in cipher.clone()
3778 { print!("{:02X} ", c); }
3779 println!();
3780 let mut txt = String::new();
3781 for c in cipher.clone()
3782 { write!(txt, "{:02X} ", c); }
3783 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
3784
3785 let mut recovered = String::new();
3786 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3787 println!("B (128 rounds) =\t{}", recovered);
3788 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
3789 assert_eq!(recovered, message);
3790 println!();
3791
3792 // Expanded case for 0 rounds which means that key is meaningless
3793 let key1 = 0x_1234567890ABCDEF_u64;
3794 let key2 = 0_u64;
3795 println!("K =\t{:#016X}", key);
3796 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3797 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3798
3799 let message = "In the beginning God created the heavens and the earth.";
3800 println!("M =\t{}", message);
3801 let mut cipher1 = Vec::<u8>::new();
3802 let mut cipher2 = Vec::<u8>::new();
3803 c_des.encrypt_str_into_vec(&message, &mut cipher1);
3804 d_des.encrypt_str_into_vec(&message, &mut cipher2);
3805 print!("C (0 rounds) =\t");
3806 for c in cipher1.clone()
3807 { print!("{:02X} ", c); }
3808 println!();
3809 let mut txt = String::new();
3810 for c in cipher1.clone()
3811 { write!(txt, "{:02X} ", c); }
3812 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
3813 print!("D (0 rounds) =\t");
3814 for c in cipher2.clone()
3815 { print!("{:02X} ", c); }
3816 println!();
3817 let mut txt = String::new();
3818 for c in cipher2.clone()
3819 { write!(txt, "{:02X} ", c); }
3820 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
3821
3822 let mut recovered1 = String::new();
3823 let mut recovered2 = String::new();
3824 c_des.decrypt_into_string(cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3825 d_des.decrypt_into_string(cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3826 println!("B1 (0 rounds) =\t{}", recovered1);
3827 println!("B2 (0 rounds) =\t{}", recovered2);
3828 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
3829 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
3830 assert_eq!(recovered1, message);
3831 assert_eq!(recovered2, message);
3832 assert_eq!(recovered1, recovered2);
3833 println!();
3834
3835 // Normal case for the message of 0 bytes
3836 let key = 0x_1234567890ABCDEF_u64;
3837 println!("K =\t{:#016X}", key);
3838 let mut a_des = DES::new_with_key_u64(key);
3839
3840 let message = "";
3841 println!("M =\t{}", message);
3842 let mut cipher = Vec::<u8>::new();
3843 a_des.encrypt_str_into_vec(&message, &mut cipher);
3844 print!("C =\t");
3845 for c in cipher.clone()
3846 { print!("{:02X} ", c); }
3847 println!();
3848 let mut txt = String::new();
3849 for c in cipher.clone()
3850 { write!(txt, "{:02X} ", c); }
3851 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
3852
3853 let mut recovered = String::new();
3854 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3855 println!("B =\t{}", recovered);
3856 assert_eq!(recovered, "");
3857 assert_eq!(recovered, message);
3858 println!();
3859
3860 // Normal case for the message shorter than 8 bytes
3861 let key = 0x_1234567890ABCDEF_u64;
3862 println!("K =\t{:#016X}", key);
3863 let mut a_des = DES::new_with_key_u64(key);
3864
3865 let message = "7 bytes";
3866 println!("M =\t{}", message);
3867 let mut cipher = Vec::<u8>::new();
3868 a_des.encrypt_str_into_vec(&message, &mut cipher);
3869 print!("C =\t");
3870 for c in cipher.clone()
3871 { print!("{:02X} ", c); }
3872 println!();
3873 let mut txt = String::new();
3874 for c in cipher.clone()
3875 { write!(txt, "{:02X} ", c); }
3876 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
3877
3878 let mut recovered = String::new();
3879 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3880 println!("B =\t{}", recovered);
3881 assert_eq!(recovered, "7 bytes");
3882 assert_eq!(recovered, message);
3883 println!();
3884
3885 // Normal case for the message of 8 bytes
3886 let key = 0x_1234567890ABCDEF_u64;
3887 println!("K =\t{:#016X}", key);
3888 let mut a_des = DES::new_with_key_u64(key);
3889
3890 let message = "I am OK.";
3891 println!("M =\t{}", message);
3892 let mut cipher = Vec::<u8>::new();
3893 a_des.encrypt_str_into_vec(&message, &mut cipher);
3894 print!("C =\t");
3895 for c in cipher.clone()
3896 { print!("{:02X} ", c); }
3897 println!();
3898 let mut txt = String::new();
3899 for c in cipher.clone()
3900 { write!(txt, "{:02X} ", c); }
3901 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
3902
3903 let mut recovered = String::new();
3904 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3905 println!("B =\t{}", recovered);
3906 assert_eq!(recovered, "I am OK.");
3907 assert_eq!(recovered, message);
3908 println!();
3909
3910 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3911 let key = 0x_1234567890ABCDEF_u64;
3912 println!("K =\t{:#016X}", key);
3913 let mut a_des = DES::new_with_key_u64(key);
3914
3915 let message = "PARK Youngho";
3916 println!("M =\t{}", message);
3917 let mut cipher = Vec::<u8>::new();
3918 a_des.encrypt_str_into_vec(&message, &mut cipher);
3919 print!("C =\t");
3920 for c in cipher.clone()
3921 { print!("{:02X} ", c); }
3922 println!();
3923 let mut txt = String::new();
3924 for c in cipher.clone()
3925 { write!(txt, "{:02X} ", c); }
3926 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
3927
3928 let mut recovered = String::new();
3929 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3930 println!("B =\t{}", recovered);
3931 assert_eq!(recovered, "PARK Youngho");
3932 assert_eq!(recovered, message);
3933 println!();
3934
3935 // Normal case for the message of 16 bytes
3936 let key = 0x_1234567890ABCDEF_u64;
3937 println!("K =\t{:#016X}", key);
3938 let mut a_des = DES::new_with_key_u64(key);
3939
3940 let message = "고맙습니다.";
3941 println!("M =\t{}", message);
3942 let mut cipher = Vec::<u8>::new();
3943 a_des.encrypt_str_into_vec(&message, &mut cipher);
3944 print!("C =\t");
3945 for c in cipher.clone()
3946 { print!("{:02X} ", c); }
3947 println!();
3948 let mut txt = String::new();
3949 for c in cipher.clone()
3950 { write!(txt, "{:02X} ", c); }
3951 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
3952
3953 let mut recovered = String::new();
3954 a_des.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3955 println!("B =\t{}", recovered);
3956 assert_eq!(recovered, "고맙습니다.");
3957 assert_eq!(recovered, message);
3958 println!("-------------------------------");
3959}
3960
3961fn des_decrypt_vec_with_padding_pkcs7_ecb()
3962{
3963 println!("des_decrypt_vec_with_padding_pkcs7_ecb()");
3964 use std::io::Write;
3965 use std::fmt::Write as _;
3966 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
3967
3968 // Normal case
3969 let key = 0x_1234567890ABCDEF_u64;
3970 println!("K =\t{:#016X}", key);
3971 let mut a_des = DES::new_with_key_u64(key);
3972
3973 let message = "In the beginning God created the heavens and the earth.";
3974 println!("M =\t{}", message);
3975 let mut cipher = Vec::<u8>::new();
3976 a_des.encrypt_str_into_vec(&message, &mut cipher);
3977 print!("C (16 rounds) =\t");
3978 for c in cipher.clone()
3979 { print!("{:02X} ", c); }
3980 println!();
3981 let mut txt = String::new();
3982 for c in cipher.clone()
3983 { write!(txt, "{:02X} ", c); }
3984 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
3985
3986 let mut recovered = vec![0; 55];
3987 a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
3988 print!("Ba (16 rounds) =\t");
3989 for b in recovered.clone()
3990 { print!("{:02X} ", b); }
3991 println!();
3992 let mut txt = String::new();
3993 for c in recovered.clone()
3994 { write!(txt, "{:02X} ", c); }
3995 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3996
3997 let mut converted = String::new();
3998 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3999
4000 println!("Bb (16 rounds) =\t{}", converted);
4001 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4002 assert_eq!(converted, message);
4003 println!();
4004
4005 // Expanded case for 128 rounds
4006 let key = 0x_1234567890ABCDEF_u64;
4007 println!("K =\t{:#016X}", key);
4008 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4009
4010 let message = "In the beginning God created the heavens and the earth.";
4011 println!("M =\t{}", message);
4012 let mut cipher = Vec::<u8>::new();
4013 a_des.encrypt_str_into_vec(&message, &mut cipher);
4014 print!("C (128 rounds) =\t");
4015 for c in cipher.clone()
4016 { print!("{:02X} ", c); }
4017 println!();
4018 let mut txt = String::new();
4019 for c in cipher.clone()
4020 { write!(txt, "{:02X} ", c); }
4021 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
4022
4023 let mut recovered = vec![0; 55];
4024 a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4025 print!("Ba (128 rounds) =\t");
4026 for b in recovered.clone()
4027 { print!("{:02X} ", b); }
4028 println!();
4029 let mut txt = String::new();
4030 for c in recovered.clone()
4031 { write!(txt, "{:02X} ", c); }
4032 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4033
4034 let mut converted = String::new();
4035 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4036
4037 println!("Bb (128 rounds) =\t{}", converted);
4038 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4039 assert_eq!(converted, message);
4040 println!();
4041
4042 // Expanded case for 0 rounds which means that key is meaningless
4043 let key1 = 0x_1234567890ABCDEF_u64;
4044 let key2 = 0_u64;
4045 println!("K =\t{:#016X}", key);
4046 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4047 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4048
4049 let message = "In the beginning God created the heavens and the earth.";
4050 println!("M =\t{}", message);
4051 let mut cipher1 = Vec::<u8>::new();
4052 let mut cipher2 = Vec::<u8>::new();
4053 c_des.encrypt_str_into_vec(&message, &mut cipher1);
4054 d_des.encrypt_str_into_vec(&message, &mut cipher2);
4055 print!("C (0 rounds) =\t");
4056 for c in cipher1.clone()
4057 { print!("{:02X} ", c); }
4058 println!();
4059 let mut txt = String::new();
4060 for c in cipher1.clone()
4061 { write!(txt, "{:02X} ", c); }
4062 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
4063 print!("D (0 rounds) =\t");
4064 for c in cipher2.clone()
4065 { print!("{:02X} ", c); }
4066 println!();
4067 let mut txt = String::new();
4068 for c in cipher2.clone()
4069 { write!(txt, "{:02X} ", c); }
4070 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
4071
4072 let mut recovered1 = vec![0; 55];
4073 let mut recovered2 = vec![0; 55];
4074 c_des.decrypt_vec(&cipher1, recovered1.as_mut_ptr());
4075 d_des.decrypt_vec(&cipher2, recovered2.as_mut_ptr());
4076 print!("B1a (0 rounds) =\t");
4077 for b in recovered1.clone()
4078 { print!("{:02X} ", b); }
4079 println!();
4080 let mut txt = String::new();
4081 for c in recovered1.clone()
4082 { write!(txt, "{:02X} ", c); }
4083 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4084 print!("B2a (0 rounds) =\t");
4085 for b in recovered2.clone()
4086 { print!("{:02X} ", b); }
4087 println!();
4088 let mut txt = String::new();
4089 for c in recovered2.clone()
4090 { write!(txt, "{:02X} ", c); }
4091 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4092
4093 let mut converted1 = String::new();
4094 let mut converted2 = String::new();
4095 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4096 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4097
4098 println!("B1b (0 rounds) =\t{}", converted1);
4099 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4100 assert_eq!(converted1, message);
4101 println!("B2b (0 rounds) =\t{}", converted2);
4102 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4103 assert_eq!(converted2, message);
4104 assert_eq!(converted1, converted1);
4105 println!();
4106
4107 // Normal case for the message of 0 bytes
4108 let key = 0x_1234567890ABCDEF_u64;
4109 println!("K =\t{:#016X}", key);
4110 let mut a_des = DES::new_with_key_u64(key);
4111
4112 let message = "";
4113 println!("M =\t{}", message);
4114 let mut cipher = Vec::<u8>::new();
4115 a_des.encrypt_str_into_vec(&message, &mut cipher);
4116 print!("C =\t");
4117 for c in cipher.clone()
4118 { print!("{:02X} ", c); }
4119 println!();
4120 let mut txt = String::new();
4121 for c in cipher.clone()
4122 { write!(txt, "{:02X} ", c); }
4123 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
4124
4125 let mut recovered = vec![0; 8];
4126 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4127 print!("Ba =\t");
4128 for b in recovered.clone()
4129 { print!("{:02X} ", b); }
4130 println!();
4131 let mut txt = String::new();
4132 for c in recovered.clone()
4133 { write!(txt, "{:02X} ", c); }
4134 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4135
4136 let mut converted = String::new();
4137 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4138 converted.truncate(len as usize);
4139
4140 println!("Bb =\t{}", converted);
4141 assert_eq!(converted, "");
4142 assert_eq!(converted, message);
4143 println!();
4144
4145 // Normal case for the message shorter than 8 bytes
4146 let key = 0x_1234567890ABCDEF_u64;
4147 println!("K =\t{:#016X}", key);
4148 let mut a_des = DES::new_with_key_u64(key);
4149
4150 let message = "7 bytes";
4151 println!("M =\t{}", message);
4152 let mut cipher = Vec::<u8>::new();
4153 a_des.encrypt_str_into_vec(&message, &mut cipher);
4154 print!("C =\t");
4155 for c in cipher.clone()
4156 { print!("{:02X} ", c); }
4157 println!();
4158 let mut txt = String::new();
4159 for c in cipher.clone()
4160 { write!(txt, "{:02X} ", c); }
4161 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
4162
4163 let mut recovered = vec![0; 8];
4164 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4165 print!("Ba =\t");
4166 for b in recovered.clone()
4167 { print!("{:02X} ", b); }
4168 println!();
4169 let mut txt = String::new();
4170 for c in recovered.clone()
4171 { write!(txt, "{:02X} ", c); }
4172 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4173
4174 let mut converted = String::new();
4175 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4176 converted.truncate(len as usize);
4177
4178 println!("Bb =\t{}", converted);
4179 assert_eq!(converted, "7 bytes");
4180 assert_eq!(converted, message);
4181 println!();
4182
4183 // Normal case for the message of 8 bytes
4184 let key = 0x_1234567890ABCDEF_u64;
4185 println!("K =\t{:#016X}", key);
4186 let mut a_des = DES::new_with_key_u64(key);
4187
4188 let message = "I am OK.";
4189 println!("M =\t{}", message);
4190 let mut cipher = Vec::<u8>::new();
4191 a_des.encrypt_str_into_vec(&message, &mut cipher);
4192 print!("C =\t");
4193 for c in cipher.clone()
4194 { print!("{:02X} ", c); }
4195 println!();
4196 let mut txt = String::new();
4197 for c in cipher.clone()
4198 { write!(txt, "{:02X} ", c); }
4199 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
4200
4201 let mut recovered = vec![0; 16];
4202 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4203 print!("Ba =\t");
4204 for b in recovered.clone()
4205 { print!("{:02X} ", b); }
4206 println!();
4207 let mut txt = String::new();
4208 for c in recovered.clone()
4209 { write!(txt, "{:02X} ", c); }
4210 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4211
4212 let mut converted = String::new();
4213 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4214 converted.truncate(len as usize);
4215
4216 println!("Bb =\t{}", converted);
4217 assert_eq!(converted, "I am OK.");
4218 assert_eq!(converted, message);
4219 println!();
4220
4221 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4222 let key = 0x_1234567890ABCDEF_u64;
4223 println!("K =\t{:#016X}", key);
4224 let mut a_des = DES::new_with_key_u64(key);
4225
4226 let message = "PARK Youngho";
4227 println!("M =\t{}", message);
4228 let mut cipher = Vec::<u8>::new();
4229 a_des.encrypt_str_into_vec(&message, &mut cipher);
4230 print!("C =\t");
4231 for c in cipher.clone()
4232 { print!("{:02X} ", c); }
4233 println!();
4234 let mut txt = String::new();
4235 for c in cipher.clone()
4236 { write!(txt, "{:02X} ", c); }
4237 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
4238
4239 let mut recovered = vec![0; 16];
4240 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4241 print!("Ba =\t");
4242 for b in recovered.clone()
4243 { print!("{:02X} ", b); }
4244 println!();
4245 let mut txt = String::new();
4246 for c in recovered.clone()
4247 { write!(txt, "{:02X} ", c); }
4248 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4249
4250 let mut converted = String::new();
4251 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4252 converted.truncate(len as usize);
4253
4254 println!("Bb =\t{}", converted);
4255 assert_eq!(converted, "PARK Youngho");
4256 assert_eq!(converted, message);
4257 println!();
4258
4259 // Normal case for the message of 16 bytes
4260 let key = 0x_1234567890ABCDEF_u64;
4261 println!("K =\t{:#016X}", key);
4262 let mut a_des = DES::new_with_key_u64(key);
4263
4264 let message = "고맙습니다.";
4265 println!("M =\t{}", message);
4266 let mut cipher = Vec::<u8>::new();
4267 a_des.encrypt_str_into_vec(&message, &mut cipher);
4268 print!("C =\t");
4269 for c in cipher.clone()
4270 { print!("{:02X} ", c); }
4271 println!();
4272 let mut txt = String::new();
4273 for c in cipher.clone()
4274 { write!(txt, "{:02X} ", c); }
4275 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
4276
4277 let mut recovered = vec![0; 24];
4278 let len = a_des.decrypt_vec(&cipher, recovered.as_mut_ptr());
4279 print!("Ba =\t");
4280 for b in recovered.clone()
4281 { print!("{:02X} ", b); }
4282 println!();
4283 let mut txt = String::new();
4284 for c in recovered.clone()
4285 { write!(txt, "{:02X} ", c); }
4286 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4287
4288 let mut converted = String::new();
4289 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4290 converted.truncate(len as usize);
4291
4292 println!("Bb =\t{}", converted);
4293 assert_eq!(converted, "고맙습니다.");
4294 assert_eq!(converted, message);
4295 println!("-------------------------------");
4296}
4297
4298fn des_decrypt_vec_with_padding_pkcs7_ecb_into_vec()
4299{
4300 println!("des_decrypt_vec_with_padding_pkcs7_ecb_into_vec()");
4301 use std::io::Write;
4302 use std::fmt::Write as _;
4303 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
4304
4305 // Normal case
4306 let key = 0x_1234567890ABCDEF_u64;
4307 println!("K =\t{:#016X}", key);
4308 let mut a_des = DES::new_with_key_u64(key);
4309
4310 let message = "In the beginning God created the heavens and the earth.";
4311 println!("M =\t{}", message);
4312 let mut cipher = Vec::<u8>::new();
4313 a_des.encrypt_str_into_vec(&message, &mut cipher);
4314 print!("C (16 rounds) =\t");
4315 for c in cipher.clone()
4316 { print!("{:02X} ", c); }
4317 println!();
4318 let mut txt = String::new();
4319 for c in cipher.clone()
4320 { write!(txt, "{:02X} ", c); }
4321 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
4322
4323 let mut recovered = Vec::<u8>::new();
4324 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4325 print!("Ba (16 rounds) =\t");
4326 for b in recovered.clone()
4327 { print!("{:02X} ", b); }
4328 println!();
4329 let mut txt = String::new();
4330 for c in recovered.clone()
4331 { write!(txt, "{:02X} ", c); }
4332 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4333
4334 let mut converted = String::new();
4335 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4336
4337 println!("Bb (16 rounds) =\t{}", converted);
4338 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4339 assert_eq!(converted, message);
4340 println!();
4341
4342 // Expanded case for 128 rounds
4343 let key = 0x_1234567890ABCDEF_u64;
4344 println!("K =\t{:#016X}", key);
4345 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4346
4347 let message = "In the beginning God created the heavens and the earth.";
4348 println!("M =\t{}", message);
4349 let mut cipher = Vec::<u8>::new();
4350 a_des.encrypt_str_into_vec(&message, &mut cipher);
4351 print!("C (128 rounds) =\t");
4352 for c in cipher.clone()
4353 { print!("{:02X} ", c); }
4354 println!();
4355 let mut txt = String::new();
4356 for c in cipher.clone()
4357 { write!(txt, "{:02X} ", c); }
4358 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
4359
4360 let mut recovered = Vec::<u8>::new();
4361 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4362 print!("Ba (128 rounds) =\t");
4363 for b in recovered.clone()
4364 { print!("{:02X} ", b); }
4365 println!();
4366 let mut txt = String::new();
4367 for c in recovered.clone()
4368 { write!(txt, "{:02X} ", c); }
4369 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4370
4371 let mut converted = String::new();
4372 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4373
4374 println!("Bb (128 rounds) =\t{}", converted);
4375 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4376 assert_eq!(converted, message);
4377 println!();
4378
4379 // Expanded case for 0 rounds which means that key is meaningless
4380 let key1 = 0x_1234567890ABCDEF_u64;
4381 let key2 = 0_u64;
4382 println!("K =\t{:#016X}", key);
4383 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4384 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4385
4386 let message = "In the beginning God created the heavens and the earth.";
4387 println!("M =\t{}", message);
4388 let mut cipher1 = Vec::<u8>::new();
4389 let mut cipher2 = Vec::<u8>::new();
4390 c_des.encrypt_str_into_vec(&message, &mut cipher1);
4391 d_des.encrypt_str_into_vec(&message, &mut cipher2);
4392 print!("C (0 rounds) =\t");
4393 for c in cipher1.clone()
4394 { print!("{:02X} ", c); }
4395 println!();
4396 let mut txt = String::new();
4397 for c in cipher1.clone()
4398 { write!(txt, "{:02X} ", c); }
4399 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
4400 print!("D (0 rounds) =\t");
4401 for c in cipher2.clone()
4402 { print!("{:02X} ", c); }
4403 println!();
4404 let mut txt = String::new();
4405 for c in cipher2.clone()
4406 { write!(txt, "{:02X} ", c); }
4407 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
4408
4409 let mut recovered1 = Vec::<u8>::new();
4410 let mut recovered2 = Vec::<u8>::new();
4411 c_des.decrypt_vec_into_vec(&cipher1, &mut recovered1);
4412 d_des.decrypt_vec_into_vec(&cipher2, &mut recovered2);
4413 print!("B1a (0 rounds) =\t");
4414 for b in recovered1.clone()
4415 { print!("{:02X} ", b); }
4416 println!();
4417 let mut txt = String::new();
4418 for c in recovered1.clone()
4419 { write!(txt, "{:02X} ", c); }
4420 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4421 print!("B2a (0 rounds) =\t");
4422 for b in recovered2.clone()
4423 { print!("{:02X} ", b); }
4424 println!();
4425 let mut txt = String::new();
4426 for c in recovered2.clone()
4427 { write!(txt, "{:02X} ", c); }
4428 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4429
4430 let mut converted1 = String::new();
4431 let mut converted2 = String::new();
4432 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4433 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4434
4435 println!("B1b (0 rounds) =\t{}", converted1);
4436 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4437 assert_eq!(converted1, message);
4438 println!("B2b (0 rounds) =\t{}", converted2);
4439 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4440 assert_eq!(converted2, message);
4441 assert_eq!(converted1, converted1);
4442 println!();
4443
4444 // Normal case for the message of 0 bytes
4445 let key = 0x_1234567890ABCDEF_u64;
4446 println!("K =\t{:#016X}", key);
4447 let mut a_des = DES::new_with_key_u64(key);
4448
4449 let message = "";
4450 println!("M =\t{}", message);
4451 let mut cipher = Vec::<u8>::new();
4452 a_des.encrypt_str_into_vec(&message, &mut cipher);
4453 print!("C =\t");
4454 for c in cipher.clone()
4455 { print!("{:02X} ", c); }
4456 println!();
4457 let mut txt = String::new();
4458 for c in cipher.clone()
4459 { write!(txt, "{:02X} ", c); }
4460 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
4461
4462 let mut recovered = Vec::<u8>::new();
4463 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4464 print!("Ba =\t");
4465 for b in recovered.clone()
4466 { print!("{:02X} ", b); }
4467 println!();
4468 let mut txt = String::new();
4469 for c in recovered.clone()
4470 { write!(txt, "{:02X} ", c); }
4471 assert_eq!(txt, "");
4472
4473 let mut converted = String::new();
4474 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4475
4476 println!("Bb =\t{}", converted);
4477 assert_eq!(converted, "");
4478 assert_eq!(converted, message);
4479 println!();
4480
4481 // Normal case for the message shorter than 8 bytes
4482 let key = 0x_1234567890ABCDEF_u64;
4483 println!("K =\t{:#016X}", key);
4484 let mut a_des = DES::new_with_key_u64(key);
4485
4486 let message = "7 bytes";
4487 println!("M =\t{}", message);
4488 let mut cipher = Vec::<u8>::new();
4489 a_des.encrypt_str_into_vec(&message, &mut cipher);
4490 print!("C =\t");
4491 for c in cipher.clone()
4492 { print!("{:02X} ", c); }
4493 println!();
4494 let mut txt = String::new();
4495 for c in cipher.clone()
4496 { write!(txt, "{:02X} ", c); }
4497 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
4498
4499 let mut recovered = Vec::<u8>::new();
4500 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4501 print!("Ba =\t");
4502 for b in recovered.clone()
4503 { print!("{:02X} ", b); }
4504 println!();
4505 let mut txt = String::new();
4506 for c in recovered.clone()
4507 { write!(txt, "{:02X} ", c); }
4508 assert_eq!(txt, "37 20 62 79 74 65 73 ");
4509
4510 let mut converted = String::new();
4511 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4512
4513 println!("Bb =\t{}", converted);
4514 assert_eq!(converted, "7 bytes");
4515 assert_eq!(converted, message);
4516 println!();
4517
4518 // Normal case for the message of 8 bytes
4519 let key = 0x_1234567890ABCDEF_u64;
4520 println!("K =\t{:#016X}", key);
4521 let mut a_des = DES::new_with_key_u64(key);
4522
4523 let message = "I am OK.";
4524 println!("M =\t{}", message);
4525 let mut cipher = Vec::<u8>::new();
4526 a_des.encrypt_str_into_vec(&message, &mut cipher);
4527 print!("C =\t");
4528 for c in cipher.clone()
4529 { print!("{:02X} ", c); }
4530 println!();
4531 let mut txt = String::new();
4532 for c in cipher.clone()
4533 { write!(txt, "{:02X} ", c); }
4534 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
4535
4536 let mut recovered = Vec::<u8>::new();
4537 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4538 print!("Ba =\t");
4539 for b in recovered.clone()
4540 { print!("{:02X} ", b); }
4541 println!();
4542 let mut txt = String::new();
4543 for c in recovered.clone()
4544 { write!(txt, "{:02X} ", c); }
4545 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4546
4547 let mut converted = String::new();
4548 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4549
4550 println!("Bb =\t{}", converted);
4551 assert_eq!(converted, "I am OK.");
4552 assert_eq!(converted, message);
4553 println!();
4554
4555 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4556 let key = 0x_1234567890ABCDEF_u64;
4557 println!("K =\t{:#016X}", key);
4558 let mut a_des = DES::new_with_key_u64(key);
4559
4560 let message = "PARK Youngho";
4561 println!("M =\t{}", message);
4562 let mut cipher = Vec::<u8>::new();
4563 a_des.encrypt_str_into_vec(&message, &mut cipher);
4564 print!("C =\t");
4565 for c in cipher.clone()
4566 { print!("{:02X} ", c); }
4567 println!();
4568 let mut txt = String::new();
4569 for c in cipher.clone()
4570 { write!(txt, "{:02X} ", c); }
4571 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
4572
4573 let mut recovered = Vec::<u8>::new();
4574 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4575 print!("Ba =\t");
4576 for b in recovered.clone()
4577 { print!("{:02X} ", b); }
4578 println!();
4579 let mut txt = String::new();
4580 for c in recovered.clone()
4581 { write!(txt, "{:02X} ", c); }
4582 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4583
4584 let mut converted = String::new();
4585 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4586
4587 println!("Bb =\t{}", converted);
4588 assert_eq!(converted, "PARK Youngho");
4589 assert_eq!(converted, message);
4590 println!();
4591
4592 // Normal case for the message of 16 bytes
4593 let key = 0x_1234567890ABCDEF_u64;
4594 println!("K =\t{:#016X}", key);
4595 let mut a_des = DES::new_with_key_u64(key);
4596
4597 let message = "고맙습니다.";
4598 println!("M =\t{}", message);
4599 let mut cipher = Vec::<u8>::new();
4600 a_des.encrypt_str_into_vec(&message, &mut cipher);
4601 print!("C =\t");
4602 for c in cipher.clone()
4603 { print!("{:02X} ", c); }
4604 println!();
4605 let mut txt = String::new();
4606 for c in cipher.clone()
4607 { write!(txt, "{:02X} ", c); }
4608 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
4609
4610 let mut recovered = Vec::<u8>::new();
4611 a_des.decrypt_vec_into_vec(&cipher, &mut recovered);
4612 print!("Ba =\t");
4613 for b in recovered.clone()
4614 { print!("{:02X} ", b); }
4615 println!();
4616 let mut txt = String::new();
4617 for c in recovered.clone()
4618 { write!(txt, "{:02X} ", c); }
4619 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4620
4621 let mut converted = String::new();
4622 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4623
4624 println!("Bb =\t{}", converted);
4625 assert_eq!(converted, "고맙습니다.");
4626 assert_eq!(converted, message);
4627 println!("-------------------------------");
4628}
4629
4630fn des_decrypt_vec_with_padding_pkcs7_ecb_into_array()
4631{
4632 println!("des_decrypt_vec_with_padding_pkcs7_ecb_into_array()");
4633 use std::io::Write;
4634 use std::fmt::Write as _;
4635 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
4636
4637 // Normal case
4638 let key = 0x_1234567890ABCDEF_u64;
4639 println!("K =\t{:#016X}", key);
4640 let mut a_des = DES::new_with_key_u64(key);
4641
4642 let message = "In the beginning God created the heavens and the earth.";
4643 println!("M =\t{}", message);
4644 let mut cipher = Vec::<u8>::new();
4645 a_des.encrypt_str_into_vec(&message, &mut cipher);
4646 print!("C (16 rounds) =\t");
4647 for c in cipher.clone()
4648 { print!("{:02X} ", c); }
4649 println!();
4650 let mut txt = String::new();
4651 for c in cipher.clone()
4652 { write!(txt, "{:02X} ", c); }
4653 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
4654
4655 let mut recovered = [0u8; 56];
4656 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4657 print!("Ba (16 rounds) =\t");
4658 for b in recovered.clone()
4659 { print!("{:02X} ", b); }
4660 println!();
4661 let mut txt = String::new();
4662 for c in recovered.clone()
4663 { write!(txt, "{:02X} ", c); }
4664 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4665
4666 let mut converted = String::new();
4667 unsafe { converted.as_mut_vec() }.write(&recovered);
4668 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4669 println!("Bb (16 rounds) =\t{}", converted);
4670 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4671 assert_eq!(converted, message);
4672 println!();
4673
4674 // Expanded case for 128 rounds
4675 let key = 0x_1234567890ABCDEF_u64;
4676 println!("K =\t{:#016X}", key);
4677 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4678
4679 let message = "In the beginning God created the heavens and the earth.";
4680 println!("M =\t{}", message);
4681 let mut cipher = Vec::<u8>::new();
4682 a_des.encrypt_str_into_vec(&message, &mut cipher);
4683 print!("C (128 rounds) =\t");
4684 for c in cipher.clone()
4685 { print!("{:02X} ", c); }
4686 println!();
4687 let mut txt = String::new();
4688 for c in cipher.clone()
4689 { write!(txt, "{:02X} ", c); }
4690 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
4691
4692 let mut recovered = [0u8; 56];
4693 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4694 print!("Ba (16 rounds) =\t");
4695 for b in recovered.clone()
4696 { print!("{:02X} ", b); }
4697 println!();
4698 let mut txt = String::new();
4699 for c in recovered.clone()
4700 { write!(txt, "{:02X} ", c); }
4701 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4702
4703 let mut converted = String::new();
4704 unsafe { converted.as_mut_vec() }.write(&recovered);
4705 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4706 println!("Bb (16 rounds) =\t{}", converted);
4707 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4708 assert_eq!(converted, message);
4709 println!();
4710
4711 // Expanded case for 0 rounds which means that key is meaningless
4712 let key1 = 0x_1234567890ABCDEF_u64;
4713 let key2 = 0_u64;
4714 println!("K =\t{:#016X}", key);
4715 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4716 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4717
4718 let message = "In the beginning God created the heavens and the earth.";
4719 println!("M =\t{}", message);
4720 let mut cipher1 = Vec::<u8>::new();
4721 let mut cipher2 = Vec::<u8>::new();
4722 c_des.encrypt_str_into_vec(&message, &mut cipher1);
4723 d_des.encrypt_str_into_vec(&message, &mut cipher2);
4724 print!("C (0 rounds) =\t");
4725 for c in cipher1.clone()
4726 { print!("{:02X} ", c); }
4727 println!();
4728 let mut txt = String::new();
4729 for c in cipher1.clone()
4730 { write!(txt, "{:02X} ", c); }
4731 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
4732 print!("D (0 rounds) =\t");
4733 for c in cipher2.clone()
4734 { print!("{:02X} ", c); }
4735 println!();
4736 let mut txt = String::new();
4737 for c in cipher2.clone()
4738 { write!(txt, "{:02X} ", c); }
4739 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
4740
4741 let mut recovered1 = [0u8; 56];
4742 let mut recovered2 = [0u8; 56];
4743 let len1 = c_des.decrypt_vec_into_array(&cipher1, &mut recovered1);
4744 let len2 = d_des.decrypt_vec_into_array(&cipher2, &mut recovered2);
4745 print!("B1a (0 rounds) =\t");
4746 for b in recovered1.clone()
4747 { print!("{:02X} ", b); }
4748 println!();
4749 let mut txt = String::new();
4750 for c in recovered1.clone()
4751 { write!(txt, "{:02X} ", c); }
4752 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4753 print!("B2a (0 rounds) =\t");
4754 for b in recovered2.clone()
4755 { print!("{:02X} ", b); }
4756 println!();
4757 let mut txt = String::new();
4758 for c in recovered.clone()
4759 { write!(txt, "{:02X} ", c); }
4760 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4761
4762 let mut converted1 = String::new();
4763 let mut converted2 = String::new();
4764 unsafe { converted1.as_mut_vec() }.write(&recovered1);
4765 unsafe { converted2.as_mut_vec() }.write(&recovered2);
4766 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
4767 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
4768 println!("B1b (0 rounds) =\t{}", converted1);
4769 println!("B2b (0 rounds) =\t{}", converted2);
4770 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4771 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4772 assert_eq!(converted1, message);
4773 assert_eq!(converted2, message);
4774 assert_eq!(converted1, converted2);
4775 println!();
4776
4777 // Normal case for the message of 0 bytes
4778 let key = 0x_1234567890ABCDEF_u64;
4779 println!("K =\t{:#016X}", key);
4780 let mut a_des = DES::new_with_key_u64(key);
4781
4782 let message = "";
4783 println!("M =\t{}", message);
4784 let mut cipher = Vec::<u8>::new();
4785 a_des.encrypt_str_into_vec(&message, &mut cipher);
4786 print!("C =\t");
4787 for c in cipher.clone()
4788 { print!("{:02X} ", c); }
4789 println!();
4790 let mut txt = String::new();
4791 for c in cipher.clone()
4792 { write!(txt, "{:02X} ", c); }
4793 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
4794
4795 let mut recovered = [0u8; 8];
4796 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4797
4798 print!("Ba =\t");
4799 for b in recovered.clone()
4800 { print!("{:02X} ", b); }
4801 println!();
4802 let mut txt = String::new();
4803 for c in recovered.clone()
4804 { write!(txt, "{:02X} ", c); }
4805 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4806
4807 let mut converted = String::new();
4808 unsafe { converted.as_mut_vec() }.write(&recovered);
4809 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4810 println!("Bb =\t{}", converted);
4811 assert_eq!(converted, "");
4812 assert_eq!(converted, message);
4813 println!();
4814
4815 // Normal case for the message shorter than 8 bytes
4816 let key = 0x_1234567890ABCDEF_u64;
4817 println!("K =\t{:#016X}", key);
4818 let mut a_des = DES::new_with_key_u64(key);
4819
4820 let message = "7 bytes";
4821 println!("M =\t{}", message);
4822 let mut cipher = Vec::<u8>::new();
4823 a_des.encrypt_str_into_vec(&message, &mut cipher);
4824 print!("C =\t");
4825 for c in cipher.clone()
4826 { print!("{:02X} ", c); }
4827 println!();
4828 let mut txt = String::new();
4829 for c in cipher.clone()
4830 { write!(txt, "{:02X} ", c); }
4831 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
4832
4833 let mut recovered = [0u8; 8];
4834 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4835
4836 print!("Ba =\t");
4837 for b in recovered.clone()
4838 { print!("{:02X} ", b); }
4839 println!();
4840 let mut txt = String::new();
4841 for c in recovered.clone()
4842 { write!(txt, "{:02X} ", c); }
4843 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4844
4845 let mut converted = String::new();
4846 unsafe { converted.as_mut_vec() }.write(&recovered);
4847 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4848 println!("Bb =\t{}", converted);
4849 assert_eq!(converted, "7 bytes");
4850 assert_eq!(converted, message);
4851 println!();
4852
4853 // Normal case for the message of 8 bytes
4854 let key = 0x_1234567890ABCDEF_u64;
4855 println!("K =\t{:#016X}", key);
4856 let mut a_des = DES::new_with_key_u64(key);
4857
4858 let message = "I am OK.";
4859 println!("M =\t{}", message);
4860 let mut cipher = Vec::<u8>::new();
4861 a_des.encrypt_str_into_vec(&message, &mut cipher);
4862 print!("C =\t");
4863 for c in cipher.clone()
4864 { print!("{:02X} ", c); }
4865 println!();
4866 let mut txt = String::new();
4867 for c in cipher.clone()
4868 { write!(txt, "{:02X} ", c); }
4869 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
4870
4871 let mut recovered = [0u8; 16];
4872 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4873
4874 print!("Ba =\t");
4875 for b in recovered.clone()
4876 { print!("{:02X} ", b); }
4877 println!();
4878 let mut txt = String::new();
4879 for c in recovered.clone()
4880 { write!(txt, "{:02X} ", c); }
4881 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4882
4883 let mut converted = String::new();
4884 unsafe { converted.as_mut_vec() }.write(&recovered);
4885 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4886 println!("Bb =\t{}", converted);
4887 assert_eq!(converted, "I am OK.");
4888 assert_eq!(converted, message);
4889 println!();
4890
4891 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4892 let key = 0x_1234567890ABCDEF_u64;
4893 println!("K =\t{:#016X}", key);
4894 let mut a_des = DES::new_with_key_u64(key);
4895
4896 let message = "PARK Youngho";
4897 println!("M =\t{}", message);
4898 let mut cipher = Vec::<u8>::new();
4899 a_des.encrypt_str_into_vec(&message, &mut cipher);
4900 print!("C =\t");
4901 for c in cipher.clone()
4902 { print!("{:02X} ", c); }
4903 println!();
4904 let mut txt = String::new();
4905 for c in cipher.clone()
4906 { write!(txt, "{:02X} ", c); }
4907 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
4908
4909 let mut recovered = [0u8; 16];
4910 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4911
4912 print!("Ba =\t");
4913 for b in recovered.clone()
4914 { print!("{:02X} ", b); }
4915 println!();
4916 let mut txt = String::new();
4917 for c in recovered.clone()
4918 { write!(txt, "{:02X} ", c); }
4919 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4920
4921 let mut converted = String::new();
4922 unsafe { converted.as_mut_vec() }.write(&recovered);
4923 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4924 println!("Bb =\t{}", converted);
4925 assert_eq!(converted, "PARK Youngho");
4926 assert_eq!(converted, message);
4927 println!();
4928
4929 // Normal case for the message of 16 bytes
4930 let key = 0x_1234567890ABCDEF_u64;
4931 println!("K =\t{:#016X}", key);
4932 let mut a_des = DES::new_with_key_u64(key);
4933
4934 let message = "고맙습니다.";
4935 println!("M =\t{}", message);
4936 let mut cipher = Vec::<u8>::new();
4937 a_des.encrypt_str_into_vec(&message, &mut cipher);
4938 print!("C =\t");
4939 for c in cipher.clone()
4940 { print!("{:02X} ", c); }
4941 println!();
4942 let mut txt = String::new();
4943 for c in cipher.clone()
4944 { write!(txt, "{:02X} ", c); }
4945 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
4946
4947 let mut recovered = [0u8; 24];
4948 let len = a_des.decrypt_vec_into_array(&cipher, &mut recovered);
4949
4950 print!("Ba =\t");
4951 for b in recovered.clone()
4952 { print!("{:02X} ", b); }
4953 println!();
4954 let mut txt = String::new();
4955 for c in recovered.clone()
4956 { write!(txt, "{:02X} ", c); }
4957 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4958
4959 let mut converted = String::new();
4960 unsafe { converted.as_mut_vec() }.write(&recovered);
4961 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4962 println!("Bb =\t{}", converted);
4963 assert_eq!(converted, "고맙습니다.");
4964 assert_eq!(converted, message);
4965 println!("-------------------------------");
4966}
4967
4968fn des_decrypt_vec_with_padding_pkcs7_ecb_into_string()
4969{
4970 println!("des_decrypt_vec_with_padding_pkcs7_ecb_into_string()");
4971 use std::io::Write;
4972 use std::fmt::Write as _;
4973 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
4974
4975 // Normal case
4976 let key = 0x_1234567890ABCDEF_u64;
4977 println!("K =\t{:#016X}", key);
4978 let mut a_des = DES::new_with_key_u64(key);
4979
4980 let message = "In the beginning God created the heavens and the earth.";
4981 println!("M =\t{}", message);
4982 let mut cipher = Vec::<u8>::new();
4983 a_des.encrypt_str_into_vec(&message, &mut cipher);
4984 print!("C (16 rounds) =\t");
4985 for c in cipher.clone()
4986 { print!("{:02X} ", c); }
4987 println!();
4988 let mut txt = String::new();
4989 for c in cipher.clone()
4990 { write!(txt, "{:02X} ", c); }
4991 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
4992
4993 let mut recovered = String::new();
4994 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
4995 println!("B (16 rounds) =\t{}", recovered);
4996 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4997 assert_eq!(recovered, message);
4998 println!();
4999
5000 // Expanded case for 128 rounds
5001 let key = 0x_1234567890ABCDEF_u64;
5002 println!("K =\t{:#016X}", key);
5003 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5004
5005 let message = "In the beginning God created the heavens and the earth.";
5006 println!("M =\t{}", message);
5007 let mut cipher = Vec::<u8>::new();
5008 a_des.encrypt_str_into_vec(&message, &mut cipher);
5009 print!("C (128 rounds) =\t");
5010 for c in cipher.clone()
5011 { print!("{:02X} ", c); }
5012 println!();
5013 let mut txt = String::new();
5014 for c in cipher.clone()
5015 { write!(txt, "{:02X} ", c); }
5016 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
5017
5018 let mut recovered = String::new();
5019 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5020 println!("B (128 rounds) =\t{}", recovered);
5021 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5022 assert_eq!(recovered, message);
5023 println!();
5024
5025 // Expanded case for 0 rounds which means that key is meaningless
5026 let key1 = 0x_1234567890ABCDEF_u64;
5027 let key2 = 0_u64;
5028 println!("K =\t{:#016X}", key);
5029 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5030 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5031
5032 let message = "In the beginning God created the heavens and the earth.";
5033 println!("M =\t{}", message);
5034 let mut cipher1 = Vec::<u8>::new();
5035 let mut cipher2 = Vec::<u8>::new();
5036 c_des.encrypt_str_into_vec(&message, &mut cipher1);
5037 d_des.encrypt_str_into_vec(&message, &mut cipher2);
5038 print!("C (0 rounds) =\t");
5039 for c in cipher1.clone()
5040 { print!("{:02X} ", c); }
5041 println!();
5042 let mut txt = String::new();
5043 for c in cipher1.clone()
5044 { write!(txt, "{:02X} ", c); }
5045 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5046 print!("D (0 rounds) =\t");
5047 for c in cipher2.clone()
5048 { print!("{:02X} ", c); }
5049 println!();
5050 let mut txt = String::new();
5051 for c in cipher2.clone()
5052 { write!(txt, "{:02X} ", c); }
5053 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5054
5055 let mut recovered1 = String::new();
5056 let mut recovered2 = String::new();
5057 c_des.decrypt_vec_into_string(&cipher1, &mut recovered1);
5058 d_des.decrypt_vec_into_string(&cipher2, &mut recovered2);
5059 println!("B1 (0 rounds) =\t{}", recovered1);
5060 println!("B2 (0 rounds) =\t{}", recovered2);
5061 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5062 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5063 assert_eq!(recovered1, message);
5064 assert_eq!(recovered2, message);
5065 assert_eq!(recovered1, recovered2);
5066 println!();
5067
5068 // Normal case for the message of 0 bytes
5069 let key = 0x_1234567890ABCDEF_u64;
5070 println!("K =\t{:#016X}", key);
5071 let mut a_des = DES::new_with_key_u64(key);
5072
5073 let message = "";
5074 println!("M =\t{}", message);
5075 let mut cipher = Vec::<u8>::new();
5076 a_des.encrypt_str_into_vec(&message, &mut cipher);
5077 print!("C =\t");
5078 for c in cipher.clone()
5079 { print!("{:02X} ", c); }
5080 println!();
5081 let mut txt = String::new();
5082 for c in cipher.clone()
5083 { write!(txt, "{:02X} ", c); }
5084 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
5085
5086 let mut recovered = String::new();
5087 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5088 println!("B =\t{}", recovered);
5089 assert_eq!(recovered, "");
5090 assert_eq!(recovered, message);
5091 println!();
5092
5093 // Normal case for the message shorter than 8 bytes
5094 let key = 0x_1234567890ABCDEF_u64;
5095 println!("K =\t{:#016X}", key);
5096 let mut a_des = DES::new_with_key_u64(key);
5097
5098 let message = "7 bytes";
5099 println!("M =\t{}", message);
5100 let mut cipher = Vec::<u8>::new();
5101 a_des.encrypt_str_into_vec(&message, &mut cipher);
5102 print!("C =\t");
5103 for c in cipher.clone()
5104 { print!("{:02X} ", c); }
5105 println!();
5106 let mut txt = String::new();
5107 for c in cipher.clone()
5108 { write!(txt, "{:02X} ", c); }
5109 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
5110
5111 let mut recovered = String::new();
5112 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5113 println!("B =\t{}", recovered);
5114 assert_eq!(recovered, "7 bytes");
5115 assert_eq!(recovered, message);
5116 println!();
5117
5118 // Normal case for the message of 8 bytes
5119 let key = 0x_1234567890ABCDEF_u64;
5120 println!("K =\t{:#016X}", key);
5121 let mut a_des = DES::new_with_key_u64(key);
5122
5123 let message = "I am OK.";
5124 println!("M =\t{}", message);
5125 let mut cipher = Vec::<u8>::new();
5126 a_des.encrypt_str_into_vec(&message, &mut cipher);
5127 print!("C =\t");
5128 for c in cipher.clone()
5129 { print!("{:02X} ", c); }
5130 println!();
5131 let mut txt = String::new();
5132 for c in cipher.clone()
5133 { write!(txt, "{:02X} ", c); }
5134 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
5135
5136 let mut recovered = String::new();
5137 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5138 println!("B =\t{}", recovered);
5139 assert_eq!(recovered, "I am OK.");
5140 assert_eq!(recovered, message);
5141 println!();
5142
5143 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5144 let key = 0x_1234567890ABCDEF_u64;
5145 println!("K =\t{:#016X}", key);
5146 let mut a_des = DES::new_with_key_u64(key);
5147
5148 let message = "PARK Youngho";
5149 println!("M =\t{}", message);
5150 let mut cipher = Vec::<u8>::new();
5151 a_des.encrypt_str_into_vec(&message, &mut cipher);
5152 print!("C =\t");
5153 for c in cipher.clone()
5154 { print!("{:02X} ", c); }
5155 println!();
5156 let mut txt = String::new();
5157 for c in cipher.clone()
5158 { write!(txt, "{:02X} ", c); }
5159 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
5160
5161 let mut recovered = String::new();
5162 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5163 println!("B =\t{}", recovered);
5164 assert_eq!(recovered, "PARK Youngho");
5165 assert_eq!(recovered, message);
5166 println!();
5167
5168 // Normal case for the message of 16 bytes
5169 let key = 0x_1234567890ABCDEF_u64;
5170 println!("K =\t{:#016X}", key);
5171 let mut a_des = DES::new_with_key_u64(key);
5172
5173 let message = "고맙습니다.";
5174 println!("M =\t{}", message);
5175 let mut cipher = Vec::<u8>::new();
5176 a_des.encrypt_str_into_vec(&message, &mut cipher);
5177 print!("C =\t");
5178 for c in cipher.clone()
5179 { print!("{:02X} ", c); }
5180 println!();
5181 let mut txt = String::new();
5182 for c in cipher.clone()
5183 { write!(txt, "{:02X} ", c); }
5184 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
5185
5186 let mut recovered = String::new();
5187 a_des.decrypt_vec_into_string(&cipher, &mut recovered);
5188 println!("B =\t{}", recovered);
5189 assert_eq!(recovered, "고맙습니다.");
5190 assert_eq!(recovered, message);
5191 println!("-------------------------------");
5192}
5193
5194fn des_decrypt_array_with_padding_pkcs7_ecb()
5195{
5196 println!("des_decrypt_array_with_padding_pkcs7_ecb()");
5197 use std::io::Write;
5198 use std::fmt::Write as _;
5199 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
5200
5201 // Normal case
5202 let key = 0x_1234567890ABCDEF_u64;
5203 println!("K =\t{:#016X}", key);
5204 let mut a_des = DES::new_with_key_u64(key);
5205
5206 let message = "In the beginning God created the heavens and the earth.";
5207 println!("M =\t{}", message);
5208 let mut cipher = [0_u8; 56];
5209 a_des.encrypt_str_into_array(&message, &mut cipher);
5210 print!("C (16 rounds) =\t");
5211 for c in cipher.clone()
5212 { print!("{:02X} ", c); }
5213 println!();
5214 let mut txt = String::new();
5215 for c in cipher.clone()
5216 { write!(txt, "{:02X} ", c); }
5217 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
5218
5219 let mut recovered = vec![0; 55];
5220 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5221 recovered.truncate(len as usize);
5222 print!("Ba (16 rounds) =\t");
5223 for b in recovered.clone()
5224 { print!("{:02X} ", b); }
5225 println!();
5226 let mut txt = String::new();
5227 for c in recovered.clone()
5228 { write!(txt, "{:02X} ", c); }
5229 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5230
5231 let mut converted = String::new();
5232 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5233
5234 println!("Bb (16 rounds) =\t{}", converted);
5235 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5236 assert_eq!(converted, message);
5237 println!();
5238
5239 // Expanded case for 128 rounds
5240 let key = 0x_1234567890ABCDEF_u64;
5241 println!("K =\t{:#016X}", key);
5242 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5243
5244 let message = "In the beginning God created the heavens and the earth.";
5245 println!("M =\t{}", message);
5246 let mut cipher = [0_u8; 56];
5247 a_des.encrypt_str_into_array(&message, &mut cipher);
5248 print!("C (128 rounds) =\t");
5249 for c in cipher.clone()
5250 { print!("{:02X} ", c); }
5251 println!();
5252 let mut txt = String::new();
5253 for c in cipher.clone()
5254 { write!(txt, "{:02X} ", c); }
5255 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
5256
5257 let mut recovered = vec![0; 55];
5258 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5259 recovered.truncate(len as usize);
5260 print!("Ba (128 rounds) =\t");
5261 for b in recovered.clone()
5262 { print!("{:02X} ", b); }
5263 println!();
5264 let mut txt = String::new();
5265 for c in recovered.clone()
5266 { write!(txt, "{:02X} ", c); }
5267 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5268
5269 let mut converted = String::new();
5270 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5271
5272 println!("Bb (128 rounds) =\t{}", converted);
5273 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5274 assert_eq!(converted, message);
5275 println!();
5276
5277 // Expanded case for 0 rounds which means that key is meaningless
5278 let key1 = 0x_1234567890ABCDEF_u64;
5279 let key2 = 0_u64;
5280 println!("K =\t{:#016X}", key);
5281 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5282 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5283
5284 let message = "In the beginning God created the heavens and the earth.";
5285 println!("M =\t{}", message);
5286 let mut cipher1 = [0_u8; 56];
5287 let mut cipher2 = [0_u8; 56];
5288 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5289 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5290 print!("C (0 rounds) =\t");
5291 for c in cipher1.clone()
5292 { print!("{:02X} ", c); }
5293 println!();
5294 let mut txt = String::new();
5295 for c in cipher1.clone()
5296 { write!(txt, "{:02X} ", c); }
5297 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5298 print!("D (0 rounds) =\t");
5299 for c in cipher2.clone()
5300 { print!("{:02X} ", c); }
5301 println!();
5302 let mut txt = String::new();
5303 for c in cipher2.clone()
5304 { write!(txt, "{:02X} ", c); }
5305 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5306
5307 let mut recovered1 = vec![0; 55];
5308 let mut recovered2 = vec![0; 55];
5309 let len1 = c_des.decrypt_array(&cipher1, recovered1.as_mut_ptr());
5310 let len2 = d_des.decrypt_array(&cipher2, recovered2.as_mut_ptr());
5311 recovered1.truncate(len1 as usize);
5312 recovered2.truncate(len2 as usize);
5313
5314 print!("B1a (0 rounds) =\t");
5315 for b in recovered1.clone()
5316 { print!("{:02X} ", b); }
5317 println!();
5318 let mut txt = String::new();
5319 for c in recovered1.clone()
5320 { write!(txt, "{:02X} ", c); }
5321 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5322 print!("B2a (0 rounds) =\t");
5323 for b in recovered2.clone()
5324 { print!("{:02X} ", b); }
5325 println!();
5326 let mut txt = String::new();
5327 for c in recovered2.clone()
5328 { write!(txt, "{:02X} ", c); }
5329 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5330
5331 let mut converted1 = String::new();
5332 let mut converted2 = String::new();
5333 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5334 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5335
5336 println!("B1b (0 rounds) =\t{}", converted1);
5337 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5338 assert_eq!(converted1, message);
5339 println!("B2b (0 rounds) =\t{}", converted2);
5340 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5341 assert_eq!(converted2, message);
5342 assert_eq!(converted1, converted1);
5343 println!();
5344
5345 // Normal case for the message of 0 bytes
5346 let key = 0x_1234567890ABCDEF_u64;
5347 println!("K =\t{:#016X}", key);
5348 let mut a_des = DES::new_with_key_u64(key);
5349
5350 let message = "";
5351 println!("M =\t{}", message);
5352 let mut cipher = [0_u8; 8];
5353 a_des.encrypt_str_into_array(&message, &mut cipher);
5354 print!("C =\t");
5355 for c in cipher.clone()
5356 { print!("{:02X} ", c); }
5357 println!();
5358 let mut txt = String::new();
5359 for c in cipher.clone()
5360 { write!(txt, "{:02X} ", c); }
5361 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
5362
5363 let mut recovered = vec![0; 8];
5364 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5365 recovered.truncate(len as usize);
5366
5367 print!("Ba =\t");
5368 for b in recovered.clone()
5369 { print!("{:02X} ", b); }
5370 println!();
5371 let mut txt = String::new();
5372 for c in recovered.clone()
5373 { write!(txt, "{:02X} ", c); }
5374 assert_eq!(txt, "");
5375
5376 let mut converted = String::new();
5377 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5378
5379 println!("Bb =\t{}", converted);
5380 assert_eq!(converted, "");
5381 assert_eq!(converted, message);
5382 println!();
5383
5384 // Normal case for the message shorter than 8 bytes
5385 let key = 0x_1234567890ABCDEF_u64;
5386 println!("K =\t{:#016X}", key);
5387 let mut a_des = DES::new_with_key_u64(key);
5388
5389 let message = "7 bytes";
5390 println!("M =\t{}", message);
5391 let mut cipher = [0_u8; 8];
5392 a_des.encrypt_str_into_array(&message, &mut cipher);
5393 print!("C =\t");
5394 for c in cipher.clone()
5395 { print!("{:02X} ", c); }
5396 println!();
5397 let mut txt = String::new();
5398 for c in cipher.clone()
5399 { write!(txt, "{:02X} ", c); }
5400 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
5401
5402 let mut recovered = vec![0; 8];
5403 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5404 recovered.truncate(len as usize);
5405
5406 print!("Ba =\t");
5407 for b in recovered.clone()
5408 { print!("{:02X} ", b); }
5409 println!();
5410 let mut txt = String::new();
5411 for c in recovered.clone()
5412 { write!(txt, "{:02X} ", c); }
5413 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5414
5415 let mut converted = String::new();
5416 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5417
5418 println!("Bb =\t{}", converted);
5419 assert_eq!(converted, "7 bytes");
5420 assert_eq!(converted, message);
5421 println!();
5422
5423 // Normal case for the message of 8 bytes
5424 let key = 0x_1234567890ABCDEF_u64;
5425 println!("K =\t{:#016X}", key);
5426 let mut a_des = DES::new_with_key_u64(key);
5427
5428 let message = "I am OK.";
5429 println!("M =\t{}", message);
5430 let mut cipher = [0_u8; 16];
5431 a_des.encrypt_str_into_array(&message, &mut cipher);
5432 print!("C =\t");
5433 for c in cipher.clone()
5434 { print!("{:02X} ", c); }
5435 println!();
5436 let mut txt = String::new();
5437 for c in cipher.clone()
5438 { write!(txt, "{:02X} ", c); }
5439 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
5440
5441 let mut recovered = vec![0; 16];
5442 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5443 recovered.truncate(len as usize);
5444
5445 print!("Ba =\t");
5446 for b in recovered.clone()
5447 { print!("{:02X} ", b); }
5448 println!();
5449 let mut txt = String::new();
5450 for c in recovered.clone()
5451 { write!(txt, "{:02X} ", c); }
5452 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5453
5454 let mut converted = String::new();
5455 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5456
5457 println!("Bb =\t{}", converted);
5458 assert_eq!(converted, "I am OK.");
5459 assert_eq!(converted, message);
5460 println!();
5461
5462 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5463 let key = 0x_1234567890ABCDEF_u64;
5464 println!("K =\t{:#016X}", key);
5465 let mut a_des = DES::new_with_key_u64(key);
5466
5467 let message = "PARK Youngho";
5468 println!("M =\t{}", message);
5469 let mut cipher = [0_u8; 16];
5470 a_des.encrypt_str_into_array(&message, &mut cipher);
5471 print!("C =\t");
5472 for c in cipher.clone()
5473 { print!("{:02X} ", c); }
5474 println!();
5475 let mut txt = String::new();
5476 for c in cipher.clone()
5477 { write!(txt, "{:02X} ", c); }
5478 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
5479
5480 let mut recovered = vec![0; 16];
5481 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5482 recovered.truncate(len as usize);
5483 print!("Ba =\t");
5484 for b in recovered.clone()
5485 { print!("{:02X} ", b); }
5486 println!();
5487 let mut txt = String::new();
5488 for c in recovered.clone()
5489 { write!(txt, "{:02X} ", c); }
5490 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5491
5492 let mut converted = String::new();
5493 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5494
5495 println!("Bb =\t{}", converted);
5496 assert_eq!(converted, "PARK Youngho");
5497 assert_eq!(converted, message);
5498 println!();
5499
5500 // Normal case for the message of 16 bytes
5501 let key = 0x_1234567890ABCDEF_u64;
5502 println!("K =\t{:#016X}", key);
5503 let mut a_des = DES::new_with_key_u64(key);
5504
5505 let message = "고맙습니다.";
5506 println!("M =\t{}", message);
5507 let mut cipher = [0_u8; 24];
5508 a_des.encrypt_str_into_array(&message, &mut cipher);
5509 print!("C =\t");
5510 for c in cipher.clone()
5511 { print!("{:02X} ", c); }
5512 println!();
5513 let mut txt = String::new();
5514 for c in cipher.clone()
5515 { write!(txt, "{:02X} ", c); }
5516 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
5517
5518 let mut recovered = vec![0; 24];
5519 let len = a_des.decrypt_array(&cipher, recovered.as_mut_ptr());
5520 recovered.truncate(len as usize);
5521
5522 print!("Ba =\t");
5523 for b in recovered.clone()
5524 { print!("{:02X} ", b); }
5525 println!();
5526 let mut txt = String::new();
5527 for c in recovered.clone()
5528 { write!(txt, "{:02X} ", c); }
5529 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5530
5531 let mut converted = String::new();
5532 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5533
5534 println!("Bb =\t{}", converted);
5535 assert_eq!(converted, "고맙습니다.");
5536 assert_eq!(converted, message);
5537 println!("-------------------------------");
5538}
5539
5540fn des_decrypt_array_with_padding_pkcs7_ecb_into_vec()
5541{
5542 println!("des_decrypt_array_with_padding_pkcs7_ecb_into_vec()");
5543 use std::io::Write;
5544 use std::fmt::Write as _;
5545 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
5546
5547 // Normal case
5548 let key = 0x_1234567890ABCDEF_u64;
5549 println!("K =\t{:#016X}", key);
5550 let mut a_des = DES::new_with_key_u64(key);
5551
5552 let message = "In the beginning God created the heavens and the earth.";
5553 println!("M =\t{}", message);
5554 let mut cipher = [0_u8; 56];
5555 a_des.encrypt_str_into_array(&message, &mut cipher);
5556 print!("C (16 rounds) =\t");
5557 for c in cipher.clone()
5558 { print!("{:02X} ", c); }
5559 println!();
5560 let mut txt = String::new();
5561 for c in cipher.clone()
5562 { write!(txt, "{:02X} ", c); }
5563 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
5564
5565 let mut recovered = Vec::<u8>::new();
5566 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5567 print!("Ba (16 rounds) =\t");
5568 for b in recovered.clone()
5569 { print!("{:02X} ", b); }
5570 println!();
5571 let mut txt = String::new();
5572 for c in recovered.clone()
5573 { write!(txt, "{:02X} ", c); }
5574 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5575
5576 let mut converted = String::new();
5577 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5578
5579 println!("Bb (16 rounds) =\t{}", converted);
5580 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5581 assert_eq!(converted, message);
5582 println!();
5583
5584 // Expanded case for 128 rounds
5585 let key = 0x_1234567890ABCDEF_u64;
5586 println!("K =\t{:#016X}", key);
5587 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5588
5589 let message = "In the beginning God created the heavens and the earth.";
5590 println!("M =\t{}", message);
5591 let mut cipher = [0_u8; 56];
5592 a_des.encrypt_str_into_array(&message, &mut cipher);
5593 print!("C (128 rounds) =\t");
5594 for c in cipher.clone()
5595 { print!("{:02X} ", c); }
5596 println!();
5597 let mut txt = String::new();
5598 for c in cipher.clone()
5599 { write!(txt, "{:02X} ", c); }
5600 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
5601
5602 let mut recovered = Vec::<u8>::new();
5603 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5604 print!("Ba (128 rounds) =\t");
5605 for b in recovered.clone()
5606 { print!("{:02X} ", b); }
5607 println!();
5608 let mut txt = String::new();
5609 for c in recovered.clone()
5610 { write!(txt, "{:02X} ", c); }
5611 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5612
5613 let mut converted = String::new();
5614 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5615
5616 println!("Bb (128 rounds) =\t{}", converted);
5617 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5618 assert_eq!(converted, message);
5619 println!();
5620
5621 // Expanded case for 0 rounds which means that key is meaningless
5622 let key1 = 0x_1234567890ABCDEF_u64;
5623 let key2 = 0_u64;
5624 println!("K =\t{:#016X}", key);
5625 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5626 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5627
5628 let message = "In the beginning God created the heavens and the earth.";
5629 println!("M =\t{}", message);
5630 let mut cipher1 = [0_u8; 56];
5631 let mut cipher2 = [0_u8; 56];
5632 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5633 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5634 print!("C (0 rounds) =\t");
5635 for c in cipher1.clone()
5636 { print!("{:02X} ", c); }
5637 println!();
5638 let mut txt = String::new();
5639 for c in cipher1.clone()
5640 { write!(txt, "{:02X} ", c); }
5641 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5642 print!("D (0 rounds) =\t");
5643 for c in cipher2.clone()
5644 { print!("{:02X} ", c); }
5645 println!();
5646 let mut txt = String::new();
5647 for c in cipher2.clone()
5648 { write!(txt, "{:02X} ", c); }
5649 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5650
5651 let mut recovered1 = Vec::<u8>::new();
5652 let mut recovered2 = Vec::<u8>::new();
5653 c_des.decrypt_array_into_vec(&cipher1, &mut recovered1);
5654 d_des.decrypt_array_into_vec(&cipher2, &mut recovered2);
5655 print!("B1a (0 rounds) =\t");
5656 for b in recovered1.clone()
5657 { print!("{:02X} ", b); }
5658 println!();
5659 let mut txt = String::new();
5660 for c in recovered1.clone()
5661 { write!(txt, "{:02X} ", c); }
5662 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5663 print!("B2a (0 rounds) =\t");
5664 for b in recovered2.clone()
5665 { print!("{:02X} ", b); }
5666 println!();
5667 let mut txt = String::new();
5668 for c in recovered2.clone()
5669 { write!(txt, "{:02X} ", c); }
5670 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5671
5672 let mut converted1 = String::new();
5673 let mut converted2 = String::new();
5674 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5675 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5676
5677 println!("B1b (0 rounds) =\t{}", converted1);
5678 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5679 assert_eq!(converted1, message);
5680 println!("B2b (0 rounds) =\t{}", converted2);
5681 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5682 assert_eq!(converted2, message);
5683 assert_eq!(converted1, converted1);
5684 println!();
5685
5686 // Normal case for the message of 0 bytes
5687 let key = 0x_1234567890ABCDEF_u64;
5688 println!("K =\t{:#016X}", key);
5689 let mut a_des = DES::new_with_key_u64(key);
5690
5691 let message = "";
5692 println!("M =\t{}", message);
5693 let mut cipher = [0_u8; 8];
5694 a_des.encrypt_str_into_array(&message, &mut cipher);
5695 print!("C =\t");
5696 for c in cipher.clone()
5697 { print!("{:02X} ", c); }
5698 println!();
5699 let mut txt = String::new();
5700 for c in cipher.clone()
5701 { write!(txt, "{:02X} ", c); }
5702 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
5703
5704 let mut recovered = Vec::<u8>::new();
5705 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5706 print!("Ba =\t");
5707 for b in recovered.clone()
5708 { print!("{:02X} ", b); }
5709 println!();
5710 let mut txt = String::new();
5711 for c in recovered.clone()
5712 { write!(txt, "{:02X} ", c); }
5713 assert_eq!(txt, "");
5714
5715 let mut converted = String::new();
5716 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5717
5718 println!("Bb =\t{}", converted);
5719 assert_eq!(converted, "");
5720 assert_eq!(converted, message);
5721 println!();
5722
5723 // Normal case for the message shorter than 8 bytes
5724 let key = 0x_1234567890ABCDEF_u64;
5725 println!("K =\t{:#016X}", key);
5726 let mut a_des = DES::new_with_key_u64(key);
5727
5728 let message = "7 bytes";
5729 println!("M =\t{}", message);
5730 let mut cipher = [0_u8; 8];
5731 a_des.encrypt_str_into_array(&message, &mut cipher);
5732 print!("C =\t");
5733 for c in cipher.clone()
5734 { print!("{:02X} ", c); }
5735 println!();
5736 let mut txt = String::new();
5737 for c in cipher.clone()
5738 { write!(txt, "{:02X} ", c); }
5739 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
5740
5741 let mut recovered = Vec::<u8>::new();
5742 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5743 print!("Ba =\t");
5744 for b in recovered.clone()
5745 { print!("{:02X} ", b); }
5746 println!();
5747 let mut txt = String::new();
5748 for c in recovered.clone()
5749 { write!(txt, "{:02X} ", c); }
5750 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5751
5752 let mut converted = String::new();
5753 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5754
5755 println!("Bb =\t{}", converted);
5756 assert_eq!(converted, "7 bytes");
5757 assert_eq!(converted, message);
5758 println!();
5759
5760 // Normal case for the message of 8 bytes
5761 let key = 0x_1234567890ABCDEF_u64;
5762 println!("K =\t{:#016X}", key);
5763 let mut a_des = DES::new_with_key_u64(key);
5764
5765 let message = "I am OK.";
5766 println!("M =\t{}", message);
5767 let mut cipher = [0_u8; 16];
5768 a_des.encrypt_str_into_array(&message, &mut cipher);
5769 print!("C =\t");
5770 for c in cipher.clone()
5771 { print!("{:02X} ", c); }
5772 println!();
5773 let mut txt = String::new();
5774 for c in cipher.clone()
5775 { write!(txt, "{:02X} ", c); }
5776 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
5777
5778 let mut recovered = Vec::<u8>::new();
5779 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5780 print!("Ba =\t");
5781 for b in recovered.clone()
5782 { print!("{:02X} ", b); }
5783 println!();
5784 let mut txt = String::new();
5785 for c in recovered.clone()
5786 { write!(txt, "{:02X} ", c); }
5787 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5788
5789 let mut converted = String::new();
5790 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5791
5792 println!("Bb =\t{}", converted);
5793 assert_eq!(converted, "I am OK.");
5794 assert_eq!(converted, message);
5795 println!();
5796
5797 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5798 let key = 0x_1234567890ABCDEF_u64;
5799 println!("K =\t{:#016X}", key);
5800 let mut a_des = DES::new_with_key_u64(key);
5801
5802 let message = "PARK Youngho";
5803 println!("M =\t{}", message);
5804 let mut cipher = [0_u8; 16];
5805 a_des.encrypt_str_into_array(&message, &mut cipher);
5806 print!("C =\t");
5807 for c in cipher.clone()
5808 { print!("{:02X} ", c); }
5809 println!();
5810 let mut txt = String::new();
5811 for c in cipher.clone()
5812 { write!(txt, "{:02X} ", c); }
5813 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
5814
5815 let mut recovered = Vec::<u8>::new();
5816 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5817 print!("Ba =\t");
5818 for b in recovered.clone()
5819 { print!("{:02X} ", b); }
5820 println!();
5821 let mut txt = String::new();
5822 for c in recovered.clone()
5823 { write!(txt, "{:02X} ", c); }
5824 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5825
5826 let mut converted = String::new();
5827 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5828
5829 println!("Bb =\t{}", converted);
5830 assert_eq!(converted, "PARK Youngho");
5831 assert_eq!(converted, message);
5832 println!();
5833
5834 // Normal case for the message of 16 bytes
5835 let key = 0x_1234567890ABCDEF_u64;
5836 println!("K =\t{:#016X}", key);
5837 let mut a_des = DES::new_with_key_u64(key);
5838
5839 let message = "고맙습니다.";
5840 println!("M =\t{}", message);
5841 let mut cipher = [0_u8; 24];
5842 a_des.encrypt_str_into_array(&message, &mut cipher);
5843 print!("C =\t");
5844 for c in cipher.clone()
5845 { print!("{:02X} ", c); }
5846 println!();
5847 let mut txt = String::new();
5848 for c in cipher.clone()
5849 { write!(txt, "{:02X} ", c); }
5850 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
5851
5852 let mut recovered = Vec::<u8>::new();
5853 a_des.decrypt_array_into_vec(&cipher, &mut recovered);
5854 print!("Ba =\t");
5855 for b in recovered.clone()
5856 { print!("{:02X} ", b); }
5857 println!();
5858 let mut txt = String::new();
5859 for c in recovered.clone()
5860 { write!(txt, "{:02X} ", c); }
5861 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5862
5863 let mut converted = String::new();
5864 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5865
5866 println!("Bb =\t{}", converted);
5867 assert_eq!(converted, "고맙습니다.");
5868 assert_eq!(converted, message);
5869 println!("-------------------------------");
5870}
5871
5872fn des_decrypt_array_with_padding_pkcs7_ecb_into_array()
5873{
5874 println!("des_decrypt_array_with_padding_pkcs7_ecb_into_array()");
5875 use std::io::Write;
5876 use std::fmt::Write as _;
5877 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
5878
5879 // Normal case
5880 let key = 0x_1234567890ABCDEF_u64;
5881 println!("K =\t{:#016X}", key);
5882 let mut a_des = DES::new_with_key_u64(key);
5883
5884 let message = "In the beginning God created the heavens and the earth.";
5885 println!("M =\t{}", message);
5886 let mut cipher = [0_u8; 56];
5887 a_des.encrypt_str_into_array(&message, &mut cipher);
5888 print!("C (16 rounds) =\t");
5889 for c in cipher.clone()
5890 { print!("{:02X} ", c); }
5891 println!();
5892 let mut txt = String::new();
5893 for c in cipher.clone()
5894 { write!(txt, "{:02X} ", c); }
5895 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
5896
5897 let mut recovered = [0u8; 56];
5898 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5899 print!("Ba (16 rounds) =\t");
5900 for b in recovered.clone()
5901 { print!("{:02X} ", b); }
5902 println!();
5903 let mut txt = String::new();
5904 for c in recovered.clone()
5905 { write!(txt, "{:02X} ", c); }
5906 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5907
5908 let mut converted = String::new();
5909 unsafe { converted.as_mut_vec() }.write(&recovered);
5910 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5911 println!("Bb (16 rounds) =\t{}", converted);
5912 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5913 assert_eq!(converted, message);
5914 println!();
5915
5916 // Expanded case for 128 rounds
5917 let key = 0x_1234567890ABCDEF_u64;
5918 println!("K =\t{:#016X}", key);
5919 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5920
5921 let message = "In the beginning God created the heavens and the earth.";
5922 println!("M =\t{}", message);
5923 let mut cipher = [0_u8; 56];
5924 a_des.encrypt_str_into_array(&message, &mut cipher);
5925 print!("C (128 rounds) =\t");
5926 for c in cipher.clone()
5927 { print!("{:02X} ", c); }
5928 println!();
5929 let mut txt = String::new();
5930 for c in cipher.clone()
5931 { write!(txt, "{:02X} ", c); }
5932 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
5933
5934 let mut recovered = [0u8; 56];
5935 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
5936 print!("Ba (16 rounds) =\t");
5937 for b in recovered.clone()
5938 { print!("{:02X} ", b); }
5939 println!();
5940 let mut txt = String::new();
5941 for c in recovered.clone()
5942 { write!(txt, "{:02X} ", c); }
5943 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5944
5945 let mut converted = String::new();
5946 unsafe { converted.as_mut_vec() }.write(&recovered);
5947 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5948 println!("Bb (16 rounds) =\t{}", converted);
5949 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5950 assert_eq!(converted, message);
5951 println!();
5952
5953 // Expanded case for 0 rounds which means that key is meaningless
5954 let key1 = 0x_1234567890ABCDEF_u64;
5955 let key2 = 0_u64;
5956 println!("K =\t{:#016X}", key);
5957 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5958 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5959
5960 let message = "In the beginning God created the heavens and the earth.";
5961 println!("M =\t{}", message);
5962 let mut cipher1 = [0_u8; 56];
5963 let mut cipher2 = [0_u8; 56];
5964 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
5965 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
5966 print!("C (0 rounds) =\t");
5967 for c in cipher1.clone()
5968 { print!("{:02X} ", c); }
5969 println!();
5970 let mut txt = String::new();
5971 for c in cipher1.clone()
5972 { write!(txt, "{:02X} ", c); }
5973 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5974 print!("D (0 rounds) =\t");
5975 for c in cipher2.clone()
5976 { print!("{:02X} ", c); }
5977 println!();
5978 let mut txt = String::new();
5979 for c in cipher2.clone()
5980 { write!(txt, "{:02X} ", c); }
5981 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
5982
5983 let mut recovered1 = [0u8; 56];
5984 let mut recovered2 = [0u8; 56];
5985 let len1 = c_des.decrypt_array_into_array(&cipher1, &mut recovered1);
5986 let len2 = d_des.decrypt_array_into_array(&cipher2, &mut recovered2);
5987 print!("B1a (0 rounds) =\t");
5988 for b in recovered1.clone()
5989 { print!("{:02X} ", b); }
5990 println!();
5991 let mut txt = String::new();
5992 for c in recovered1.clone()
5993 { write!(txt, "{:02X} ", c); }
5994 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5995 print!("B2a (0 rounds) =\t");
5996 for b in recovered2.clone()
5997 { print!("{:02X} ", b); }
5998 println!();
5999 let mut txt = String::new();
6000 for c in recovered.clone()
6001 { write!(txt, "{:02X} ", c); }
6002 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6003
6004 let mut converted1 = String::new();
6005 let mut converted2 = String::new();
6006 unsafe { converted1.as_mut_vec() }.write(&recovered1);
6007 unsafe { converted2.as_mut_vec() }.write(&recovered2);
6008 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6009 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6010 println!("B1b (0 rounds) =\t{}", converted1);
6011 println!("B2b (0 rounds) =\t{}", converted2);
6012 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6013 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6014 assert_eq!(converted1, message);
6015 assert_eq!(converted2, message);
6016 assert_eq!(converted1, converted2);
6017 println!();
6018
6019 // Normal case for the message of 0 bytes
6020 let key = 0x_1234567890ABCDEF_u64;
6021 println!("K =\t{:#016X}", key);
6022 let mut a_des = DES::new_with_key_u64(key);
6023
6024 let message = "";
6025 println!("M =\t{}", message);
6026 let mut cipher = [0_u8; 8];
6027 a_des.encrypt_str_into_array(&message, &mut cipher);
6028 print!("C =\t");
6029 for c in cipher.clone()
6030 { print!("{:02X} ", c); }
6031 println!();
6032 let mut txt = String::new();
6033 for c in cipher.clone()
6034 { write!(txt, "{:02X} ", c); }
6035 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
6036
6037 let mut recovered = [0u8; 8];
6038 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6039
6040 print!("Ba =\t");
6041 for b in recovered.clone()
6042 { print!("{:02X} ", b); }
6043 println!();
6044 let mut txt = String::new();
6045 for c in recovered.clone()
6046 { write!(txt, "{:02X} ", c); }
6047 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6048
6049 let mut converted = String::new();
6050 unsafe { converted.as_mut_vec() }.write(&recovered);
6051 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6052 println!("Bb =\t{}", converted);
6053 assert_eq!(converted, "");
6054 assert_eq!(converted, message);
6055 println!();
6056
6057 // Normal case for the message shorter than 8 bytes
6058 let key = 0x_1234567890ABCDEF_u64;
6059 println!("K =\t{:#016X}", key);
6060 let mut a_des = DES::new_with_key_u64(key);
6061
6062 let message = "7 bytes";
6063 println!("M =\t{}", message);
6064 let mut cipher = [0_u8; 8];
6065 a_des.encrypt_str_into_array(&message, &mut cipher);
6066 print!("C =\t");
6067 for c in cipher.clone()
6068 { print!("{:02X} ", c); }
6069 println!();
6070 let mut txt = String::new();
6071 for c in cipher.clone()
6072 { write!(txt, "{:02X} ", c); }
6073 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
6074
6075 let mut recovered = [0u8; 8];
6076 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6077
6078 print!("Ba =\t");
6079 for b in recovered.clone()
6080 { print!("{:02X} ", b); }
6081 println!();
6082 let mut txt = String::new();
6083 for c in recovered.clone()
6084 { write!(txt, "{:02X} ", c); }
6085 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6086
6087 let mut converted = String::new();
6088 unsafe { converted.as_mut_vec() }.write(&recovered);
6089 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6090 println!("Bb =\t{}", converted);
6091 assert_eq!(converted, "7 bytes");
6092 assert_eq!(converted, message);
6093 println!();
6094
6095 // Normal case for the message of 8 bytes
6096 let key = 0x_1234567890ABCDEF_u64;
6097 println!("K =\t{:#016X}", key);
6098 let mut a_des = DES::new_with_key_u64(key);
6099
6100 let message = "I am OK.";
6101 println!("M =\t{}", message);
6102 let mut cipher = [0_u8; 16];
6103 a_des.encrypt_str_into_array(&message, &mut cipher);
6104 print!("C =\t");
6105 for c in cipher.clone()
6106 { print!("{:02X} ", c); }
6107 println!();
6108 let mut txt = String::new();
6109 for c in cipher.clone()
6110 { write!(txt, "{:02X} ", c); }
6111 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
6112
6113 let mut recovered = [0u8; 16];
6114 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6115
6116 print!("Ba =\t");
6117 for b in recovered.clone()
6118 { print!("{:02X} ", b); }
6119 println!();
6120 let mut txt = String::new();
6121 for c in recovered.clone()
6122 { write!(txt, "{:02X} ", c); }
6123 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6124
6125 let mut converted = String::new();
6126 unsafe { converted.as_mut_vec() }.write(&recovered);
6127 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6128 println!("Bb =\t{}", converted);
6129 assert_eq!(converted, "I am OK.");
6130 assert_eq!(converted, message);
6131 println!();
6132
6133 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6134 let key = 0x_1234567890ABCDEF_u64;
6135 println!("K =\t{:#016X}", key);
6136 let mut a_des = DES::new_with_key_u64(key);
6137
6138 let message = "PARK Youngho";
6139 println!("M =\t{}", message);
6140 let mut cipher = [0_u8; 16];
6141 a_des.encrypt_str_into_array(&message, &mut cipher);
6142 print!("C =\t");
6143 for c in cipher.clone()
6144 { print!("{:02X} ", c); }
6145 println!();
6146 let mut txt = String::new();
6147 for c in cipher.clone()
6148 { write!(txt, "{:02X} ", c); }
6149 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
6150
6151 let mut recovered = [0u8; 16];
6152 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6153
6154 print!("Ba =\t");
6155 for b in recovered.clone()
6156 { print!("{:02X} ", b); }
6157 println!();
6158 let mut txt = String::new();
6159 for c in recovered.clone()
6160 { write!(txt, "{:02X} ", c); }
6161 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6162
6163 let mut converted = String::new();
6164 unsafe { converted.as_mut_vec() }.write(&recovered);
6165 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6166 println!("Bb =\t{}", converted);
6167 assert_eq!(converted, "PARK Youngho");
6168 assert_eq!(converted, message);
6169 println!();
6170
6171 // Normal case for the message of 16 bytes
6172 let key = 0x_1234567890ABCDEF_u64;
6173 println!("K =\t{:#016X}", key);
6174 let mut a_des = DES::new_with_key_u64(key);
6175
6176 let message = "고맙습니다.";
6177 println!("M =\t{}", message);
6178 let mut cipher = [0_u8; 24];
6179 a_des.encrypt_str_into_array(&message, &mut cipher);
6180 print!("C =\t");
6181 for c in cipher.clone()
6182 { print!("{:02X} ", c); }
6183 println!();
6184 let mut txt = String::new();
6185 for c in cipher.clone()
6186 { write!(txt, "{:02X} ", c); }
6187 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
6188
6189 let mut recovered = [0u8; 24];
6190 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
6191
6192 print!("Ba =\t");
6193 for b in recovered.clone()
6194 { print!("{:02X} ", b); }
6195 println!();
6196 let mut txt = String::new();
6197 for c in recovered.clone()
6198 { write!(txt, "{:02X} ", c); }
6199 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6200
6201 let mut converted = String::new();
6202 unsafe { converted.as_mut_vec() }.write(&recovered);
6203 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6204 println!("Bb =\t{}", converted);
6205 assert_eq!(converted, "고맙습니다.");
6206 assert_eq!(converted, message);
6207 println!("-------------------------------");
6208}
6209
6210fn des_decrypt_array_with_padding_pkcs7_ecb_into_string()
6211{
6212 println!("des_decrypt_array_with_padding_pkcs7_ecb_into_string()");
6213 use std::io::Write;
6214 use std::fmt::Write as _;
6215 use cryptocol::symmetric::{ DES, DES_Expanded, ECB_PKCS7 };
6216
6217 // Normal case
6218 let key = 0x_1234567890ABCDEF_u64;
6219 println!("K =\t{:#016X}", key);
6220 let mut a_des = DES::new_with_key_u64(key);
6221
6222 let message = "In the beginning God created the heavens and the earth.";
6223 println!("M =\t{}", message);
6224 let mut cipher = [0_u8; 56];
6225 a_des.encrypt_str_into_array(&message, &mut cipher);
6226 print!("C (16 rounds) =\t");
6227 for c in cipher.clone()
6228 { print!("{:02X} ", c); }
6229 println!();
6230 let mut txt = String::new();
6231 for c in cipher.clone()
6232 { write!(txt, "{:02X} ", c); }
6233 assert_eq!(txt, "6F 10 01 6D 99 BF 41 F8 BC 00 A8 1D 81 B7 4B 20 6F B5 30 0A 14 03 A9 8E 69 E7 A6 33 42 AF 97 59 ED 9D E0 95 35 DC DF 0D 99 58 FA 92 13 50 4D 50 D3 4E 76 9C C5 BB 9E CB ");
6234
6235 let mut recovered = String::new();
6236 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6237 println!("B (16 rounds) =\t{}", recovered);
6238 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6239 assert_eq!(recovered, message);
6240 println!();
6241
6242 // Expanded case for 128 rounds
6243 let key = 0x_1234567890ABCDEF_u64;
6244 println!("K =\t{:#016X}", key);
6245 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6246
6247 let message = "In the beginning God created the heavens and the earth.";
6248 println!("M =\t{}", message);
6249 let mut cipher = [0_u8; 56];
6250 a_des.encrypt_str_into_array(&message, &mut cipher);
6251 print!("C (128 rounds) =\t");
6252 for c in cipher.clone()
6253 { print!("{:02X} ", c); }
6254 println!();
6255 let mut txt = String::new();
6256 for c in cipher.clone()
6257 { write!(txt, "{:02X} ", c); }
6258 assert_eq!(txt, "DD C6 D8 D1 B0 66 D9 AC F7 F3 B4 FD D6 6C ED 78 20 FB A6 8D 35 38 EA 65 B0 65 23 05 FF D4 53 B1 D1 E0 C5 52 36 1E AC E2 19 EF 94 B8 98 04 A9 69 CC 6A BC 81 7D 6B 29 C0 ");
6259
6260 let mut recovered = String::new();
6261 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6262 println!("B (128 rounds) =\t{}", recovered);
6263 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6264 assert_eq!(recovered, message);
6265 println!();
6266
6267 // Expanded case for 0 rounds which means that key is meaningless
6268 let key1 = 0x_1234567890ABCDEF_u64;
6269 let key2 = 0_u64;
6270 println!("K =\t{:#016X}", key);
6271 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6272 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6273
6274 let message = "In the beginning God created the heavens and the earth.";
6275 println!("M =\t{}", message);
6276 let mut cipher1 = [0_u8; 56];
6277 let mut cipher2 = [0_u8; 56];
6278 c_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher1);
6279 d_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher2);
6280 print!("C (0 rounds) =\t");
6281 for c in cipher1.clone()
6282 { print!("{:02X} ", c); }
6283 println!();
6284 let mut txt = String::new();
6285 for c in cipher1.clone()
6286 { write!(txt, "{:02X} ", c); }
6287 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
6288 print!("D (0 rounds) =\t");
6289 for c in cipher2.clone()
6290 { print!("{:02X} ", c); }
6291 println!();
6292 let mut txt = String::new();
6293 for c in cipher2.clone()
6294 { write!(txt, "{:02X} ", c); }
6295 assert_eq!(txt, "86 9D 10 B8 94 9A 10 91 9A 9B 96 9D 9D 96 9D 9B 10 8B 9F 98 10 93 B1 9A 92 B8 9A 98 10 B8 94 9A 10 94 9A 92 B9 9A 9D B3 10 92 9D 98 10 B8 94 9A 10 9A 92 B1 B8 94 1D 02 ");
6296
6297 let mut recovered1 = String::new();
6298 let mut recovered2 = String::new();
6299 c_des.decrypt_array_into_string(&cipher1, &mut recovered1);
6300 d_des.decrypt_array_into_string(&cipher2, &mut recovered2);
6301 println!("B1 (0 rounds) =\t{}", recovered1);
6302 println!("B2 (0 rounds) =\t{}", recovered2);
6303 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6304 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6305 assert_eq!(recovered1, message);
6306 assert_eq!(recovered2, message);
6307 assert_eq!(recovered1, recovered2);
6308 println!();
6309
6310 // Normal case for the message of 0 bytes
6311 let key = 0x_1234567890ABCDEF_u64;
6312 println!("K =\t{:#016X}", key);
6313 let mut a_des = DES::new_with_key_u64(key);
6314
6315 let message = "";
6316 println!("M =\t{}", message);
6317 let mut cipher = [0_u8; 8];
6318 a_des.encrypt_str_into_array(&message, &mut cipher);
6319 print!("C =\t");
6320 for c in cipher.clone()
6321 { print!("{:02X} ", c); }
6322 println!();
6323 let mut txt = String::new();
6324 for c in cipher.clone()
6325 { write!(txt, "{:02X} ", c); }
6326 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
6327
6328 let mut recovered = String::new();
6329 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6330 println!("B =\t{}", recovered);
6331 assert_eq!(recovered, "");
6332 assert_eq!(recovered, message);
6333 println!();
6334
6335 // Normal case for the message shorter than 8 bytes
6336 let key = 0x_1234567890ABCDEF_u64;
6337 println!("K =\t{:#016X}", key);
6338 let mut a_des = DES::new_with_key_u64(key);
6339
6340 let message = "7 bytes";
6341 println!("M =\t{}", message);
6342 let mut cipher = [0_u8; 8];
6343 a_des.encrypt_str_into_array(&message, &mut cipher);
6344 print!("C =\t");
6345 for c in cipher.clone()
6346 { print!("{:02X} ", c); }
6347 println!();
6348 let mut txt = String::new();
6349 for c in cipher.clone()
6350 { write!(txt, "{:02X} ", c); }
6351 assert_eq!(txt, "F6 F0 41 DD 55 55 3B 35 ");
6352
6353 let mut recovered = String::new();
6354 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6355 println!("B =\t{}", recovered);
6356 assert_eq!(recovered, "7 bytes");
6357 assert_eq!(recovered, message);
6358 println!();
6359
6360 // Normal case for the message of 8 bytes
6361 let key = 0x_1234567890ABCDEF_u64;
6362 println!("K =\t{:#016X}", key);
6363 let mut a_des = DES::new_with_key_u64(key);
6364
6365 let message = "I am OK.";
6366 println!("M =\t{}", message);
6367 let mut cipher = [0_u8; 16];
6368 a_des.encrypt_str_into_array(&message, &mut cipher);
6369 print!("C =\t");
6370 for c in cipher.clone()
6371 { print!("{:02X} ", c); }
6372 println!();
6373 let mut txt = String::new();
6374 for c in cipher.clone()
6375 { write!(txt, "{:02X} ", c); }
6376 assert_eq!(txt, "27 F5 93 EE 76 DC 64 87 41 7F 89 79 08 CD A1 4C ");
6377
6378 let mut recovered = String::new();
6379 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6380 println!("B =\t{}", recovered);
6381 assert_eq!(recovered, "I am OK.");
6382 assert_eq!(recovered, message);
6383 println!();
6384
6385 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6386 let key = 0x_1234567890ABCDEF_u64;
6387 println!("K =\t{:#016X}", key);
6388 let mut a_des = DES::new_with_key_u64(key);
6389
6390 let message = "PARK Youngho";
6391 println!("M =\t{}", message);
6392 let mut cipher = [0_u8; 16];
6393 a_des.encrypt_str_into_array(&message, &mut cipher);
6394 print!("C =\t");
6395 for c in cipher.clone()
6396 { print!("{:02X} ", c); }
6397 println!();
6398 let mut txt = String::new();
6399 for c in cipher.clone()
6400 { write!(txt, "{:02X} ", c); }
6401 assert_eq!(txt, "8E 52 20 47 78 78 51 B7 00 69 10 77 91 B7 52 36 ");
6402
6403 let mut recovered = String::new();
6404 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6405 println!("B =\t{}", recovered);
6406 assert_eq!(recovered, "PARK Youngho");
6407 assert_eq!(recovered, message);
6408 println!();
6409
6410 // Normal case for the message of 16 bytes
6411 let key = 0x_1234567890ABCDEF_u64;
6412 println!("K =\t{:#016X}", key);
6413 let mut a_des = DES::new_with_key_u64(key);
6414
6415 let message = "고맙습니다.";
6416 println!("M =\t{}", message);
6417 let mut cipher = [0_u8; 24];
6418 a_des.encrypt_str_into_array(&message, &mut cipher);
6419 print!("C =\t");
6420 for c in cipher.clone()
6421 { print!("{:02X} ", c); }
6422 println!();
6423 let mut txt = String::new();
6424 for c in cipher.clone()
6425 { write!(txt, "{:02X} ", c); }
6426 assert_eq!(txt, "20 83 6B 12 1D 3A 5D BA 4D D6 5F 5A 8E 2E AC E7 41 7F 89 79 08 CD A1 4C ");
6427
6428 let mut recovered = String::new();
6429 a_des.decrypt_array_into_string(&cipher, &mut recovered);
6430 println!("B =\t{}", recovered);
6431 assert_eq!(recovered, "고맙습니다.");
6432 assert_eq!(recovered, message);
6433 println!("-------------------------------");
6434}54fn des_encrypt_cfb()
55{
56 println!("des_encrypt_cfb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
60
61 // Normal case
62 let key = 0x_1234567890ABCDEF_u64;
63 println!("K =\t{:#016X}", key);
64 let mut a_des = DES::new_with_key_u64(key);
65
66 let message = "In the beginning God created the heavens and the earth.";
67 println!("M =\t{}", message);
68 let iv = 0x_FEDCBA0987654321_u64;
69 println!("IV = {}", iv);
70 let mut cipher = [0_u8; 55];
71 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
72 print!("C (16 rounds) =\t");
73 for c in cipher.clone()
74 { print!("{:02X} ", c); }
75 println!();
76 let mut txt = String::new();
77 for c in cipher.clone()
78 { write!(txt, "{:02X} ", c); }
79 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
80 println!();
81
82 // Expanded case for 128 rounds
83 let key = 0x_1234567890ABCDEF_u64;
84 println!("K =\t{:#016X}", key);
85 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
86
87 let message = "In the beginning God created the heavens and the earth.";
88 println!("M =\t{}", message);
89
90 let iv = 0x_FEDCBA0987654321_u64;
91 println!("IV = {}", iv);
92 let mut cipher = [0_u8; 55];
93 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
94 print!("C (128 rounds) =\t");
95 for c in cipher.clone()
96 { print!("{:02X} ", c); }
97 println!();
98 let mut txt = String::new();
99 for c in cipher.clone()
100 { write!(txt, "{:02X} ", c); }
101 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
102 println!();
103
104 // Expanded case for 0 rounds which means that key is meaningless
105 let key1 = 0x_1234567890ABCDEF_u64;
106 let key2 = 0_u64;
107 println!("K =\t{:#016X}", key);
108 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
109 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
110
111 let message = "In the beginning God created the heavens and the earth.";
112 println!("M =\t{}", message);
113 let iv = 0x_FEDCBA0987654321_u64;
114 println!("IV = {}", iv);
115 let mut cipher1 = [0_u8; 55];
116 let mut cipher2 = [0_u8; 55];
117 c_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher1.as_mut_ptr());
118 d_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher2.as_mut_ptr());
119 print!("C (0 rounds) =\t");
120 for c in cipher1.clone()
121 { print!("{:02X} ", c); }
122 println!();
123 let mut txt = String::new();
124 for c in cipher1.clone()
125 { write!(txt, "{:02X} ", c); }
126 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
127 print!("D (0 rounds) =\t");
128 for c in cipher2.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher2.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
135 println!();
136
137 // Normal case for the message of 0 bytes
138 let key = 0x_1234567890ABCDEF_u64;
139 println!("K =\t{:#016X}", key);
140 let mut a_des = DES::new_with_key_u64(key);
141
142 let message = "";
143 println!("M =\t{}", message);
144 let iv = 0x_FEDCBA0987654321_u64;
145 println!("IV = {}", iv);
146 let mut cipher = [0_u8; 0];
147 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
148 print!("C =\t");
149 for c in cipher.clone()
150 { print!("{:02X} ", c); }
151 println!();
152 let mut txt = String::new();
153 for c in cipher.clone()
154 { write!(txt, "{:02X} ", c); }
155 assert_eq!(txt, "");
156 println!();
157
158 // Normal case for the message shorter than 8 bytes
159 let key = 0x_1234567890ABCDEF_u64;
160 println!("K =\t{:#016X}", key);
161 let mut a_des = DES::new_with_key_u64(key);
162
163 let message = "7 bytes";
164 println!("M =\t{}", message);
165 let iv = 0x_FEDCBA0987654321_u64;
166 println!("IV = {}", iv);
167 let mut cipher = [0_u8; 7];
168 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
169 print!("C =\t");
170 for c in cipher.clone()
171 { print!("{:02X} ", c); }
172 println!();
173 let mut txt = String::new();
174 for c in cipher.clone()
175 { write!(txt, "{:02X} ", c); }
176 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
177 println!();
178
179 // Normal case for the message of 8 bytes
180 let key = 0x_1234567890ABCDEF_u64;
181 println!("K =\t{:#016X}", key);
182 let mut a_des = DES::new_with_key_u64(key);
183
184 let message = "I am OK.";
185 println!("M =\t{}", message);
186 let iv = 0x_FEDCBA0987654321_u64;
187 println!("IV = {}", iv);
188 let mut cipher = [0_u8; 8];
189 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
190 print!("C =\t");
191 for c in cipher.clone()
192 { print!("{:02X} ", c); }
193 println!();
194 let mut txt = String::new();
195 for c in cipher.clone()
196 { write!(txt, "{:02X} ", c); }
197 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
198 println!();
199
200 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
201 let key = 0x_1234567890ABCDEF_u64;
202 println!("K =\t{:#016X}", key);
203 let mut a_des = DES::new_with_key_u64(key);
204
205 let message = "PARK Youngho";
206 println!("M =\t{}", message);
207 let iv = 0x_FEDCBA0987654321_u64;
208 println!("IV = {}", iv);
209 let mut cipher = [0_u8; 12];
210 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
211 print!("C =\t");
212 for c in cipher.clone()
213 { print!("{:02X} ", c); }
214 println!();
215 let mut txt = String::new();
216 for c in cipher.clone()
217 { write!(txt, "{:02X} ", c); }
218 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
219 println!();
220
221 // Normal case for the message of 16 bytes
222 let key = 0x_1234567890ABCDEF_u64;
223 println!("K =\t{:#016X}", key);
224 let mut a_des = DES::new_with_key_u64(key);
225
226 let message = "고맙습니다.";
227 println!("M =\t{}", message);
228 let iv = 0x_FEDCBA0987654321_u64;
229 println!("IV = {}", iv);
230 let mut cipher = [0_u8; 16];
231 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
232 print!("C =\t");
233 for c in cipher.clone()
234 { print!("{:02X} ", c); }
235 println!();
236 let mut txt = String::new();
237 for c in cipher.clone()
238 { write!(txt, "{:02X} ", c); }
239 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
240 println!("-------------------------------");
241}
242
243fn des_encrypt_cfb_into_vec()
244{
245 println!("des_encrypt_cfb_into_vec()");
246 use std::io::Write;
247 use std::fmt::Write as _;
248 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
249
250 // Normal case
251 let key = 0x_1234567890ABCDEF_u64;
252 println!("K =\t{:#016X}", key);
253 let mut a_des = DES::new_with_key_u64(key);
254
255 let message = "In the beginning God created the heavens and the earth.";
256 println!("M =\t{}", message);
257 let iv = 0x_FEDCBA0987654321_u64;
258 println!("IV = {}", iv);
259 let mut cipher = Vec::<u8>::new();
260 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
261 print!("C (16 rounds) =\t");
262 for c in cipher.clone()
263 { print!("{:02X} ", c); }
264 println!();
265 let mut txt = String::new();
266 for c in cipher.clone()
267 { write!(txt, "{:02X} ", c); }
268 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
269 println!();
270
271 // Expanded case for 128 rounds
272 let key = 0x_1234567890ABCDEF_u64;
273 println!("K =\t{:#016X}", key);
274 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
275
276 let message = "In the beginning God created the heavens and the earth.";
277 println!("M =\t{}", message);
278 let iv = 0x_FEDCBA0987654321_u64;
279 println!("IV = {}", iv);
280 let mut cipher = Vec::<u8>::new();
281 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
282 print!("C (128 rounds) =\t");
283 for c in cipher.clone()
284 { print!("{:02X} ", c); }
285 println!();
286 let mut txt = String::new();
287 for c in cipher.clone()
288 { write!(txt, "{:02X} ", c); }
289 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
290 println!();
291
292 // Expanded case for 0 rounds which means that key is meaningless
293 let key1 = 0x_1234567890ABCDEF_u64;
294 let key2 = 0_u64;
295 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
296 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
297 println!("K =\t{:#016X}", key);
298
299 let message = "In the beginning God created the heavens and the earth.";
300 println!("M =\t{}", message);
301 let iv = 0x_FEDCBA0987654321_u64;
302 println!("IV = {}", iv);
303 let mut cipher1 = Vec::<u8>::new();
304 let mut cipher2 = Vec::<u8>::new();
305 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
306 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
307 print!("C (0 rounds) =\t");
308 for c in cipher1.clone()
309 { print!("{:02X} ", c); }
310 println!();
311 let mut txt = String::new();
312 for c in cipher1.clone()
313 { write!(txt, "{:02X} ", c); }
314 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
315 print!("D (0 rounds) =\t");
316 for c in cipher2.clone()
317 { print!("{:02X} ", c); }
318 println!();
319 let mut txt = String::new();
320 for c in cipher2.clone()
321 { write!(txt, "{:02X} ", c); }
322 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
323 println!();
324
325 // Normal case for the message of 0 bytes
326 let key = 0x_1234567890ABCDEF_u64;
327 println!("K =\t{:#016X}", key);
328 let mut a_des = DES::new_with_key_u64(key);
329
330 let message = "";
331 println!("M =\t{}", message);
332 let iv = 0x_FEDCBA0987654321_u64;
333 println!("IV = {}", iv);
334 let mut cipher = Vec::<u8>::new();
335 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
336 print!("C =\t");
337 for c in cipher.clone()
338 { print!("{:02X} ", c); }
339 println!();
340 let mut txt = String::new();
341 for c in cipher.clone()
342 { write!(txt, "{:02X} ", c); }
343 assert_eq!(txt, "");
344 println!();
345
346 // Normal case for the message shorter than 8 bytes
347 let key = 0x_1234567890ABCDEF_u64;
348 println!("K =\t{:#016X}", key);
349 let mut a_des = DES::new_with_key_u64(key);
350
351 let message = "7 bytes";
352 println!("M =\t{}", message);
353 let iv = 0x_FEDCBA0987654321_u64;
354 println!("IV = {}", iv);
355 let mut cipher = Vec::<u8>::new();
356 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
357 print!("C =\t");
358 for c in cipher.clone()
359 { print!("{:02X} ", c); }
360 println!();
361 let mut txt = String::new();
362 for c in cipher.clone()
363 { write!(txt, "{:02X} ", c); }
364 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
365 println!();
366
367 // Normal case for the message of 8 bytes
368 let key = 0x_1234567890ABCDEF_u64;
369 println!("K =\t{:#016X}", key);
370 let mut a_des = DES::new_with_key_u64(key);
371
372 let message = "I am OK.";
373 println!("M =\t{}", message);
374 let iv = 0x_FEDCBA0987654321_u64;
375 println!("IV = {}", iv);
376 let mut cipher = Vec::<u8>::new();
377 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
378 print!("C =\t");
379 for c in cipher.clone()
380 { print!("{:02X} ", c); }
381 println!();
382 let mut txt = String::new();
383 for c in cipher.clone()
384 { write!(txt, "{:02X} ", c); }
385 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
386 println!();
387
388 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
389 let key = 0x_1234567890ABCDEF_u64;
390 println!("K =\t{:#016X}", key);
391 let mut a_des = DES::new_with_key_u64(key);
392
393 let message = "PARK Youngho";
394 println!("M =\t{}", message);
395 let iv = 0x_FEDCBA0987654321_u64;
396 println!("IV = {}", iv);
397 let mut cipher = Vec::<u8>::new();
398 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
399 print!("C =\t");
400 for c in cipher.clone()
401 { print!("{:02X} ", c); }
402 println!();
403 let mut txt = String::new();
404 for c in cipher.clone()
405 { write!(txt, "{:02X} ", c); }
406 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
407 println!();
408
409 // Normal case for the message of 16 bytes
410 let key = 0x_1234567890ABCDEF_u64;
411 println!("K =\t{:#016X}", key);
412 let mut a_des = DES::new_with_key_u64(key);
413
414 let message = "고맙습니다.";
415 println!("M =\t{}", message);
416 let iv = 0x_FEDCBA0987654321_u64;
417 println!("IV = {}", iv);
418 let mut cipher = Vec::<u8>::new();
419 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
420 print!("C =\t");
421 for c in cipher.clone()
422 { print!("{:02X} ", c); }
423 println!();
424 let mut txt = String::new();
425 for c in cipher.clone()
426 { write!(txt, "{:02X} ", c); }
427 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
428 println!("-------------------------------");
429}
430
431fn des_encrypt_cfb_into_array()
432{
433 println!("des_encrypt_cfb_into_array()");
434 use std::io::Write;
435 use std::fmt::Write as _;
436 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
437
438 // Normal case
439 let key = 0x_1234567890ABCDEF_u64;
440 println!("K =\t{:#016X}", key);
441 let mut a_des = DES::new_with_key_u64(key);
442
443 let message = "In the beginning God created the heavens and the earth.";
444 println!("M =\t{}", message);
445 let iv = 0x_FEDCBA0987654321_u64;
446 println!("IV = {}", iv);
447 let mut cipher = [0_u8; 55];
448 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
449 print!("C (16 rounds) =\t");
450 for c in cipher.clone()
451 { print!("{:02X} ", c); }
452 println!();
453 let mut txt = String::new();
454 for c in cipher.clone()
455 { write!(txt, "{:02X} ", c); }
456 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
457 println!();
458
459 // Expanded case for 128 rounds
460 let key = 0x_1234567890ABCDEF_u64;
461 println!("K =\t{:#016X}", key);
462 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
463
464 let message = "In the beginning God created the heavens and the earth.";
465 println!("M =\t{}", message);
466 let iv = 0x_FEDCBA0987654321_u64;
467 println!("IV = {}", iv);
468 let mut cipher = [0_u8; 55];
469 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
470 print!("C (128 rounds) =\t");
471 for c in cipher.clone()
472 { print!("{:02X} ", c); }
473 println!();
474 let mut txt = String::new();
475 for c in cipher.clone()
476 { write!(txt, "{:02X} ", c); }
477 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
478 println!();
479
480 // Expanded case for 0 rounds which means that key is meaningless
481 let key1 = 0x_1234567890ABCDEF_u64;
482 let key2 = 0_u64;
483 println!("K =\t{:#016X}", key);
484 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
485 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
486
487 let message = "In the beginning God created the heavens and the earth.";
488 println!("M =\t{}", message);
489 let iv = 0x_FEDCBA0987654321_u64;
490 println!("IV = {}", iv);
491 let mut cipher1 = [0_u8; 55];
492 let mut cipher2 = [0_u8; 55];
493 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
494 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
495 print!("C (0 rounds) =\t");
496 for c in cipher1.clone()
497 { print!("{:02X} ", c); }
498 println!();
499 let mut txt = String::new();
500 for c in cipher1.clone()
501 { write!(txt, "{:02X} ", c); }
502 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
503 print!("D (0 rounds) =\t");
504 for c in cipher2.clone()
505 { print!("{:02X} ", c); }
506 println!();
507 let mut txt = String::new();
508 for c in cipher2.clone()
509 { write!(txt, "{:02X} ", c); }
510 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
511 println!();
512
513 // Normal case for the message of 0 bytes
514 let key = 0x_1234567890ABCDEF_u64;
515 println!("K =\t{:#016X}", key);
516 let mut a_des = DES::new_with_key_u64(key);
517
518 let message = "";
519 println!("M =\t{}", message);
520 let iv = 0x_FEDCBA0987654321_u64;
521 println!("IV = {}", iv);
522 let mut cipher = [0_u8; 0];
523 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
524 print!("C =\t");
525 for c in cipher.clone()
526 { print!("{:02X} ", c); }
527 println!();
528 let mut txt = String::new();
529 for c in cipher.clone()
530 { write!(txt, "{:02X} ", c); }
531 assert_eq!(txt, "");
532 println!();
533
534 // Normal case for the message shorter than 8 bytes
535 let key = 0x_1234567890ABCDEF_u64;
536 println!("K =\t{:#016X}", key);
537 let mut a_des = DES::new_with_key_u64(key);
538
539 let message = "7 bytes";
540 println!("M =\t{}", message);
541 let iv = 0x_FEDCBA0987654321_u64;
542 println!("IV = {}", iv);
543 let mut cipher = [0_u8; 7];
544 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
545 print!("C =\t");
546 for c in cipher.clone()
547 { print!("{:02X} ", c); }
548 println!();
549 let mut txt = String::new();
550 for c in cipher.clone()
551 { write!(txt, "{:02X} ", c); }
552 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
553 println!();
554
555 // Normal case for the message of 8 bytes
556 let key = 0x_1234567890ABCDEF_u64;
557 println!("K =\t{:#016X}", key);
558 let mut a_des = DES::new_with_key_u64(key);
559
560 let message = "I am OK.";
561 println!("M =\t{}", message);
562 let iv = 0x_FEDCBA0987654321_u64;
563 println!("IV = {}", iv);
564 let mut cipher = [0_u8; 8];
565 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
566 print!("C =\t");
567 for c in cipher.clone()
568 { print!("{:02X} ", c); }
569 println!();
570 let mut txt = String::new();
571 for c in cipher.clone()
572 { write!(txt, "{:02X} ", c); }
573 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
574 println!();
575
576 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
577 let key = 0x_1234567890ABCDEF_u64;
578 println!("K =\t{:#016X}", key);
579 let mut a_des = DES::new_with_key_u64(key);
580
581 let message = "PARK Youngho";
582 println!("M =\t{}", message);
583 let iv = 0x_FEDCBA0987654321_u64;
584 println!("IV = {}", iv);
585 let mut cipher = [0_u8; 12];
586 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
587 print!("C =\t");
588 for c in cipher.clone()
589 { print!("{:02X} ", c); }
590 println!();
591 let mut txt = String::new();
592 for c in cipher.clone()
593 { write!(txt, "{:02X} ", c); }
594 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
595 println!();
596
597 // Normal case for the message of 16 bytes
598 let key = 0x_1234567890ABCDEF_u64;
599 println!("K =\t{:#016X}", key);
600 let mut a_des = DES::new_with_key_u64(key);
601
602 let message = "고맙습니다.";
603 println!("M =\t{}", message);
604 let iv = 0x_FEDCBA0987654321_u64;
605 println!("IV = {}", iv);
606 let mut cipher = [0_u8; 16];
607 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
608 print!("C =\t");
609 for c in cipher.clone()
610 { print!("{:02X} ", c); }
611 println!();
612 let mut txt = String::new();
613 for c in cipher.clone()
614 { write!(txt, "{:02X} ", c); }
615 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
616 println!("-------------------------------");
617}
618
619fn des_encrypt_str_cfb()
620{
621 println!("des_encrypt_str_cfb()");
622 use std::io::Write;
623 use std::fmt::Write as _;
624 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
625
626 // Normal case
627 let key = 0x_1234567890ABCDEF_u64;
628 println!("K =\t{:#016X}", key);
629 let mut a_des = DES::new_with_key_u64(key);
630
631 let message = "In the beginning God created the heavens and the earth.";
632 println!("M =\t{}", message);
633 let iv = 0x_FEDCBA0987654321_u64;
634 println!("IV = {}", iv);
635 let mut cipher = [0_u8; 55];
636 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
637 print!("C (16 rounds) =\t");
638 for c in cipher.clone()
639 { print!("{:02X} ", c); }
640 println!();
641 let mut txt = String::new();
642 for c in cipher.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
645 println!();
646
647 // Expanded case for 128 rounds
648 let key = 0x_1234567890ABCDEF_u64;
649 println!("K =\t{:#016X}", key);
650 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
651
652 let message = "In the beginning God created the heavens and the earth.";
653 println!("M =\t{}", message);
654 let iv = 0x_FEDCBA0987654321_u64;
655 println!("IV = {}", iv);
656 let mut cipher = [0_u8; 55];
657 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
658 print!("C (128 rounds) =\t");
659 for c in cipher.clone()
660 { print!("{:02X} ", c); }
661 println!();
662 let mut txt = String::new();
663 for c in cipher.clone()
664 { write!(txt, "{:02X} ", c); }
665 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
666 println!();
667
668 // Expanded case for 0 rounds which means that key is meaningless
669 let key1 = 0x_1234567890ABCDEF_u64;
670 let key2 = 0_u64;
671 println!("K =\t{:#016X}", key);
672 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
673 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
674
675 let message = "In the beginning God created the heavens and the earth.";
676 println!("M =\t{}", message);
677 let iv = 0x_FEDCBA0987654321_u64;
678 println!("IV = {}", iv);
679 let mut cipher1 = [0_u8; 55];
680 let mut cipher2 = [0_u8; 55];
681 c_des.encrypt_str(iv, &message, cipher1.as_mut_ptr());
682 d_des.encrypt_str(iv, &message, cipher2.as_mut_ptr());
683 print!("C (0 rounds) =\t");
684 for c in cipher1.clone()
685 { print!("{:02X} ", c); }
686 println!();
687 let mut txt = String::new();
688 for c in cipher1.clone()
689 { write!(txt, "{:02X} ", c); }
690 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
691 print!("D (0 rounds) =\t");
692 for c in cipher2.clone()
693 { print!("{:02X} ", c); }
694 println!();
695 let mut txt = String::new();
696 for c in cipher2.clone()
697 { write!(txt, "{:02X} ", c); }
698 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
699 println!();
700
701 // Normal case for the message of 0 bytes
702 let key = 0x_1234567890ABCDEF_u64;
703 println!("K =\t{:#016X}", key);
704 let mut a_des = DES::new_with_key_u64(key);
705
706 let message = "";
707 println!("M =\t{}", message);
708 let iv = 0x_FEDCBA0987654321_u64;
709 println!("IV = {}", iv);
710 let mut cipher = [0_u8; 0];
711 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "");
720 println!();
721
722 // Normal case for the message shorter than 8 bytes
723 let key = 0x_1234567890ABCDEF_u64;
724 println!("K =\t{:#016X}", key);
725 let mut a_des = DES::new_with_key_u64(key);
726
727 let message = "7 bytes";
728 println!("M =\t{}", message);
729 let iv = 0x_FEDCBA0987654321_u64;
730 println!("IV = {}", iv);
731 let mut cipher = [0_u8; 7];
732 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
733 print!("C =\t");
734 for c in cipher.clone()
735 { print!("{:02X} ", c); }
736 println!();
737 let mut txt = String::new();
738 for c in cipher.clone()
739 { write!(txt, "{:02X} ", c); }
740 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
741 println!();
742
743 // Normal case for the message of 8 bytes
744 let key = 0x_1234567890ABCDEF_u64;
745 println!("K =\t{:#016X}", key);
746 let mut a_des = DES::new_with_key_u64(key);
747
748 let message = "I am OK.";
749 println!("M =\t{}", message);
750 let iv = 0x_FEDCBA0987654321_u64;
751 println!("IV = {}", iv);
752 let mut cipher = [0_u8; 8];
753 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
754 print!("C =\t");
755 for c in cipher.clone()
756 { print!("{:02X} ", c); }
757 println!();
758 let mut txt = String::new();
759 for c in cipher.clone()
760 { write!(txt, "{:02X} ", c); }
761 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
762 println!();
763
764 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
765 let key = 0x_1234567890ABCDEF_u64;
766 println!("K =\t{:#016X}", key);
767 let mut a_des = DES::new_with_key_u64(key);
768
769 let message = "PARK Youngho";
770 println!("M =\t{}", message);
771 let iv = 0x_FEDCBA0987654321_u64;
772 println!("IV = {}", iv);
773 let mut cipher = [0_u8; 12];
774 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
775 print!("C =\t");
776 for c in cipher.clone()
777 { print!("{:02X} ", c); }
778 println!();
779 let mut txt = String::new();
780 for c in cipher.clone()
781 { write!(txt, "{:02X} ", c); }
782 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
783 println!();
784
785 // Normal case for the message of 16 bytes
786 let key = 0x_1234567890ABCDEF_u64;
787 println!("K =\t{:#016X}", key);
788 let mut a_des = DES::new_with_key_u64(key);
789
790 let message = "고맙습니다.";
791 println!("M =\t{}", message);
792 let iv = 0x_FEDCBA0987654321_u64;
793 println!("IV = {}", iv);
794 let mut cipher = [0_u8; 16];
795 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
796 print!("C =\t");
797 for c in cipher.clone()
798 { print!("{:02X} ", c); }
799 println!();
800 let mut txt = String::new();
801 for c in cipher.clone()
802 { write!(txt, "{:02X} ", c); }
803 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
804 println!("-------------------------------");
805}
806
807fn des_encrypt_str_cfb_into_vec()
808{
809 println!("des_encrypt_str_cfb_into_vec()");
810 use std::io::Write;
811 use std::fmt::Write as _;
812 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
813
814 // Normal case
815 let key = 0x_1234567890ABCDEF_u64;
816 println!("K =\t{:#016X}", key);
817 let mut a_des = DES::new_with_key_u64(key);
818
819 let message = "In the beginning God created the heavens and the earth.";
820 println!("M =\t{}", message);
821 let iv = 0x_FEDCBA0987654321_u64;
822 println!("IV = {}", iv);
823 let mut cipher = Vec::<u8>::new();
824 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
825 print!("C (16 rounds) =\t");
826 for c in cipher.clone()
827 { print!("{:02X} ", c); }
828 println!();
829 let mut txt = String::new();
830 for c in cipher.clone()
831 { write!(txt, "{:02X} ", c); }
832 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
833 println!();
834
835 // Expanded case for 128 rounds
836 let key = 0x_1234567890ABCDEF_u64;
837 println!("K =\t{:#016X}", key);
838 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
839
840 let message = "In the beginning God created the heavens and the earth.";
841 println!("M =\t{}", message);
842 let iv = 0x_FEDCBA0987654321_u64;
843 println!("IV = {}", iv);
844 let mut cipher = Vec::<u8>::new();
845 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
846 print!("C (128 rounds) =\t");
847 for c in cipher.clone()
848 { print!("{:02X} ", c); }
849 println!();
850 let mut txt = String::new();
851 for c in cipher.clone()
852 { write!(txt, "{:02X} ", c); }
853 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
854 println!();
855
856 // Expanded case for 0 rounds which means that key is meaningless
857 let key1 = 0x_1234567890ABCDEF_u64;
858 let key2 = 0_u64;
859 println!("K =\t{:#016X}", key);
860 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
861 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
862
863 let message = "In the beginning God created the heavens and the earth.";
864 println!("M =\t{}", message);
865 let iv = 0x_FEDCBA0987654321_u64;
866 println!("IV = {}", iv);
867 let mut cipher1 = Vec::<u8>::new();
868 let mut cipher2 = Vec::<u8>::new();
869 c_des.encrypt_str_into_vec(iv, &message, &mut cipher1);
870 d_des.encrypt_str_into_vec(iv, &message, &mut cipher2);
871 print!("C (0 rounds) =\t");
872 for c in cipher1.clone()
873 { print!("{:02X} ", c); }
874 println!();
875 let mut txt = String::new();
876 for c in cipher1.clone()
877 { write!(txt, "{:02X} ", c); }
878 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
879 print!("D (0 rounds) =\t");
880 for c in cipher2.clone()
881 { print!("{:02X} ", c); }
882 println!();
883 let mut txt = String::new();
884 for c in cipher2.clone()
885 { write!(txt, "{:02X} ", c); }
886 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
887 println!();
888
889 // Normal case for the message of 0 bytes
890 let key = 0x_1234567890ABCDEF_u64;
891 println!("K =\t{:#016X}", key);
892 let mut a_des = DES::new_with_key_u64(key);
893
894 let message = "";
895 println!("M =\t{}", message);
896 let iv = 0x_FEDCBA0987654321_u64;
897 println!("IV = {}", iv);
898 let mut cipher = Vec::<u8>::new();
899 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
900 print!("C =\t");
901 for c in cipher.clone()
902 { print!("{:02X} ", c); }
903 println!();
904 let mut txt = String::new();
905 for c in cipher.clone()
906 { write!(txt, "{:02X} ", c); }
907 assert_eq!(txt, "");
908 println!();
909
910 // Normal case for the message shorter than 8 bytes
911 let key = 0x_1234567890ABCDEF_u64;
912 println!("K =\t{:#016X}", key);
913 let mut a_des = DES::new_with_key_u64(key);
914
915 let message = "7 bytes";
916 println!("M =\t{}", message);
917 let iv = 0x_FEDCBA0987654321_u64;
918 println!("IV = {}", iv);
919 let mut cipher = Vec::<u8>::new();
920 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
921 print!("C =\t");
922 for c in cipher.clone()
923 { print!("{:02X} ", c); }
924 println!();
925 let mut txt = String::new();
926 for c in cipher.clone()
927 { write!(txt, "{:02X} ", c); }
928 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
929 println!();
930
931 // Normal case for the message of 8 bytes
932 let key = 0x_1234567890ABCDEF_u64;
933 println!("K =\t{:#016X}", key);
934 let mut a_des = DES::new_with_key_u64(key);
935
936 let message = "I am OK.";
937 println!("M =\t{}", message);
938 let iv = 0x_FEDCBA0987654321_u64;
939 println!("IV = {}", iv);
940 let mut cipher = Vec::<u8>::new();
941 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
942 print!("C =\t");
943 for c in cipher.clone()
944 { print!("{:02X} ", c); }
945 println!();
946 let mut txt = String::new();
947 for c in cipher.clone()
948 { write!(txt, "{:02X} ", c); }
949 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
950 println!();
951
952 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
953 let key = 0x_1234567890ABCDEF_u64;
954 println!("K =\t{:#016X}", key);
955 let mut a_des = DES::new_with_key_u64(key);
956
957 let message = "PARK Youngho";
958 println!("M =\t{}", message);
959 let iv = 0x_FEDCBA0987654321_u64;
960 println!("IV = {}", iv);
961 let mut cipher = Vec::<u8>::new();
962 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
963 print!("C =\t");
964 for c in cipher.clone()
965 { print!("{:02X} ", c); }
966 println!();
967 let mut txt = String::new();
968 for c in cipher.clone()
969 { write!(txt, "{:02X} ", c); }
970 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
971 println!();
972
973 // Normal case for the message of 16 bytes
974 let key = 0x_1234567890ABCDEF_u64;
975 println!("K =\t{:#016X}", key);
976 let mut a_des = DES::new_with_key_u64(key);
977
978 let message = "고맙습니다.";
979 println!("M =\t{}", message);
980 let iv = 0x_FEDCBA0987654321_u64;
981 println!("IV = {}", iv);
982 let mut cipher = Vec::<u8>::new();
983 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
984 print!("C =\t");
985 for c in cipher.clone()
986 { print!("{:02X} ", c); }
987 println!();
988 let mut txt = String::new();
989 for c in cipher.clone()
990 { write!(txt, "{:02X} ", c); }
991 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
992 println!("-------------------------------");
993}
994
995fn des_encrypt_str_cfb_into_array()
996{
997 println!("des_encrypt_str_cfb_into_array()");
998 use std::io::Write;
999 use std::fmt::Write as _;
1000 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
1001
1002 // Normal case
1003 let key = 0x_1234567890ABCDEF_u64;
1004 println!("K =\t{:#016X}", key);
1005 let mut a_des = DES::new_with_key_u64(key);
1006
1007 let message = "In the beginning God created the heavens and the earth.";
1008 println!("M =\t{}", message);
1009 let iv = 0x_FEDCBA0987654321_u64;
1010 println!("IV = {}", iv);
1011 let mut cipher = [0_u8; 55];
1012 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1013 print!("C (16 rounds) =\t");
1014 for c in cipher.clone()
1015 { print!("{:02X} ", c); }
1016 println!();
1017 let mut txt = String::new();
1018 for c in cipher.clone()
1019 { write!(txt, "{:02X} ", c); }
1020 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
1021 println!();
1022
1023 // Expanded case for 128 rounds
1024 let key = 0x_1234567890ABCDEF_u64;
1025 println!("K =\t{:#016X}", key);
1026 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1027
1028 let message = "In the beginning God created the heavens and the earth.";
1029 println!("M =\t{}", message);
1030 let iv = 0x_FEDCBA0987654321_u64;
1031 println!("IV = {}", iv);
1032 let mut cipher = [0_u8; 55];
1033 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1034 print!("C (128 rounds) =\t");
1035 for c in cipher.clone()
1036 { print!("{:02X} ", c); }
1037 println!();
1038 let mut txt = String::new();
1039 for c in cipher.clone()
1040 { write!(txt, "{:02X} ", c); }
1041 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
1042 println!();
1043
1044 // Expanded case for 0 rounds which means that key is meaningless
1045 let key1 = 0x_1234567890ABCDEF_u64;
1046 let key2 = 0_u64;
1047 println!("K =\t{:#016X}", key);
1048 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1049 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1050
1051 let message = "In the beginning God created the heavens and the earth.";
1052 println!("M =\t{}", message);
1053 let iv = 0x_FEDCBA0987654321_u64;
1054 println!("IV = {}", iv);
1055 let mut cipher1 = [0_u8; 55];
1056 let mut cipher2 = [0_u8; 55];
1057 c_des.encrypt_str_into_array(iv, &message, &mut cipher1);
1058 d_des.encrypt_str_into_array(iv, &message, &mut cipher2);
1059 print!("C (0 rounds) =\t");
1060 for c in cipher1.clone()
1061 { print!("{:02X} ", c); }
1062 println!();
1063 let mut txt = String::new();
1064 for c in cipher1.clone()
1065 { write!(txt, "{:02X} ", c); }
1066 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1067 print!("D (0 rounds) =\t");
1068 for c in cipher2.clone()
1069 { print!("{:02X} ", c); }
1070 println!();
1071 let mut txt = String::new();
1072 for c in cipher2.clone()
1073 { write!(txt, "{:02X} ", c); }
1074 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1075 println!();
1076
1077 // Normal case for the message of 0 bytes
1078 let key = 0x_1234567890ABCDEF_u64;
1079 println!("K =\t{:#016X}", key);
1080 let mut a_des = DES::new_with_key_u64(key);
1081
1082 let message = "";
1083 println!("M =\t{}", message);
1084 let iv = 0x_FEDCBA0987654321_u64;
1085 println!("IV = {}", iv);
1086 let mut cipher = [0_u8; 0];
1087 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1088 print!("C =\t");
1089 for c in cipher.clone()
1090 { print!("{:02X} ", c); }
1091 println!();
1092 let mut txt = String::new();
1093 for c in cipher.clone()
1094 { write!(txt, "{:02X} ", c); }
1095 assert_eq!(txt, "");
1096 println!();
1097
1098 // Normal case for the message shorter than 8 bytes
1099 let key = 0x_1234567890ABCDEF_u64;
1100 println!("K =\t{:#016X}", key);
1101 let mut a_des = DES::new_with_key_u64(key);
1102
1103 let message = "7 bytes";
1104 println!("M =\t{}", message);
1105 let iv = 0x_FEDCBA0987654321_u64;
1106 println!("IV = {}", iv);
1107 let mut cipher = [0_u8; 7];
1108 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1109 print!("C =\t");
1110 for c in cipher.clone()
1111 { print!("{:02X} ", c); }
1112 println!();
1113 let mut txt = String::new();
1114 for c in cipher.clone()
1115 { write!(txt, "{:02X} ", c); }
1116 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1117 println!();
1118
1119 // Normal case for the message of 8 bytes
1120 let key = 0x_1234567890ABCDEF_u64;
1121 println!("K =\t{:#016X}", key);
1122 let mut a_des = DES::new_with_key_u64(key);
1123
1124 let message = "I am OK.";
1125 println!("M =\t{}", message);
1126 let iv = 0x_FEDCBA0987654321_u64;
1127 println!("IV = {}", iv);
1128 let mut cipher = [0_u8; 8];
1129 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1130 print!("C =\t");
1131 for c in cipher.clone()
1132 { print!("{:02X} ", c); }
1133 println!();
1134 let mut txt = String::new();
1135 for c in cipher.clone()
1136 { write!(txt, "{:02X} ", c); }
1137 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1138 println!();
1139
1140 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1141 let key = 0x_1234567890ABCDEF_u64;
1142 println!("K =\t{:#016X}", key);
1143 let mut a_des = DES::new_with_key_u64(key);
1144
1145 let message = "PARK Youngho";
1146 println!("M =\t{}", message);
1147 let iv = 0x_FEDCBA0987654321_u64;
1148 println!("IV = {}", iv);
1149 let mut cipher = [0_u8; 12];
1150 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1151 print!("C =\t");
1152 for c in cipher.clone()
1153 { print!("{:02X} ", c); }
1154 println!();
1155 let mut txt = String::new();
1156 for c in cipher.clone()
1157 { write!(txt, "{:02X} ", c); }
1158 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
1159 println!();
1160
1161 // Normal case for the message of 16 bytes
1162 let key = 0x_1234567890ABCDEF_u64;
1163 println!("K =\t{:#016X}", key);
1164 let mut a_des = DES::new_with_key_u64(key);
1165
1166 let message = "고맙습니다.";
1167 println!("M =\t{}", message);
1168 let iv = 0x_FEDCBA0987654321_u64;
1169 println!("IV = {}", iv);
1170 let mut cipher = [0_u8; 16];
1171 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1172 print!("C =\t");
1173 for c in cipher.clone()
1174 { print!("{:02X} ", c); }
1175 println!();
1176 let mut txt = String::new();
1177 for c in cipher.clone()
1178 { write!(txt, "{:02X} ", c); }
1179 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
1180 println!("-------------------------------");
1181}
1182
1183fn des_encrypt_string_cfb()
1184{
1185 println!("des_encrypt_string_cfb()");
1186 use std::io::Write;
1187 use std::fmt::Write as _;
1188 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
1189
1190 // Normal case
1191 let key = 0x_1234567890ABCDEF_u64;
1192 println!("K =\t{:#016X}", key);
1193 let mut a_des = DES::new_with_key_u64(key);
1194
1195 let message = "In the beginning God created the heavens and the earth.".to_string();
1196 println!("M =\t{}", message);
1197 let iv = 0x_FEDCBA0987654321_u64;
1198 println!("IV = {}", iv);
1199 let mut cipher = [0_u8; 55];
1200 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1201 print!("C (16 rounds) =\t");
1202 for c in cipher.clone()
1203 { print!("{:02X} ", c); }
1204 println!();
1205 let mut txt = String::new();
1206 for c in cipher.clone()
1207 { write!(txt, "{:02X} ", c); }
1208 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
1209 println!();
1210
1211 // Expanded case for 128 rounds
1212 let key = 0x_1234567890ABCDEF_u64;
1213 println!("K =\t{:#016X}", key);
1214 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1215
1216 let message = "In the beginning God created the heavens and the earth.".to_string();
1217 println!("M =\t{}", message);
1218 let iv = 0x_FEDCBA0987654321_u64;
1219 println!("IV = {}", iv);
1220 let mut cipher = [0_u8; 55];
1221 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1222 print!("C (128 rounds) =\t");
1223 for c in cipher.clone()
1224 { print!("{:02X} ", c); }
1225 println!();
1226 let mut txt = String::new();
1227 for c in cipher.clone()
1228 { write!(txt, "{:02X} ", c); }
1229 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
1230 println!();
1231
1232 // Expanded case for 0 rounds which means that key is meaningless
1233 let key1 = 0x_1234567890ABCDEF_u64;
1234 let key2 = 0_u64;
1235 println!("K =\t{:#016X}", key);
1236 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1237 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1238
1239 let message = "In the beginning God created the heavens and the earth.".to_string();
1240 println!("M =\t{}", message);
1241 let iv = 0x_FEDCBA0987654321_u64;
1242 println!("IV = {}", iv);
1243 let mut cipher1 = [0_u8; 55];
1244 let mut cipher2 = [0_u8; 55];
1245 c_des.encrypt_string(iv, &message, cipher1.as_mut_ptr());
1246 d_des.encrypt_string(iv, &message, cipher2.as_mut_ptr());
1247 print!("C (0 rounds) =\t");
1248 for c in cipher1.clone()
1249 { print!("{:02X} ", c); }
1250 println!();
1251 let mut txt = String::new();
1252 for c in cipher1.clone()
1253 { write!(txt, "{:02X} ", c); }
1254 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1255 print!("D (0 rounds) =\t");
1256 for c in cipher2.clone()
1257 { print!("{:02X} ", c); }
1258 println!();
1259 let mut txt = String::new();
1260 for c in cipher2.clone()
1261 { write!(txt, "{:02X} ", c); }
1262 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1263 println!();
1264
1265 // Normal case for the message of 0 bytes
1266 let key = 0x_1234567890ABCDEF_u64;
1267 println!("K =\t{:#016X}", key);
1268 let mut a_des = DES::new_with_key_u64(key);
1269
1270 let message = "".to_string();
1271 println!("M =\t{}", message);
1272 let iv = 0x_FEDCBA0987654321_u64;
1273 println!("IV = {}", iv);
1274 let mut cipher = [0_u8; 0];
1275 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1276 print!("C =\t");
1277 for c in cipher.clone()
1278 { print!("{:02X} ", c); }
1279 println!();
1280 let mut txt = String::new();
1281 for c in cipher.clone()
1282 { write!(txt, "{:02X} ", c); }
1283 assert_eq!(txt, "");
1284 println!();
1285
1286 // Normal case for the message shorter than 8 bytes
1287 let key = 0x_1234567890ABCDEF_u64;
1288 println!("K =\t{:#016X}", key);
1289 let mut a_des = DES::new_with_key_u64(key);
1290
1291 let message = "7 bytes".to_string();
1292 println!("M =\t{}", message);
1293 let iv = 0x_FEDCBA0987654321_u64;
1294 println!("IV = {}", iv);
1295 let mut cipher = [0_u8; 7];
1296 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1297 print!("C =\t");
1298 for c in cipher.clone()
1299 { print!("{:02X} ", c); }
1300 println!();
1301 let mut txt = String::new();
1302 for c in cipher.clone()
1303 { write!(txt, "{:02X} ", c); }
1304 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1305 println!();
1306
1307 // Normal case for the message of 8 bytes
1308 let key = 0x_1234567890ABCDEF_u64;
1309 println!("K =\t{:#016X}", key);
1310 let mut a_des = DES::new_with_key_u64(key);
1311
1312 let message = "I am OK.".to_string();
1313 println!("M =\t{}", message);
1314 let iv = 0x_FEDCBA0987654321_u64;
1315 println!("IV = {}", iv);
1316 let mut cipher = [0_u8; 8];
1317 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1318 print!("C =\t");
1319 for c in cipher.clone()
1320 { print!("{:02X} ", c); }
1321 println!();
1322 let mut txt = String::new();
1323 for c in cipher.clone()
1324 { write!(txt, "{:02X} ", c); }
1325 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1326 println!();
1327
1328 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1329 let key = 0x_1234567890ABCDEF_u64;
1330 println!("K =\t{:#016X}", key);
1331 let mut a_des = DES::new_with_key_u64(key);
1332
1333 let message = "PARK Youngho".to_string();
1334 println!("M =\t{}", message);
1335 let iv = 0x_FEDCBA0987654321_u64;
1336 println!("IV = {}", iv);
1337 let mut cipher = [0_u8; 12];
1338 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1339 print!("C =\t");
1340 for c in cipher.clone()
1341 { print!("{:02X} ", c); }
1342 println!();
1343 let mut txt = String::new();
1344 for c in cipher.clone()
1345 { write!(txt, "{:02X} ", c); }
1346 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
1347 println!();
1348
1349 // Normal case for the message of 16 bytes
1350 let key = 0x_1234567890ABCDEF_u64;
1351 println!("K =\t{:#016X}", key);
1352 let mut a_des = DES::new_with_key_u64(key);
1353
1354 let message = "고맙습니다.".to_string();
1355 println!("M =\t{}", message);
1356 let iv = 0x_FEDCBA0987654321_u64;
1357 println!("IV = {}", iv);
1358 let mut cipher = [0_u8; 16];
1359 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1360 print!("C =\t");
1361 for c in cipher.clone()
1362 { print!("{:02X} ", c); }
1363 println!();
1364 let mut txt = String::new();
1365 for c in cipher.clone()
1366 { write!(txt, "{:02X} ", c); }
1367 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
1368 println!("-------------------------------");
1369}
1370
1371fn des_encrypt_string_cfb_into_vec()
1372{
1373 println!("des_encrypt_string_cfb_into_vec()");
1374 use std::io::Write;
1375 use std::fmt::Write as _;
1376 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
1377
1378 // Normal case
1379 let key = 0x_1234567890ABCDEF_u64;
1380 println!("K =\t{:#016X}", key);
1381 let mut a_des = DES::new_with_key_u64(key);
1382
1383 let message = "In the beginning God created the heavens and the earth.".to_string();
1384 println!("M =\t{}", message);
1385 let iv = 0x_FEDCBA0987654321_u64;
1386 println!("IV = {}", iv);
1387 let mut cipher = Vec::<u8>::new();
1388 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1389 print!("C (16 rounds) =\t");
1390 for c in cipher.clone()
1391 { print!("{:02X} ", c); }
1392 println!();
1393 let mut txt = String::new();
1394 for c in cipher.clone()
1395 { write!(txt, "{:02X} ", c); }
1396 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
1397 println!();
1398
1399 // Expanded case for 128 rounds
1400 let key = 0x_1234567890ABCDEF_u64;
1401 println!("K =\t{:#016X}", key);
1402 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1403
1404 let message = "In the beginning God created the heavens and the earth.".to_string();
1405 println!("M =\t{}", message);
1406 let iv = 0x_FEDCBA0987654321_u64;
1407 println!("IV = {}", iv);
1408 let mut cipher = Vec::<u8>::new();
1409 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1410 print!("C (128 rounds) =\t");
1411 for c in cipher.clone()
1412 { print!("{:02X} ", c); }
1413 println!();
1414 let mut txt = String::new();
1415 for c in cipher.clone()
1416 { write!(txt, "{:02X} ", c); }
1417 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
1418 println!();
1419
1420 // Expanded case for 0 rounds which means that key is meaningless
1421 let key1 = 0x_1234567890ABCDEF_u64;
1422 let key2 = 0_u64;
1423 println!("K =\t{:#016X}", key);
1424 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1425 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1426
1427 let message = "In the beginning God created the heavens and the earth.".to_string();
1428 println!("M =\t{}", message);
1429 let iv = 0x_FEDCBA0987654321_u64;
1430 println!("IV = {}", iv);
1431 let mut cipher1 = Vec::<u8>::new();
1432 let mut cipher2 = Vec::<u8>::new();
1433 c_des.encrypt_string_into_vec(iv, &message, &mut cipher1);
1434 d_des.encrypt_string_into_vec(iv, &message, &mut cipher2);
1435 print!("C (0 rounds) =\t");
1436 for c in cipher1.clone()
1437 { print!("{:02X} ", c); }
1438 println!();
1439 let mut txt = String::new();
1440 for c in cipher1.clone()
1441 { write!(txt, "{:02X} ", c); }
1442 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1443 print!("D (0 rounds) =\t");
1444 for c in cipher2.clone()
1445 { print!("{:02X} ", c); }
1446 println!();
1447 let mut txt = String::new();
1448 for c in cipher2.clone()
1449 { write!(txt, "{:02X} ", c); }
1450 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1451 println!();
1452
1453 // Normal case for the message of 0 bytes
1454 let key = 0x_1234567890ABCDEF_u64;
1455 println!("K =\t{:#016X}", key);
1456 let mut a_des = DES::new_with_key_u64(key);
1457
1458 let message = "".to_string();
1459 println!("M =\t{}", message);
1460 let iv = 0x_FEDCBA0987654321_u64;
1461 println!("IV = {}", iv);
1462 let mut cipher = Vec::<u8>::new();
1463 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1464 print!("C =\t");
1465 for c in cipher.clone()
1466 { print!("{:02X} ", c); }
1467 println!();
1468 let mut txt = String::new();
1469 for c in cipher.clone()
1470 { write!(txt, "{:02X} ", c); }
1471 assert_eq!(txt, "");
1472 println!();
1473
1474 // Normal case for the message shorter than 8 bytes
1475 let key = 0x_1234567890ABCDEF_u64;
1476 println!("K =\t{:#016X}", key);
1477 let mut a_des = DES::new_with_key_u64(key);
1478
1479 let message = "7 bytes".to_string();
1480 println!("M =\t{}", message);
1481 let iv = 0x_FEDCBA0987654321_u64;
1482 println!("IV = {}", iv);
1483 let mut cipher = Vec::<u8>::new();
1484 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1485 print!("C =\t");
1486 for c in cipher.clone()
1487 { print!("{:02X} ", c); }
1488 println!();
1489 let mut txt = String::new();
1490 for c in cipher.clone()
1491 { write!(txt, "{:02X} ", c); }
1492 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1493 println!();
1494
1495 // Normal case for the message of 8 bytes
1496 let key = 0x_1234567890ABCDEF_u64;
1497 println!("K =\t{:#016X}", key);
1498 let mut a_des = DES::new_with_key_u64(key);
1499
1500 let message = "I am OK.".to_string();
1501 println!("M =\t{}", message);
1502 let iv = 0x_FEDCBA0987654321_u64;
1503 println!("IV = {}", iv);
1504 let mut cipher = Vec::<u8>::new();
1505 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1506 print!("C =\t");
1507 for c in cipher.clone()
1508 { print!("{:02X} ", c); }
1509 println!();
1510 let mut txt = String::new();
1511 for c in cipher.clone()
1512 { write!(txt, "{:02X} ", c); }
1513 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1514 println!();
1515
1516 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1517 let key = 0x_1234567890ABCDEF_u64;
1518 println!("K =\t{:#016X}", key);
1519 let mut a_des = DES::new_with_key_u64(key);
1520
1521 let message = "PARK Youngho".to_string();
1522 println!("M =\t{}", message);
1523 let iv = 0x_FEDCBA0987654321_u64;
1524 println!("IV = {}", iv);
1525 let mut cipher = Vec::<u8>::new();
1526 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1527 print!("C =\t");
1528 for c in cipher.clone()
1529 { print!("{:02X} ", c); }
1530 println!();
1531 let mut txt = String::new();
1532 for c in cipher.clone()
1533 { write!(txt, "{:02X} ", c); }
1534 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
1535 println!();
1536
1537 // Normal case for the message of 16 bytes
1538 let key = 0x_1234567890ABCDEF_u64;
1539 println!("K =\t{:#016X}", key);
1540 let mut a_des = DES::new_with_key_u64(key);
1541
1542 let message = "고맙습니다.".to_string();
1543 println!("M =\t{}", message);
1544 let iv = 0x_FEDCBA0987654321_u64;
1545 println!("IV = {}", iv);
1546 let mut cipher = Vec::<u8>::new();
1547 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1548 print!("C =\t");
1549 for c in cipher.clone()
1550 { print!("{:02X} ", c); }
1551 println!();
1552 let mut txt = String::new();
1553 for c in cipher.clone()
1554 { write!(txt, "{:02X} ", c); }
1555 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
1556 println!("-------------------------------");
1557}
1558
1559fn des_encrypt_string_cfb_into_array()
1560{
1561 println!("des_encrypt_string_cfb_into_array()");
1562 use std::io::Write;
1563 use std::fmt::Write as _;
1564 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
1565
1566 // Normal case
1567 let key = 0x_1234567890ABCDEF_u64;
1568 println!("K =\t{:#016X}", key);
1569 let mut a_des = DES::new_with_key_u64(key);
1570
1571 let message = "In the beginning God created the heavens and the earth.".to_string();
1572 println!("M =\t{}", message);
1573 let iv = 0x_FEDCBA0987654321_u64;
1574 println!("IV = {}", iv);
1575 let mut cipher = [0_u8; 55];
1576 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1577 print!("C (16 rounds) =\t");
1578 for c in cipher.clone()
1579 { print!("{:02X} ", c); }
1580 println!();
1581 let mut txt = String::new();
1582 for c in cipher.clone()
1583 { write!(txt, "{:02X} ", c); }
1584 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
1585 println!();
1586
1587 // Expanded case for 128 rounds
1588 let key = 0x_1234567890ABCDEF_u64;
1589 println!("K =\t{:#016X}", key);
1590 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1591
1592 let message = "In the beginning God created the heavens and the earth.".to_string();
1593 println!("M =\t{}", message);
1594 let iv = 0x_FEDCBA0987654321_u64;
1595 println!("IV = {}", iv);
1596 let mut cipher = [0_u8; 55];
1597 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1598 print!("C (128 rounds) =\t");
1599 for c in cipher.clone()
1600 { print!("{:02X} ", c); }
1601 println!();
1602 let mut txt = String::new();
1603 for c in cipher.clone()
1604 { write!(txt, "{:02X} ", c); }
1605 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
1606 println!();
1607
1608 // Expanded case for 0 rounds which means that key is meaningless
1609 let key1 = 0x_1234567890ABCDEF_u64;
1610 let key2 = 0_u64;
1611 println!("K =\t{:#016X}", key);
1612 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1613 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1614
1615 let message = "In the beginning God created the heavens and the earth.".to_string();
1616 println!("M =\t{}", message);
1617 let iv = 0x_FEDCBA0987654321_u64;
1618 println!("IV = {}", iv);
1619 let mut cipher1 = [0_u8; 55];
1620 let mut cipher2 = [0_u8; 55];
1621 c_des.encrypt_string_into_array(iv, &message, &mut cipher1);
1622 d_des.encrypt_string_into_array(iv, &message, &mut cipher2);
1623 print!("C (0 rounds) =\t");
1624 for c in cipher1.clone()
1625 { print!("{:02X} ", c); }
1626 println!();
1627 let mut txt = String::new();
1628 for c in cipher1.clone()
1629 { write!(txt, "{:02X} ", c); }
1630 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1631 print!("D (0 rounds) =\t");
1632 for c in cipher2.clone()
1633 { print!("{:02X} ", c); }
1634 println!();
1635 let mut txt = String::new();
1636 for c in cipher2.clone()
1637 { write!(txt, "{:02X} ", c); }
1638 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1639 println!();
1640
1641 // Normal case for the message of 0 bytes
1642 let key = 0x_1234567890ABCDEF_u64;
1643 println!("K =\t{:#016X}", key);
1644 let mut a_des = DES::new_with_key_u64(key);
1645
1646 let message = "".to_string();
1647 println!("M =\t{}", message);
1648 let iv = 0x_FEDCBA0987654321_u64;
1649 println!("IV = {}", iv);
1650 let mut cipher = [0_u8; 0];
1651 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1652 print!("C =\t");
1653 for c in cipher.clone()
1654 { print!("{:02X} ", c); }
1655 println!();
1656 let mut txt = String::new();
1657 for c in cipher.clone()
1658 { write!(txt, "{:02X} ", c); }
1659 assert_eq!(txt, "");
1660 println!();
1661
1662 // Normal case for the message shorter than 8 bytes
1663 let key = 0x_1234567890ABCDEF_u64;
1664 println!("K =\t{:#016X}", key);
1665 let mut a_des = DES::new_with_key_u64(key);
1666
1667 let message = "7 bytes".to_string();
1668 println!("M =\t{}", message);
1669 let iv = 0x_FEDCBA0987654321_u64;
1670 println!("IV = {}", iv);
1671 let mut cipher = [0_u8; 7];
1672 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1673 print!("C =\t");
1674 for c in cipher.clone()
1675 { print!("{:02X} ", c); }
1676 println!();
1677 let mut txt = String::new();
1678 for c in cipher.clone()
1679 { write!(txt, "{:02X} ", c); }
1680 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1681 println!();
1682
1683 // Normal case for the message of 8 bytes
1684 let key = 0x_1234567890ABCDEF_u64;
1685 println!("K =\t{:#016X}", key);
1686 let mut a_des = DES::new_with_key_u64(key);
1687
1688 let message = "I am OK.".to_string();
1689 println!("M =\t{}", message);
1690 let iv = 0x_FEDCBA0987654321_u64;
1691 println!("IV = {}", iv);
1692 let mut cipher = [0_u8; 8];
1693 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1694 print!("C =\t");
1695 for c in cipher.clone()
1696 { print!("{:02X} ", c); }
1697 println!();
1698 let mut txt = String::new();
1699 for c in cipher.clone()
1700 { write!(txt, "{:02X} ", c); }
1701 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1702 println!();
1703
1704 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1705 let key = 0x_1234567890ABCDEF_u64;
1706 println!("K =\t{:#016X}", key);
1707 let mut a_des = DES::new_with_key_u64(key);
1708
1709 let message = "PARK Youngho".to_string();
1710 println!("M =\t{}", message);
1711 let iv = 0x_FEDCBA0987654321_u64;
1712 println!("IV = {}", iv);
1713 let mut cipher = [0_u8; 12];
1714 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1715 print!("C =\t");
1716 for c in cipher.clone()
1717 { print!("{:02X} ", c); }
1718 println!();
1719 let mut txt = String::new();
1720 for c in cipher.clone()
1721 { write!(txt, "{:02X} ", c); }
1722 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
1723 println!();
1724
1725 // Normal case for the message of 16 bytes
1726 let key = 0x_1234567890ABCDEF_u64;
1727 println!("K =\t{:#016X}", key);
1728 let mut a_des = DES::new_with_key_u64(key);
1729
1730 let message = "고맙습니다.".to_string();
1731 println!("M =\t{}", message);
1732 let iv = 0x_FEDCBA0987654321_u64;
1733 println!("IV = {}", iv);
1734 let mut cipher = [0_u8; 16];
1735 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1736 print!("C =\t");
1737 for c in cipher.clone()
1738 { print!("{:02X} ", c); }
1739 println!();
1740 let mut txt = String::new();
1741 for c in cipher.clone()
1742 { write!(txt, "{:02X} ", c); }
1743 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
1744 println!("-------------------------------");
1745}
1746
1747fn des_encrypt_vec_cfb()
1748{
1749 println!("des_encrypt_vec_cfb()");
1750 use std::io::Write;
1751 use std::fmt::Write as _;
1752 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
1753
1754 // Normal case
1755 let key = 0x_1234567890ABCDEF_u64;
1756 println!("K =\t{:#016X}", key);
1757 let mut a_des = DES::new_with_key_u64(key);
1758
1759 let message = "In the beginning God created the heavens and the earth.";
1760 println!("M =\t{}", message);
1761 let message = unsafe { message.to_string().as_mut_vec().clone() };
1762 let iv = 0x_FEDCBA0987654321_u64;
1763 println!("IV = {}", iv);
1764 let mut cipher = [0_u8; 55];
1765 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1766 print!("C (16 rounds) =\t");
1767 for c in cipher.clone()
1768 { print!("{:02X} ", c); }
1769 println!();
1770 let mut txt = String::new();
1771 for c in cipher.clone()
1772 { write!(txt, "{:02X} ", c); }
1773 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
1774 println!();
1775
1776 // Expanded case for 128 rounds
1777 let key = 0x_1234567890ABCDEF_u64;
1778 println!("K =\t{:#016X}", key);
1779 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1780
1781 let message = "In the beginning God created the heavens and the earth.";
1782 println!("M =\t{}", message);
1783 let message = unsafe { message.to_string().as_mut_vec().clone() };
1784 let iv = 0x_FEDCBA0987654321_u64;
1785 println!("IV = {}", iv);
1786 let mut cipher = [0_u8; 55];
1787 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1788 print!("C (128 rounds) =\t");
1789 for c in cipher.clone()
1790 { print!("{:02X} ", c); }
1791 println!();
1792 let mut txt = String::new();
1793 for c in cipher.clone()
1794 { write!(txt, "{:02X} ", c); }
1795 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
1796 println!();
1797
1798 // Expanded case for 0 rounds which means that key is meaningless
1799 let key1 = 0x_1234567890ABCDEF_u64;
1800 let key2 = 0_u64;
1801 println!("K1 =\t{:#016X}", key1);
1802 println!("K2 =\t{:#016X}", key2);
1803 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1804 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1805
1806 let message = "In the beginning God created the heavens and the earth.";
1807 println!("M =\t{}", message);
1808 let message = unsafe { message.to_string().as_mut_vec().clone() };
1809 let iv = 0x_FEDCBA0987654321_u64;
1810 println!("IV = {}", iv);
1811 let mut cipher1 = [0_u8; 55];
1812 let mut cipher2 = [0_u8; 55];
1813 c_des.encrypt_vec(iv, &message, cipher1.as_mut_ptr());
1814 d_des.encrypt_vec(iv, &message, cipher2.as_mut_ptr());
1815 print!("C (0 rounds) =\t");
1816 for c in cipher1.clone()
1817 { print!("{:02X} ", c); }
1818 println!();
1819 let mut txt = String::new();
1820 for c in cipher1.clone()
1821 { write!(txt, "{:02X} ", c); }
1822 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1823 print!("D (0 rounds) =\t");
1824 for c in cipher2.clone()
1825 { print!("{:02X} ", c); }
1826 println!();
1827 let mut txt = String::new();
1828 for c in cipher2.clone()
1829 { write!(txt, "{:02X} ", c); }
1830 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
1831 println!();
1832
1833 // Normal case for the message of 0 bytes
1834 let key = 0x_1234567890ABCDEF_u64;
1835 println!("K =\t{:#016X}", key);
1836 let mut a_des = DES::new_with_key_u64(key);
1837
1838 let message = "";
1839 println!("M =\t{}", message);
1840 let message = unsafe { message.to_string().as_mut_vec().clone() };
1841 let iv = 0x_FEDCBA0987654321_u64;
1842 println!("IV = {}", iv);
1843 let mut cipher = [0_u8; 0];
1844 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1845 print!("C =\t");
1846 for c in cipher.clone()
1847 { print!("{:02X} ", c); }
1848 println!();
1849 let mut txt = String::new();
1850 for c in cipher.clone()
1851 { write!(txt, "{:02X} ", c); }
1852 assert_eq!(txt, "");
1853 println!();
1854
1855 // Normal case for the message shorter than 8 bytes
1856 let key = 0x_1234567890ABCDEF_u64;
1857 println!("K =\t{:#016X}", key);
1858 let mut a_des = DES::new_with_key_u64(key);
1859
1860 let message = "7 bytes";
1861 println!("M =\t{}", message);
1862 let message = unsafe { message.to_string().as_mut_vec().clone() };
1863 let iv = 0x_FEDCBA0987654321_u64;
1864 println!("IV = {}", iv);
1865 let mut cipher = [0_u8; 7];
1866 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1867 print!("C =\t");
1868 for c in cipher.clone()
1869 { print!("{:02X} ", c); }
1870 println!();
1871 let mut txt = String::new();
1872 for c in cipher.clone()
1873 { write!(txt, "{:02X} ", c); }
1874 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1875 println!();
1876
1877 // Normal case for the message of 8 bytes
1878 let key = 0x_1234567890ABCDEF_u64;
1879 println!("K =\t{:#016X}", key);
1880 let mut a_des = DES::new_with_key_u64(key);
1881
1882 let message = "I am OK.";
1883 println!("M =\t{}", message);
1884 let message = unsafe { message.to_string().as_mut_vec().clone() };
1885 let iv = 0x_FEDCBA0987654321_u64;
1886 println!("IV = {}", iv);
1887 let mut cipher = [0_u8; 8];
1888 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1889 print!("C =\t");
1890 for c in cipher.clone()
1891 { print!("{:02X} ", c); }
1892 println!();
1893 let mut txt = String::new();
1894 for c in cipher.clone()
1895 { write!(txt, "{:02X} ", c); }
1896 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1897 println!();
1898
1899 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1900 let key = 0x_1234567890ABCDEF_u64;
1901 println!("K =\t{:#016X}", key);
1902 let mut a_des = DES::new_with_key_u64(key);
1903
1904 let message = "PARK Youngho";
1905 println!("M =\t{}", message);
1906 let message = unsafe { message.to_string().as_mut_vec().clone() };
1907 let iv = 0x_FEDCBA0987654321_u64;
1908 println!("IV = {}", iv);
1909 let mut cipher = [0_u8; 12];
1910 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1911 print!("C =\t");
1912 for c in cipher.clone()
1913 { print!("{:02X} ", c); }
1914 println!();
1915 let mut txt = String::new();
1916 for c in cipher.clone()
1917 { write!(txt, "{:02X} ", c); }
1918 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
1919 println!();
1920
1921 // Normal case for the message of 16 bytes
1922 let key = 0x_1234567890ABCDEF_u64;
1923 println!("K =\t{:#016X}", key);
1924 let mut a_des = DES::new_with_key_u64(key);
1925
1926 let message = "고맙습니다.";
1927 println!("M =\t{}", message);
1928 let message = unsafe { message.to_string().as_mut_vec().clone() };
1929 let iv = 0x_FEDCBA0987654321_u64;
1930 println!("IV = {}", iv);
1931 let mut cipher = [0_u8; 16];
1932 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1933 print!("C =\t");
1934 for c in cipher.clone()
1935 { print!("{:02X} ", c); }
1936 println!();
1937 let mut txt = String::new();
1938 for c in cipher.clone()
1939 { write!(txt, "{:02X} ", c); }
1940 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
1941 println!("-------------------------------");
1942}
1943
1944fn des_encrypt_vec_cfb_into_vec()
1945{
1946 println!("des_encrypt_vec_cfb_into_vec()");
1947 use std::io::Write;
1948 use std::fmt::Write as _;
1949 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
1950
1951 // Normal case
1952 let key = 0x_1234567890ABCDEF_u64;
1953 println!("K =\t{:#016X}", key);
1954 let mut a_des = DES::new_with_key_u64(key);
1955
1956 let message = "In the beginning God created the heavens and the earth.";
1957 println!("M =\t{}", message);
1958 let message = unsafe { message.to_string().as_mut_vec().clone() };
1959 let iv = 0x_FEDCBA0987654321_u64;
1960 println!("IV = {}", iv);
1961 let mut cipher = Vec::<u8>::new();
1962 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
1963 print!("C (16 rounds) =\t");
1964 for c in cipher.clone()
1965 { print!("{:02X} ", c); }
1966 println!();
1967 let mut txt = String::new();
1968 for c in cipher.clone()
1969 { write!(txt, "{:02X} ", c); }
1970 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
1971 println!();
1972
1973 // Expanded case for 128 rounds
1974 let key = 0x_1234567890ABCDEF_u64;
1975 println!("K =\t{:#016X}", key);
1976 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1977
1978 let message = "In the beginning God created the heavens and the earth.";
1979 println!("M =\t{}", message);
1980 let message = unsafe { message.to_string().as_mut_vec().clone() };
1981 let iv = 0x_FEDCBA0987654321_u64;
1982 println!("IV = {}", iv);
1983 let mut cipher = Vec::<u8>::new();
1984 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
1985 print!("C (128 rounds) =\t");
1986 for c in cipher.clone()
1987 { print!("{:02X} ", c); }
1988 println!();
1989 let mut txt = String::new();
1990 for c in cipher.clone()
1991 { write!(txt, "{:02X} ", c); }
1992 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
1993 println!();
1994
1995 // Expanded case for 0 rounds which means that key is meaningless
1996 let key1 = 0x_1234567890ABCDEF_u64;
1997 let key2 = 0_u64;
1998 println!("K1 =\t{:#016X}", key1);
1999 println!("K2 =\t{:#016X}", key2);
2000 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2001 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2002
2003 let message = "In the beginning God created the heavens and the earth.";
2004 println!("M =\t{}", message);
2005 let message = unsafe { message.to_string().as_mut_vec().clone() };
2006
2007 let iv = 0x_FEDCBA0987654321_u64;
2008 println!("IV = {}", iv);
2009 let mut cipher1 = Vec::<u8>::new();
2010 let mut cipher2 = Vec::<u8>::new();
2011 c_des.encrypt_vec_into_vec(iv, &message, &mut cipher1);
2012 d_des.encrypt_vec_into_vec(iv, &message, &mut cipher2);
2013 print!("C (0 rounds) =\t");
2014 for c in cipher1.clone()
2015 { print!("{:02X} ", c); }
2016 println!();
2017 let mut txt = String::new();
2018 for c in cipher1.clone()
2019 { write!(txt, "{:02X} ", c); }
2020 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2021 print!("D (0 rounds) =\t");
2022 for c in cipher2.clone()
2023 { print!("{:02X} ", c); }
2024 println!();
2025 let mut txt = String::new();
2026 for c in cipher2.clone()
2027 { write!(txt, "{:02X} ", c); }
2028 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2029 println!();
2030
2031 // Normal case for the message of 0 bytes
2032 let key = 0x_1234567890ABCDEF_u64;
2033 println!("K =\t{:#016X}", key);
2034 let mut a_des = DES::new_with_key_u64(key);
2035
2036 let message = "";
2037 println!("M =\t{}", message);
2038 let message = unsafe { message.to_string().as_mut_vec().clone() };
2039 let iv = 0x_FEDCBA0987654321_u64;
2040 println!("IV = {}", iv);
2041 let mut cipher = Vec::<u8>::new();
2042 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2043 print!("C =\t");
2044 for c in cipher.clone()
2045 { print!("{:02X} ", c); }
2046 println!();
2047 let mut txt = String::new();
2048 for c in cipher.clone()
2049 { write!(txt, "{:02X} ", c); }
2050 assert_eq!(txt, "");
2051 println!();
2052
2053 // Normal case for the message shorter than 8 bytes
2054 let key = 0x_1234567890ABCDEF_u64;
2055 println!("K =\t{:#016X}", key);
2056 let mut a_des = DES::new_with_key_u64(key);
2057
2058 let message = "7 bytes";
2059 println!("M =\t{}", message);
2060 let message = unsafe { message.to_string().as_mut_vec().clone() };
2061 let iv = 0x_FEDCBA0987654321_u64;
2062 println!("IV = {}", iv);
2063 let mut cipher = Vec::<u8>::new();
2064 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2065 print!("C =\t");
2066 for c in cipher.clone()
2067 { print!("{:02X} ", c); }
2068 println!();
2069 let mut txt = String::new();
2070 for c in cipher.clone()
2071 { write!(txt, "{:02X} ", c); }
2072 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2073 println!();
2074
2075 // Normal case for the message of 8 bytes
2076 let key = 0x_1234567890ABCDEF_u64;
2077 println!("K =\t{:#016X}", key);
2078 let mut a_des = DES::new_with_key_u64(key);
2079
2080 let message = "I am OK.";
2081 println!("M =\t{}", message);
2082 let message = unsafe { message.to_string().as_mut_vec().clone() };
2083 let iv = 0x_FEDCBA0987654321_u64;
2084 println!("IV = {}", iv);
2085 let mut cipher = Vec::<u8>::new();
2086 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2087 print!("C =\t");
2088 for c in cipher.clone()
2089 { print!("{:02X} ", c); }
2090 println!();
2091 let mut txt = String::new();
2092 for c in cipher.clone()
2093 { write!(txt, "{:02X} ", c); }
2094 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2095 println!();
2096
2097 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2098 let key = 0x_1234567890ABCDEF_u64;
2099 println!("K =\t{:#016X}", key);
2100 let mut a_des = DES::new_with_key_u64(key);
2101
2102 let message = "PARK Youngho";
2103 println!("M =\t{}", message);
2104 let message = unsafe { message.to_string().as_mut_vec().clone() };
2105 let iv = 0x_FEDCBA0987654321_u64;
2106 println!("IV = {}", iv);
2107 let mut cipher = Vec::<u8>::new();
2108 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2109 print!("C =\t");
2110 for c in cipher.clone()
2111 { print!("{:02X} ", c); }
2112 println!();
2113 let mut txt = String::new();
2114 for c in cipher.clone()
2115 { write!(txt, "{:02X} ", c); }
2116 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
2117 println!();
2118
2119 // Normal case for the message of 16 bytes
2120 let key = 0x_1234567890ABCDEF_u64;
2121 println!("K =\t{:#016X}", key);
2122 let mut a_des = DES::new_with_key_u64(key);
2123
2124 let message = "고맙습니다.";
2125 println!("M =\t{}", message);
2126 let message = unsafe { message.to_string().as_mut_vec().clone() };
2127 let iv = 0x_FEDCBA0987654321_u64;
2128 println!("IV = {}", iv);
2129 let mut cipher = Vec::<u8>::new();
2130 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2131 print!("C =\t");
2132 for c in cipher.clone()
2133 { print!("{:02X} ", c); }
2134 println!();
2135 let mut txt = String::new();
2136 for c in cipher.clone()
2137 { write!(txt, "{:02X} ", c); }
2138 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
2139 println!("-------------------------------");
2140}
2141
2142fn des_encrypt_vec_cfb_into_array()
2143{
2144 println!("des_encrypt_vec_cfb_into_array()");
2145 use std::io::Write;
2146 use std::fmt::Write as _;
2147 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
2148
2149 // Normal case
2150 let key = 0x_1234567890ABCDEF_u64;
2151 println!("K =\t{:#016X}", key);
2152 let mut a_des = DES::new_with_key_u64(key);
2153
2154 let message = "In the beginning God created the heavens and the earth.";
2155 println!("M =\t{}", message);
2156 let message = unsafe { message.to_string().as_mut_vec().clone() };
2157 let iv = 0x_FEDCBA0987654321_u64;
2158 println!("IV = {}", iv);
2159 let mut cipher = [0_u8; 55];
2160 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2161 print!("C (16 rounds) =\t");
2162 for c in cipher.clone()
2163 { print!("{:02X} ", c); }
2164 println!();
2165 let mut txt = String::new();
2166 for c in cipher.clone()
2167 { write!(txt, "{:02X} ", c); }
2168 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
2169 println!();
2170
2171 // Expanded case for 128 rounds
2172 let key = 0x_1234567890ABCDEF_u64;
2173 println!("K =\t{:#016X}", key);
2174 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2175
2176 let message = "In the beginning God created the heavens and the earth.";
2177 println!("M =\t{}", message);
2178 let message = unsafe { message.to_string().as_mut_vec().clone() };
2179 let iv = 0x_FEDCBA0987654321_u64;
2180 println!("IV = {}", iv);
2181 let mut cipher = [0_u8; 55];
2182 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2183 print!("C (128 rounds) =\t");
2184 for c in cipher.clone()
2185 { print!("{:02X} ", c); }
2186 println!();
2187 let mut txt = String::new();
2188 for c in cipher.clone()
2189 { write!(txt, "{:02X} ", c); }
2190 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
2191 println!();
2192
2193 // Expanded case for 0 rounds which means that key is meaningless
2194 let key1 = 0x_1234567890ABCDEF_u64;
2195 let key2 = 0_u64;
2196 println!("K1 =\t{:#016X}", key1);
2197 println!("K2 =\t{:#016X}", key2);
2198 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2199 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2200
2201 let message = "In the beginning God created the heavens and the earth.";
2202 println!("M =\t{}", message);
2203 let message = unsafe { message.to_string().as_mut_vec().clone() };
2204 let iv = 0x_FEDCBA0987654321_u64;
2205 println!("IV = {}", iv);
2206 let mut cipher1 = [0_u8; 55];
2207 let mut cipher2 = [0_u8; 55];
2208 c_des.encrypt_vec_into_array(iv, &message, &mut cipher1);
2209 d_des.encrypt_vec_into_array(iv, &message, &mut cipher2);
2210 print!("C (0 rounds) =\t");
2211 for c in cipher1.clone()
2212 { print!("{:02X} ", c); }
2213 println!();
2214 let mut txt = String::new();
2215 for c in cipher1.clone()
2216 { write!(txt, "{:02X} ", c); }
2217 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2218 print!("D (0 rounds) =\t");
2219 for c in cipher2.clone()
2220 { print!("{:02X} ", c); }
2221 println!();
2222 let mut txt = String::new();
2223 for c in cipher2.clone()
2224 { write!(txt, "{:02X} ", c); }
2225 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2226 println!();
2227
2228 // Normal case for the message of 0 bytes
2229 let key = 0x_1234567890ABCDEF_u64;
2230 println!("K =\t{:#016X}", key);
2231 let mut a_des = DES::new_with_key_u64(key);
2232
2233 let message = "";
2234 println!("M =\t{}", message);
2235 let message = unsafe { message.to_string().as_mut_vec().clone() };
2236 let iv = 0x_FEDCBA0987654321_u64;
2237 println!("IV = {}", iv);
2238 let mut cipher = [0_u8; 0];
2239 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2240 print!("C =\t");
2241 for c in cipher.clone()
2242 { print!("{:02X} ", c); }
2243 println!();
2244 let mut txt = String::new();
2245 for c in cipher.clone()
2246 { write!(txt, "{:02X} ", c); }
2247 assert_eq!(txt, "");
2248 println!();
2249
2250 // Normal case for the message shorter than 8 bytes
2251 let key = 0x_1234567890ABCDEF_u64;
2252 println!("K =\t{:#016X}", key);
2253 let mut a_des = DES::new_with_key_u64(key);
2254
2255 let message = "7 bytes";
2256 println!("M =\t{}", message);
2257 let message = unsafe { message.to_string().as_mut_vec().clone() };
2258 let iv = 0x_FEDCBA0987654321_u64;
2259 println!("IV = {}", iv);
2260 let mut cipher = [0_u8; 7];
2261 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2262 print!("C =\t");
2263 for c in cipher.clone()
2264 { print!("{:02X} ", c); }
2265 println!();
2266 let mut txt = String::new();
2267 for c in cipher.clone()
2268 { write!(txt, "{:02X} ", c); }
2269 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2270 println!();
2271
2272 // Normal case for the message of 8 bytes
2273 let key = 0x_1234567890ABCDEF_u64;
2274 println!("K =\t{:#016X}", key);
2275 let mut a_des = DES::new_with_key_u64(key);
2276
2277 let message = "I am OK.";
2278 println!("M =\t{}", message);
2279 let message = unsafe { message.to_string().as_mut_vec().clone() };
2280 let iv = 0x_FEDCBA0987654321_u64;
2281 println!("IV = {}", iv);
2282 let mut cipher = [0_u8; 8];
2283 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2284 print!("C =\t");
2285 for c in cipher.clone()
2286 { print!("{:02X} ", c); }
2287 println!();
2288 let mut txt = String::new();
2289 for c in cipher.clone()
2290 { write!(txt, "{:02X} ", c); }
2291 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2292 println!();
2293
2294 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2295 let key = 0x_1234567890ABCDEF_u64;
2296 println!("K =\t{:#016X}", key);
2297 let mut a_des = DES::new_with_key_u64(key);
2298
2299 let message = "PARK Youngho";
2300 println!("M =\t{}", message);
2301 let message = unsafe { message.to_string().as_mut_vec().clone() };
2302 let iv = 0x_FEDCBA0987654321_u64;
2303 println!("IV = {}", iv);
2304 let mut cipher = [0_u8; 12];
2305 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2306 print!("C =\t");
2307 for c in cipher.clone()
2308 { print!("{:02X} ", c); }
2309 println!();
2310 let mut txt = String::new();
2311 for c in cipher.clone()
2312 { write!(txt, "{:02X} ", c); }
2313 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
2314 println!();
2315
2316 // Normal case for the message of 16 bytes
2317 let key = 0x_1234567890ABCDEF_u64;
2318 println!("K =\t{:#016X}", key);
2319 let mut a_des = DES::new_with_key_u64(key);
2320
2321 let message = "고맙습니다.";
2322 println!("M =\t{}", message);
2323 let message = unsafe { message.to_string().as_mut_vec().clone() };
2324 let iv = 0x_FEDCBA0987654321_u64;
2325 println!("IV = {}", iv);
2326 let mut cipher = [0_u8; 16];
2327 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2328 print!("C =\t");
2329 for c in cipher.clone()
2330 { print!("{:02X} ", c); }
2331 println!();
2332 let mut txt = String::new();
2333 for c in cipher.clone()
2334 { write!(txt, "{:02X} ", c); }
2335 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
2336 println!("-------------------------------");
2337}
2338
2339fn des_encrypt_array_cfb()
2340{
2341 println!("des_encrypt_array_cfb()");
2342 use std::io::Write;
2343 use std::fmt::Write as _;
2344 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
2345
2346 // Normal case
2347 let key = 0x_1234567890ABCDEF_u64;
2348 println!("K =\t{:#016X}", key);
2349 let mut a_des = DES::new_with_key_u64(key);
2350
2351 let mes = "In the beginning God created the heavens and the earth.";
2352 println!("M =\t{}", mes);
2353 let mut message = [0_u8; 55];
2354 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2355 let iv = 0x_FEDCBA0987654321_u64;
2356 println!("IV = {}", iv);
2357 let mut cipher = [0_u8; 55];
2358 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2359 print!("C (16 rounds) =\t");
2360 for c in cipher.clone()
2361 { print!("{:02X} ", c); }
2362 println!();
2363 let mut txt = String::new();
2364 for c in cipher.clone()
2365 { write!(txt, "{:02X} ", c); }
2366 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
2367 println!();
2368
2369 // Expanded case for 128 rounds
2370 let key = 0x_1234567890ABCDEF_u64;
2371 println!("K =\t{:#016X}", key);
2372 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2373
2374 let mes = "In the beginning God created the heavens and the earth.";
2375 println!("M =\t{}", mes);
2376 let mut message = [0_u8; 55];
2377 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2378 let iv = 0x_FEDCBA0987654321_u64;
2379 println!("IV = {}", iv);
2380 let mut cipher = [0_u8; 55];
2381 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2382 print!("C (128 rounds) =\t");
2383 for c in cipher.clone()
2384 { print!("{:02X} ", c); }
2385 println!();
2386 let mut txt = String::new();
2387 for c in cipher.clone()
2388 { write!(txt, "{:02X} ", c); }
2389 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
2390 println!();
2391
2392 // Expanded case for 0 rounds which means that key is meaningless
2393 let key1 = 0x_1234567890ABCDEF_u64;
2394 let key2 = 0_u64;
2395 println!("K1 =\t{:#016X}", key1);
2396 println!("K2 =\t{:#016X}", key2);
2397 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2398 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2399
2400 let mes = "In the beginning God created the heavens and the earth.";
2401 println!("M =\t{}", mes);
2402 let mut message = [0_u8; 55];
2403 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2404 let iv = 0x_FEDCBA0987654321_u64;
2405 println!("IV = {}", iv);
2406 let mut cipher1 = [0_u8; 55];
2407 let mut cipher2 = [0_u8; 55];
2408 c_des.encrypt_array(iv, &message, cipher1.as_mut_ptr());
2409 d_des.encrypt_array(iv, &message, cipher2.as_mut_ptr());
2410 print!("C (0 rounds) =\t");
2411 for c in cipher1.clone()
2412 { print!("{:02X} ", c); }
2413 println!();
2414 let mut txt = String::new();
2415 for c in cipher1.clone()
2416 { write!(txt, "{:02X} ", c); }
2417 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2418 print!("D (0 rounds) =\t");
2419 for c in cipher2.clone()
2420 { print!("{:02X} ", c); }
2421 println!();
2422 let mut txt = String::new();
2423 for c in cipher2.clone()
2424 { write!(txt, "{:02X} ", c); }
2425 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2426 println!();
2427
2428 // Normal case for the message of 0 bytes
2429 let key = 0x_1234567890ABCDEF_u64;
2430 println!("K =\t{:#016X}", key);
2431 let mut a_des = DES::new_with_key_u64(key);
2432
2433 let mes = "";
2434 println!("M =\t{}", mes);
2435 let mut message = [0_u8; 0];
2436 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2437 let iv = 0x_FEDCBA0987654321_u64;
2438 println!("IV = {}", iv);
2439 let mut cipher = [0_u8; 0];
2440 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2441 print!("C =\t");
2442 for c in cipher.clone()
2443 { print!("{:02X} ", c); }
2444 println!();
2445 let mut txt = String::new();
2446 for c in cipher.clone()
2447 { write!(txt, "{:02X} ", c); }
2448 assert_eq!(txt, "");
2449 println!();
2450
2451 // Normal case for the message shorter than 8 bytes
2452 let key = 0x_1234567890ABCDEF_u64;
2453 println!("K =\t{:#016X}", key);
2454 let mut a_des = DES::new_with_key_u64(key);
2455
2456 let mes = "7 bytes";
2457 println!("M =\t{}", mes);
2458 let mut message = [0_u8; 7];
2459 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460 let iv = 0x_FEDCBA0987654321_u64;
2461 println!("IV = {}", iv);
2462 let mut cipher = [0_u8; 7];
2463 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2464 print!("C =\t");
2465 for c in cipher.clone()
2466 { print!("{:02X} ", c); }
2467 println!();
2468 let mut txt = String::new();
2469 for c in cipher.clone()
2470 { write!(txt, "{:02X} ", c); }
2471 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2472 println!();
2473
2474 // Normal case for the message of 8 bytes
2475 let key = 0x_1234567890ABCDEF_u64;
2476 println!("K =\t{:#016X}", key);
2477 let mut a_des = DES::new_with_key_u64(key);
2478
2479 let mes = "I am OK.";
2480 println!("M =\t{}", mes);
2481 let mut message = [0_u8; 8];
2482 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2483 let iv = 0x_FEDCBA0987654321_u64;
2484 println!("IV = {}", iv);
2485 let mut cipher = [0_u8; 8];
2486 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2487 print!("C =\t");
2488 for c in cipher.clone()
2489 { print!("{:02X} ", c); }
2490 println!();
2491 let mut txt = String::new();
2492 for c in cipher.clone()
2493 { write!(txt, "{:02X} ", c); }
2494 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2495 println!();
2496
2497 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2498 let key = 0x_1234567890ABCDEF_u64;
2499 println!("K =\t{:#016X}", key);
2500 let mut a_des = DES::new_with_key_u64(key);
2501
2502 let mes = "PARK Youngho";
2503 println!("M =\t{}", mes);
2504 let mut message = [0_u8; 12];
2505 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2506 let iv = 0x_FEDCBA0987654321_u64;
2507 println!("IV = {}", iv);
2508 let mut cipher = [0_u8; 12];
2509 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2510 print!("C =\t");
2511 for c in cipher.clone()
2512 { print!("{:02X} ", c); }
2513 println!();
2514 let mut txt = String::new();
2515 for c in cipher.clone()
2516 { write!(txt, "{:02X} ", c); }
2517 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
2518 println!();
2519
2520 // Normal case for the message of 16 bytes
2521 let key = 0x_1234567890ABCDEF_u64;
2522 println!("K =\t{:#016X}", key);
2523 let mut a_des = DES::new_with_key_u64(key);
2524
2525 let mes = "고맙습니다.";
2526 println!("M =\t{}", mes);
2527 let mut message = [0_u8; 16];
2528 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2529 let iv = 0x_FEDCBA0987654321_u64;
2530 println!("IV = {}", iv);
2531 let mut cipher = [0_u8; 16];
2532 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2533 print!("C =\t");
2534 for c in cipher.clone()
2535 { print!("{:02X} ", c); }
2536 println!();
2537 let mut txt = String::new();
2538 for c in cipher.clone()
2539 { write!(txt, "{:02X} ", c); }
2540 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
2541 println!("-------------------------------");
2542}
2543
2544fn des_encrypt_array_cfb_into_vec()
2545{
2546 println!("des_encrypt_array_cfb_into_vec()");
2547 use std::io::Write;
2548 use std::fmt::Write as _;
2549 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
2550
2551 // Normal case
2552 let key = 0x_1234567890ABCDEF_u64;
2553 println!("K =\t{:#016X}", key);
2554 let mut a_des = DES::new_with_key_u64(key);
2555
2556 let mes = "In the beginning God created the heavens and the earth.";
2557 println!("M =\t{}", mes);
2558 let mut message = [0_u8; 55];
2559 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2560 let iv = 0x_FEDCBA0987654321_u64;
2561 println!("IV = {}", iv);
2562 let mut cipher = Vec::<u8>::new();
2563 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2564 print!("C (16 rounds) =\t");
2565 for c in cipher.clone()
2566 { print!("{:02X} ", c); }
2567 println!();
2568 let mut txt = String::new();
2569 for c in cipher.clone()
2570 { write!(txt, "{:02X} ", c); }
2571 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
2572 println!();
2573
2574 // Expanded case for 128 rounds
2575 let key = 0x_1234567890ABCDEF_u64;
2576 println!("K =\t{:#016X}", key);
2577 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2578
2579 let mes = "In the beginning God created the heavens and the earth.";
2580 println!("M =\t{}", mes);
2581 let mut message = [0_u8; 55];
2582 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2583 let iv = 0x_FEDCBA0987654321_u64;
2584 println!("IV = {}", iv);
2585 let mut cipher = Vec::<u8>::new();
2586 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2587 print!("C (128 rounds) =\t");
2588 for c in cipher.clone()
2589 { print!("{:02X} ", c); }
2590 println!();
2591 let mut txt = String::new();
2592 for c in cipher.clone()
2593 { write!(txt, "{:02X} ", c); }
2594 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
2595 println!();
2596
2597 // Expanded case for 0 rounds which means that key is meaningless
2598 let key1 = 0x_1234567890ABCDEF_u64;
2599 let key2 = 0_u64;
2600 println!("K1 =\t{:#016X}", key1);
2601 println!("K2 =\t{:#016X}", key2);
2602 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2603 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2604
2605 let mes = "In the beginning God created the heavens and the earth.";
2606 println!("M =\t{}", mes);
2607 let mut message = [0_u8; 55];
2608 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2609
2610 let iv = 0x_FEDCBA0987654321_u64;
2611 println!("IV = {}", iv);
2612 let mut cipher1 = Vec::<u8>::new();
2613 let mut cipher2 = Vec::<u8>::new();
2614 c_des.encrypt_array_into_vec(iv, &message, &mut cipher1);
2615 d_des.encrypt_array_into_vec(iv, &message, &mut cipher2);
2616 print!("C (0 rounds) =\t");
2617 for c in cipher1.clone()
2618 { print!("{:02X} ", c); }
2619 println!();
2620 let mut txt = String::new();
2621 for c in cipher1.clone()
2622 { write!(txt, "{:02X} ", c); }
2623 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2624 print!("D (0 rounds) =\t");
2625 for c in cipher2.clone()
2626 { print!("{:02X} ", c); }
2627 println!();
2628 let mut txt = String::new();
2629 for c in cipher2.clone()
2630 { write!(txt, "{:02X} ", c); }
2631 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2632 println!();
2633
2634 // Normal case for the message of 0 bytes
2635 let key = 0x_1234567890ABCDEF_u64;
2636 println!("K =\t{:#016X}", key);
2637 let mut a_des = DES::new_with_key_u64(key);
2638
2639 let mes = "";
2640 println!("M =\t{}", mes);
2641 let mut message = [0_u8; 0];
2642 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2643 let iv = 0x_FEDCBA0987654321_u64;
2644 println!("IV = {}", iv);
2645 let mut cipher = Vec::<u8>::new();
2646 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2647 print!("C =\t");
2648 for c in cipher.clone()
2649 { print!("{:02X} ", c); }
2650 println!();
2651 let mut txt = String::new();
2652 for c in cipher.clone()
2653 { write!(txt, "{:02X} ", c); }
2654 assert_eq!(txt, "");
2655 println!();
2656
2657 // Normal case for the message shorter than 8 bytes
2658 let key = 0x_1234567890ABCDEF_u64;
2659 println!("K =\t{:#016X}", key);
2660 let mut a_des = DES::new_with_key_u64(key);
2661
2662 let mes = "7 bytes";
2663 println!("M =\t{}", mes);
2664 let mut message = [0_u8; 7];
2665 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2666 let iv = 0x_FEDCBA0987654321_u64;
2667 println!("IV = {}", iv);
2668 let mut cipher = Vec::<u8>::new();
2669 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2670 print!("C =\t");
2671 for c in cipher.clone()
2672 { print!("{:02X} ", c); }
2673 println!();
2674 let mut txt = String::new();
2675 for c in cipher.clone()
2676 { write!(txt, "{:02X} ", c); }
2677 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2678 println!();
2679
2680 // Normal case for the message of 8 bytes
2681 let key = 0x_1234567890ABCDEF_u64;
2682 println!("K =\t{:#016X}", key);
2683 let mut a_des = DES::new_with_key_u64(key);
2684
2685 let mes = "I am OK.";
2686 println!("M =\t{}", mes);
2687 let mut message = [0_u8; 8];
2688 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2689 let iv = 0x_FEDCBA0987654321_u64;
2690 println!("IV = {}", iv);
2691 let mut cipher = Vec::<u8>::new();
2692 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2693 print!("C =\t");
2694 for c in cipher.clone()
2695 { print!("{:02X} ", c); }
2696 println!();
2697 let mut txt = String::new();
2698 for c in cipher.clone()
2699 { write!(txt, "{:02X} ", c); }
2700 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2701 println!();
2702
2703 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2704 let key = 0x_1234567890ABCDEF_u64;
2705 println!("K =\t{:#016X}", key);
2706 let mut a_des = DES::new_with_key_u64(key);
2707
2708 let mes = "PARK Youngho";
2709 println!("M =\t{}", mes);
2710 let mut message = [0_u8; 12];
2711 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2712 let iv = 0x_FEDCBA0987654321_u64;
2713 println!("IV = {}", iv);
2714 let mut cipher = Vec::<u8>::new();
2715 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2716 print!("C =\t");
2717 for c in cipher.clone()
2718 { print!("{:02X} ", c); }
2719 println!();
2720 let mut txt = String::new();
2721 for c in cipher.clone()
2722 { write!(txt, "{:02X} ", c); }
2723 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
2724 println!();
2725
2726 // Normal case for the message of 16 bytes
2727 let key = 0x_1234567890ABCDEF_u64;
2728 println!("K =\t{:#016X}", key);
2729 let mut a_des = DES::new_with_key_u64(key);
2730
2731 let mes = "고맙습니다.";
2732 println!("M =\t{}", mes);
2733 let mut message = [0_u8; 16];
2734 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2735 let iv = 0x_FEDCBA0987654321_u64;
2736 println!("IV = {}", iv);
2737 let mut cipher = Vec::<u8>::new();
2738 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2739 print!("C =\t");
2740 for c in cipher.clone()
2741 { print!("{:02X} ", c); }
2742 println!();
2743 let mut txt = String::new();
2744 for c in cipher.clone()
2745 { write!(txt, "{:02X} ", c); }
2746 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
2747 println!("-------------------------------");
2748}
2749
2750fn des_encrypt_array_cfb_into_array()
2751{
2752 println!("des_encrypt_array_cfb_into_array()");
2753 use std::io::Write;
2754 use std::fmt::Write as _;
2755 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
2756
2757 // Normal case
2758 let key = 0x_1234567890ABCDEF_u64;
2759 println!("K =\t{:#016X}", key);
2760 let mut a_des = DES::new_with_key_u64(key);
2761
2762 let mes = "In the beginning God created the heavens and the earth.";
2763 println!("M =\t{}", mes);
2764 let mut message = [0_u8; 55];
2765 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2766 let iv = 0x_FEDCBA0987654321_u64;
2767 println!("IV = {}", iv);
2768 let mut cipher = [0_u8; 55];
2769 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2770 for c in cipher.clone()
2771 { print!("{:02X} ", c); }
2772 println!();
2773 let mut txt = String::new();
2774 for c in cipher.clone()
2775 { write!(txt, "{:02X} ", c); }
2776 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
2777 println!();
2778
2779 // Expanded case for 128 rounds
2780 let key = 0x_1234567890ABCDEF_u64;
2781 println!("K =\t{:#016X}", key);
2782 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2783
2784 let mes = "In the beginning God created the heavens and the earth.";
2785 println!("M =\t{}", mes);
2786 let mut message = [0_u8; 55];
2787 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2788 let iv = 0x_FEDCBA0987654321_u64;
2789 println!("IV = {}", iv);
2790 let mut cipher = [0_u8; 55];
2791 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2792 print!("C (128 rounds) =\t");
2793 for c in cipher.clone()
2794 { print!("{:02X} ", c); }
2795 println!();
2796 let mut txt = String::new();
2797 for c in cipher.clone()
2798 { write!(txt, "{:02X} ", c); }
2799 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
2800 println!();
2801
2802 // Expanded case for 0 rounds which means that key is meaningless
2803 let key1 = 0x_1234567890ABCDEF_u64;
2804 let key2 = 0_u64;
2805 println!("K1 =\t{:#016X}", key1);
2806 println!("K2 =\t{:#016X}", key2);
2807 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2808 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2809
2810 let mes = "In the beginning God created the heavens and the earth.";
2811 println!("M =\t{}", mes);
2812 let mut message = [0_u8; 55];
2813 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2814 let iv = 0x_FEDCBA0987654321_u64;
2815 println!("IV = {}", iv);
2816 let mut cipher1 = [0_u8; 55];
2817 let mut cipher2 = [0_u8; 55];
2818 c_des.encrypt_array_into_array(iv, &message, &mut cipher1);
2819 d_des.encrypt_array_into_array(iv, &message, &mut cipher2);
2820 print!("C (0 rounds) =\t");
2821 for c in cipher1.clone()
2822 { print!("{:02X} ", c); }
2823 println!();
2824 let mut txt = String::new();
2825 for c in cipher1.clone()
2826 { write!(txt, "{:02X} ", c); }
2827 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2828 print!("D (0 rounds) =\t");
2829 for c in cipher2.clone()
2830 { print!("{:02X} ", c); }
2831 println!();
2832 let mut txt = String::new();
2833 for c in cipher2.clone()
2834 { write!(txt, "{:02X} ", c); }
2835 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
2836 println!();
2837
2838 // Normal case for the message of 0 bytes
2839 let key = 0x_1234567890ABCDEF_u64;
2840 println!("K =\t{:#016X}", key);
2841 let mut a_des = DES::new_with_key_u64(key);
2842
2843 let mes = "";
2844 println!("M =\t{}", mes);
2845 let mut message = [0_u8; 0];
2846 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2847 let iv = 0x_FEDCBA0987654321_u64;
2848 println!("IV = {}", iv);
2849 let mut cipher = [0_u8; 0];
2850 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2851 print!("C =\t");
2852 for c in cipher.clone()
2853 { print!("{:02X} ", c); }
2854 println!();
2855 let mut txt = String::new();
2856 for c in cipher.clone()
2857 { write!(txt, "{:02X} ", c); }
2858 assert_eq!(txt, "");
2859 println!();
2860
2861 // Normal case for the message shorter than 8 bytes
2862 let key = 0x_1234567890ABCDEF_u64;
2863 println!("K =\t{:#016X}", key);
2864 let mut a_des = DES::new_with_key_u64(key);
2865
2866 let mes = "7 bytes";
2867 println!("M =\t{}", mes);
2868 let mut message = [0_u8; 7];
2869 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2870 let iv = 0x_FEDCBA0987654321_u64;
2871 println!("IV = {}", iv);
2872 let mut cipher = [0_u8; 7];
2873 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2874 print!("C =\t");
2875 for c in cipher.clone()
2876 { print!("{:02X} ", c); }
2877 println!();
2878 let mut txt = String::new();
2879 for c in cipher.clone()
2880 { write!(txt, "{:02X} ", c); }
2881 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2882 println!();
2883
2884 // Normal case for the message of 8 bytes
2885 let key = 0x_1234567890ABCDEF_u64;
2886 println!("K =\t{:#016X}", key);
2887 let mut a_des = DES::new_with_key_u64(key);
2888
2889 let mes = "I am OK.";
2890 println!("M =\t{}", mes);
2891 let mut message = [0_u8; 8];
2892 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2893 let iv = 0x_FEDCBA0987654321_u64;
2894 println!("IV = {}", iv);
2895 let mut cipher = [0_u8; 8];
2896 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2897 print!("C =\t");
2898 for c in cipher.clone()
2899 { print!("{:02X} ", c); }
2900 println!();
2901 let mut txt = String::new();
2902 for c in cipher.clone()
2903 { write!(txt, "{:02X} ", c); }
2904 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2905 println!();
2906
2907 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2908 let key = 0x_1234567890ABCDEF_u64;
2909 println!("K =\t{:#016X}", key);
2910 let mut a_des = DES::new_with_key_u64(key);
2911
2912 let mes = "PARK Youngho";
2913 println!("M =\t{}", mes);
2914 let mut message = [0_u8; 12];
2915 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2916 let iv = 0x_FEDCBA0987654321_u64;
2917 println!("IV = {}", iv);
2918 let mut cipher = [0_u8; 12];
2919 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2920 print!("C =\t");
2921 for c in cipher.clone()
2922 { print!("{:02X} ", c); }
2923 println!();
2924 let mut txt = String::new();
2925 for c in cipher.clone()
2926 { write!(txt, "{:02X} ", c); }
2927 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
2928 println!();
2929
2930 // Normal case for the message of 16 bytes
2931 let key = 0x_1234567890ABCDEF_u64;
2932 println!("K =\t{:#016X}", key);
2933 let mut a_des = DES::new_with_key_u64(key);
2934
2935 let mes = "고맙습니다.";
2936 println!("M =\t{}", mes);
2937 let mut message = [0_u8; 16];
2938 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2939 let iv = 0x_FEDCBA0987654321_u64;
2940 println!("IV = {}", iv);
2941 let mut cipher = [0_u8; 16];
2942 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2943 print!("C =\t");
2944 for c in cipher.clone()
2945 { print!("{:02X} ", c); }
2946 println!();
2947 let mut txt = String::new();
2948 for c in cipher.clone()
2949 { write!(txt, "{:02X} ", c); }
2950 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
2951 println!("-------------------------------");
2952}
2953
2954fn des_decrypt_cfb()
2955{
2956 println!("des_decrypt_cfb()");
2957 use std::io::Write;
2958 use std::fmt::Write as _;
2959 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
2960
2961 // Normal case
2962 let key = 0x_1234567890ABCDEF_u64;
2963 println!("K =\t{:#016X}", key);
2964 let mut a_des = DES::new_with_key_u64(key);
2965
2966 let message = "In the beginning God created the heavens and the earth.";
2967 println!("M =\t{}", message);
2968 let iv = 0x_FEDCBA0987654321_u64;
2969 println!("IV = {}", iv);
2970 let mut cipher = Vec::<u8>::new();
2971 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
2972 print!("C (16 rounds) =\t");
2973 for c in cipher.clone()
2974 { print!("{:02X} ", c); }
2975 println!();
2976 let mut txt = String::new();
2977 for c in cipher.clone()
2978 { write!(txt, "{:02X} ", c); }
2979 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
2980
2981 let mut recovered = vec![0; 55];
2982 a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2983 print!("Ba (16 rounds) =\t");
2984 for b in recovered.clone()
2985 { print!("{:02X} ", b); }
2986 println!();
2987 let mut txt = String::new();
2988 for c in recovered.clone()
2989 { write!(txt, "{:02X} ", c); }
2990 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2991
2992 let mut converted = String::new();
2993 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2994
2995 println!("Bb (16 rounds) =\t{}", converted);
2996 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2997 assert_eq!(converted, message);
2998 println!();
2999
3000 // Expanded case for 128 rounds
3001 let key = 0x_1234567890ABCDEF_u64;
3002 println!("K =\t{:#016X}", key);
3003 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3004
3005 let message = "In the beginning God created the heavens and the earth.";
3006 println!("M =\t{}", message);
3007 let iv = 0x_FEDCBA0987654321_u64;
3008 println!("IV = {}", iv);
3009 let mut cipher = Vec::<u8>::new();
3010 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3011 print!("C (128 rounds) =\t");
3012 for c in cipher.clone()
3013 { print!("{:02X} ", c); }
3014 println!();
3015 let mut txt = String::new();
3016 for c in cipher.clone()
3017 { write!(txt, "{:02X} ", c); }
3018 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
3019
3020 let mut recovered = vec![0; 55];
3021 a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3022 print!("Ba (128 rounds) =\t");
3023 for b in recovered.clone()
3024 { print!("{:02X} ", b); }
3025 println!();
3026 let mut txt = String::new();
3027 for c in recovered.clone()
3028 { write!(txt, "{:02X} ", c); }
3029 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3030
3031 let mut converted = String::new();
3032 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3033
3034 println!("Bb (128 rounds) =\t{}", converted);
3035 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3036 assert_eq!(converted, message);
3037 println!();
3038
3039 // Expanded case for 0 rounds which means that key is meaningless
3040 let key1 = 0x_1234567890ABCDEF_u64;
3041 let key2 = 0_u64;
3042 println!("K =\t{:#016X}", key);
3043 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3044 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3045
3046 let message = "In the beginning God created the heavens and the earth.";
3047 println!("M =\t{}", message);
3048 let iv = 0x_FEDCBA0987654321_u64;
3049 println!("IV = {}", iv);
3050 let mut cipher1 = Vec::<u8>::new();
3051 let mut cipher2 = Vec::<u8>::new();
3052 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
3053 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
3054 print!("C (0 rounds) =\t");
3055 for c in cipher1.clone()
3056 { print!("{:02X} ", c); }
3057 println!();
3058 let mut txt = String::new();
3059 for c in cipher1.clone()
3060 { write!(txt, "{:02X} ", c); }
3061 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
3062 print!("D (0 rounds) =\t");
3063 for c in cipher2.clone()
3064 { print!("{:02X} ", c); }
3065 println!();
3066 let mut txt = String::new();
3067 for c in cipher2.clone()
3068 { write!(txt, "{:02X} ", c); }
3069 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
3070
3071 let mut recovered1 = vec![0; 55];
3072 let mut recovered2 = vec![0; 55];
3073 c_des.decrypt(iv, cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
3074 d_des.decrypt(iv, cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
3075 print!("B1a (0 rounds) =\t");
3076 for b in recovered1.clone()
3077 { print!("{:02X} ", b); }
3078 println!();
3079 let mut txt = String::new();
3080 for c in recovered1.clone()
3081 { write!(txt, "{:02X} ", c); }
3082 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3083 print!("B2a (0 rounds) =\t");
3084 for b in recovered2.clone()
3085 { print!("{:02X} ", b); }
3086 println!();
3087 let mut txt = String::new();
3088 for c in recovered2.clone()
3089 { write!(txt, "{:02X} ", c); }
3090 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3091
3092 let mut converted1 = String::new();
3093 let mut converted2 = String::new();
3094 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3095 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3096
3097 println!("B1b (0 rounds) =\t{}", converted1);
3098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3099 assert_eq!(converted1, message);
3100 println!("B2b (0 rounds) =\t{}", converted2);
3101 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3102 assert_eq!(converted2, message);
3103 assert_eq!(converted1, converted1);
3104 println!();
3105
3106 // Normal case for the message of 0 bytes
3107 let key = 0x_1234567890ABCDEF_u64;
3108 println!("K =\t{:#016X}", key);
3109 let mut a_des = DES::new_with_key_u64(key);
3110
3111 let message = "";
3112 println!("M =\t{}", message);
3113 let iv = 0x_FEDCBA0987654321_u64;
3114 println!("IV = {}", iv);
3115 let mut cipher = Vec::<u8>::new();
3116 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3117 print!("C =\t");
3118 for c in cipher.clone()
3119 { print!("{:02X} ", c); }
3120 println!();
3121 let mut txt = String::new();
3122 for c in cipher.clone()
3123 { write!(txt, "{:02X} ", c); }
3124 assert_eq!(txt, "");
3125
3126 let mut recovered = vec![0; 8];
3127 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3128 print!("Ba =\t");
3129 for b in recovered.clone()
3130 { print!("{:02X} ", b); }
3131 println!();
3132 let mut txt = String::new();
3133 for c in recovered.clone()
3134 { write!(txt, "{:02X} ", c); }
3135 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3136
3137 let mut converted = String::new();
3138 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139 converted.truncate(len as usize);
3140
3141 println!("Bb =\t{}", converted);
3142 assert_eq!(converted, "");
3143 assert_eq!(converted, message);
3144 println!();
3145
3146 // Normal case for the message shorter than 8 bytes
3147 let key = 0x_1234567890ABCDEF_u64;
3148 println!("K =\t{:#016X}", key);
3149 let mut a_des = DES::new_with_key_u64(key);
3150
3151 let message = "7 bytes";
3152 println!("M =\t{}", message);
3153 let iv = 0x_FEDCBA0987654321_u64;
3154 println!("IV = {}", iv);
3155 let mut cipher = Vec::<u8>::new();
3156 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3157 print!("C =\t");
3158 for c in cipher.clone()
3159 { print!("{:02X} ", c); }
3160 println!();
3161 let mut txt = String::new();
3162 for c in cipher.clone()
3163 { write!(txt, "{:02X} ", c); }
3164 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
3165
3166 let mut recovered = vec![0; 8];
3167 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3168 print!("Ba =\t");
3169 for b in recovered.clone()
3170 { print!("{:02X} ", b); }
3171 println!();
3172 let mut txt = String::new();
3173 for c in recovered.clone()
3174 { write!(txt, "{:02X} ", c); }
3175 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3176
3177 let mut converted = String::new();
3178 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3179 converted.truncate(len as usize);
3180
3181 println!("Bb =\t{}", converted);
3182 assert_eq!(converted, "7 bytes");
3183 assert_eq!(converted, message);
3184 println!();
3185
3186 // Normal case for the message of 8 bytes
3187 let key = 0x_1234567890ABCDEF_u64;
3188 println!("K =\t{:#016X}", key);
3189 let mut a_des = DES::new_with_key_u64(key);
3190
3191 let message = "I am OK.";
3192 println!("M =\t{}", message);
3193 let iv = 0x_FEDCBA0987654321_u64;
3194 println!("IV = {}", iv);
3195 let mut cipher = Vec::<u8>::new();
3196 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3197 print!("C =\t");
3198 for c in cipher.clone()
3199 { print!("{:02X} ", c); }
3200 println!();
3201 let mut txt = String::new();
3202 for c in cipher.clone()
3203 { write!(txt, "{:02X} ", c); }
3204 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
3205
3206 let mut recovered = vec![0; 16];
3207 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3208 print!("Ba =\t");
3209 for b in recovered.clone()
3210 { print!("{:02X} ", b); }
3211 println!();
3212 let mut txt = String::new();
3213 for c in recovered.clone()
3214 { write!(txt, "{:02X} ", c); }
3215 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3216
3217 let mut converted = String::new();
3218 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3219 converted.truncate(len as usize);
3220
3221 println!("Bb =\t{}", converted);
3222 assert_eq!(converted, "I am OK.");
3223 assert_eq!(converted, message);
3224 println!();
3225
3226 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3227 let key = 0x_1234567890ABCDEF_u64;
3228 println!("K =\t{:#016X}", key);
3229 let mut a_des = DES::new_with_key_u64(key);
3230
3231 let message = "PARK Youngho";
3232 println!("M =\t{}", message);
3233 let iv = 0x_FEDCBA0987654321_u64;
3234 println!("IV = {}", iv);
3235 let mut cipher = Vec::<u8>::new();
3236 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3237 print!("C =\t");
3238 for c in cipher.clone()
3239 { print!("{:02X} ", c); }
3240 println!();
3241 let mut txt = String::new();
3242 for c in cipher.clone()
3243 { write!(txt, "{:02X} ", c); }
3244 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
3245
3246 let mut recovered = vec![0; 16];
3247 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3248 print!("Ba =\t");
3249 for b in recovered.clone()
3250 { print!("{:02X} ", b); }
3251 println!();
3252 let mut txt = String::new();
3253 for c in recovered.clone()
3254 { write!(txt, "{:02X} ", c); }
3255 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3256
3257 let mut converted = String::new();
3258 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3259 converted.truncate(len as usize);
3260
3261 println!("Bb =\t{}", converted);
3262 assert_eq!(converted, "PARK Youngho");
3263 assert_eq!(converted, message);
3264 println!();
3265
3266 // Normal case for the message of 16 bytes
3267 let key = 0x_1234567890ABCDEF_u64;
3268 println!("K =\t{:#016X}", key);
3269 let mut a_des = DES::new_with_key_u64(key);
3270
3271 let message = "고맙습니다.";
3272 println!("M =\t{}", message);
3273 let iv = 0x_FEDCBA0987654321_u64;
3274 println!("IV = {}", iv);
3275 let mut cipher = Vec::<u8>::new();
3276 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3277 print!("C =\t");
3278 for c in cipher.clone()
3279 { print!("{:02X} ", c); }
3280 println!();
3281 let mut txt = String::new();
3282 for c in cipher.clone()
3283 { write!(txt, "{:02X} ", c); }
3284 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
3285
3286 let mut recovered = vec![0; 24];
3287 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3288 print!("Ba =\t");
3289 for b in recovered.clone()
3290 { print!("{:02X} ", b); }
3291 println!();
3292 let mut txt = String::new();
3293 for c in recovered.clone()
3294 { write!(txt, "{:02X} ", c); }
3295 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3296
3297 let mut converted = String::new();
3298 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3299 converted.truncate(len as usize);
3300
3301 println!("Bb =\t{}", converted);
3302 assert_eq!(converted, "고맙습니다.");
3303 assert_eq!(converted, message);
3304 println!("-------------------------------");
3305}
3306
3307fn des_decrypt_cfb_into_vec()
3308{
3309 println!("des_decrypt_cfb_into_vec()");
3310 use std::io::Write;
3311 use std::fmt::Write as _;
3312 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
3313
3314 // Normal case
3315 let key = 0x_1234567890ABCDEF_u64;
3316 println!("K =\t{:#016X}", key);
3317 let mut a_des = DES::new_with_key_u64(key);
3318
3319 let message = "In the beginning God created the heavens and the earth.";
3320 println!("M =\t{}", message);
3321 let iv = 0x_FEDCBA0987654321_u64;
3322 println!("IV = {}", iv);
3323 let mut cipher = Vec::<u8>::new();
3324 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3325 print!("C (16 rounds) =\t");
3326 for c in cipher.clone()
3327 { print!("{:02X} ", c); }
3328 println!();
3329 let mut txt = String::new();
3330 for c in cipher.clone()
3331 { write!(txt, "{:02X} ", c); }
3332 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
3333
3334 let mut recovered = Vec::<u8>::new();
3335 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3336 print!("Ba (16 rounds) =\t");
3337 for b in recovered.clone()
3338 { print!("{:02X} ", b); }
3339 println!();
3340 let mut txt = String::new();
3341 for c in recovered.clone()
3342 { write!(txt, "{:02X} ", c); }
3343 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3344
3345 let mut converted = String::new();
3346 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3347
3348 println!("Bb (16 rounds) =\t{}", converted);
3349 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3350 assert_eq!(converted, message);
3351 println!();
3352
3353 // Expanded case for 128 rounds
3354 let key = 0x_1234567890ABCDEF_u64;
3355 println!("K =\t{:#016X}", key);
3356 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3357
3358 let message = "In the beginning God created the heavens and the earth.";
3359 println!("M =\t{}", message);
3360 let iv = 0x_FEDCBA0987654321_u64;
3361 println!("IV = {}", iv);
3362 let mut cipher = Vec::<u8>::new();
3363 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3364 print!("C (128 rounds) =\t");
3365 for c in cipher.clone()
3366 { print!("{:02X} ", c); }
3367 println!();
3368 let mut txt = String::new();
3369 for c in cipher.clone()
3370 { write!(txt, "{:02X} ", c); }
3371 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
3372
3373 let mut recovered = Vec::<u8>::new();
3374 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3375 print!("Ba (128 rounds) =\t");
3376 for b in recovered.clone()
3377 { print!("{:02X} ", b); }
3378 println!();
3379 let mut txt = String::new();
3380 for c in recovered.clone()
3381 { write!(txt, "{:02X} ", c); }
3382 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3383
3384 let mut converted = String::new();
3385 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3386
3387 println!("Bb (128 rounds) =\t{}", converted);
3388 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3389 assert_eq!(converted, message);
3390 println!();
3391
3392 // Expanded case for 0 rounds which means that key is meaningless
3393 let key1 = 0x_1234567890ABCDEF_u64;
3394 let key2 = 0_u64;
3395 println!("K =\t{:#016X}", key);
3396 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3397 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3398
3399 let message = "In the beginning God created the heavens and the earth.";
3400 println!("M =\t{}", message);
3401 let iv = 0x_FEDCBA0987654321_u64;
3402 println!("IV = {}", iv);
3403 let mut cipher1 = Vec::<u8>::new();
3404 let mut cipher2 = Vec::<u8>::new();
3405 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
3406 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
3407 print!("C (0 rounds) =\t");
3408 for c in cipher1.clone()
3409 { print!("{:02X} ", c); }
3410 println!();
3411 let mut txt = String::new();
3412 for c in cipher1.clone()
3413 { write!(txt, "{:02X} ", c); }
3414 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
3415 print!("D (0 rounds) =\t");
3416 for c in cipher2.clone()
3417 { print!("{:02X} ", c); }
3418 println!();
3419 let mut txt = String::new();
3420 for c in cipher2.clone()
3421 { write!(txt, "{:02X} ", c); }
3422 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
3423
3424 let mut recovered1 = Vec::<u8>::new();
3425 let mut recovered2 = Vec::<u8>::new();
3426 c_des.decrypt_into_vec(iv, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3427 d_des.decrypt_into_vec(iv, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3428 print!("B1a (0 rounds) =\t");
3429 for b in recovered1.clone()
3430 { print!("{:02X} ", b); }
3431 println!();
3432 let mut txt = String::new();
3433 for c in recovered1.clone()
3434 { write!(txt, "{:02X} ", c); }
3435 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3436 print!("B2a (0 rounds) =\t");
3437 for b in recovered2.clone()
3438 { print!("{:02X} ", b); }
3439 println!();
3440 let mut txt = String::new();
3441 for c in recovered2.clone()
3442 { write!(txt, "{:02X} ", c); }
3443 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3444
3445 let mut converted1 = String::new();
3446 let mut converted2 = String::new();
3447 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3448 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3449
3450 println!("B1b (0 rounds) =\t{}", converted1);
3451 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3452 assert_eq!(converted1, message);
3453 println!("B2b (0 rounds) =\t{}", converted2);
3454 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3455 assert_eq!(converted2, message);
3456 assert_eq!(converted1, converted1);
3457 println!();
3458
3459 // Normal case for the message of 0 bytes
3460 let key = 0x_1234567890ABCDEF_u64;
3461 println!("K =\t{:#016X}", key);
3462 let mut a_des = DES::new_with_key_u64(key);
3463
3464 let message = "";
3465 println!("M =\t{}", message);
3466 let iv = 0x_FEDCBA0987654321_u64;
3467 println!("IV = {}", iv);
3468 let mut cipher = Vec::<u8>::new();
3469 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3470 print!("C =\t");
3471 for c in cipher.clone()
3472 { print!("{:02X} ", c); }
3473 println!();
3474 let mut txt = String::new();
3475 for c in cipher.clone()
3476 { write!(txt, "{:02X} ", c); }
3477 assert_eq!(txt, "");
3478
3479 let mut recovered = Vec::<u8>::new();
3480 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3481 print!("Ba =\t");
3482 for b in recovered.clone()
3483 { print!("{:02X} ", b); }
3484 println!();
3485 let mut txt = String::new();
3486 for c in recovered.clone()
3487 { write!(txt, "{:02X} ", c); }
3488 assert_eq!(txt, "");
3489
3490 let mut converted = String::new();
3491 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3492
3493 println!("Bb =\t{}", converted);
3494 assert_eq!(converted, "");
3495 assert_eq!(converted, message);
3496 println!();
3497
3498 // Normal case for the message shorter than 8 bytes
3499 let key = 0x_1234567890ABCDEF_u64;
3500 println!("K =\t{:#016X}", key);
3501 let mut a_des = DES::new_with_key_u64(key);
3502
3503 let message = "7 bytes";
3504 println!("M =\t{}", message);
3505 let iv = 0x_FEDCBA0987654321_u64;
3506 println!("IV = {}", iv);
3507 let mut cipher = Vec::<u8>::new();
3508 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3509 print!("C =\t");
3510 for c in cipher.clone()
3511 { print!("{:02X} ", c); }
3512 println!();
3513 let mut txt = String::new();
3514 for c in cipher.clone()
3515 { write!(txt, "{:02X} ", c); }
3516 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
3517
3518 let mut recovered = Vec::<u8>::new();
3519 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3520 print!("Ba =\t");
3521 for b in recovered.clone()
3522 { print!("{:02X} ", b); }
3523 println!();
3524 let mut txt = String::new();
3525 for c in recovered.clone()
3526 { write!(txt, "{:02X} ", c); }
3527 assert_eq!(txt, "37 20 62 79 74 65 73 ");
3528
3529 let mut converted = String::new();
3530 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3531
3532 println!("Bb =\t{}", converted);
3533 assert_eq!(converted, "7 bytes");
3534 assert_eq!(converted, message);
3535 println!();
3536
3537 // Normal case for the message of 8 bytes
3538 let key = 0x_1234567890ABCDEF_u64;
3539 println!("K =\t{:#016X}", key);
3540 let mut a_des = DES::new_with_key_u64(key);
3541
3542 let message = "I am OK.";
3543 println!("M =\t{}", message);
3544 let iv = 0x_FEDCBA0987654321_u64;
3545 println!("IV = {}", iv);
3546 let mut cipher = Vec::<u8>::new();
3547 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3548 print!("C =\t");
3549 for c in cipher.clone()
3550 { print!("{:02X} ", c); }
3551 println!();
3552 let mut txt = String::new();
3553 for c in cipher.clone()
3554 { write!(txt, "{:02X} ", c); }
3555 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
3556
3557 let mut recovered = Vec::<u8>::new();
3558 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3559 print!("Ba =\t");
3560 for b in recovered.clone()
3561 { print!("{:02X} ", b); }
3562 println!();
3563 let mut txt = String::new();
3564 for c in recovered.clone()
3565 { write!(txt, "{:02X} ", c); }
3566 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3567
3568 let mut converted = String::new();
3569 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3570
3571 println!("Bb =\t{}", converted);
3572 assert_eq!(converted, "I am OK.");
3573 assert_eq!(converted, message);
3574 println!();
3575
3576 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3577 let key = 0x_1234567890ABCDEF_u64;
3578 println!("K =\t{:#016X}", key);
3579 let mut a_des = DES::new_with_key_u64(key);
3580
3581 let message = "PARK Youngho";
3582 println!("M =\t{}", message);
3583 let iv = 0x_FEDCBA0987654321_u64;
3584 println!("IV = {}", iv);
3585 let mut cipher = Vec::<u8>::new();
3586 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3587 print!("C =\t");
3588 for c in cipher.clone()
3589 { print!("{:02X} ", c); }
3590 println!();
3591 let mut txt = String::new();
3592 for c in cipher.clone()
3593 { write!(txt, "{:02X} ", c); }
3594 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
3595
3596 let mut recovered = Vec::<u8>::new();
3597 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3598 print!("Ba =\t");
3599 for b in recovered.clone()
3600 { print!("{:02X} ", b); }
3601 println!();
3602 let mut txt = String::new();
3603 for c in recovered.clone()
3604 { write!(txt, "{:02X} ", c); }
3605 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3606
3607 let mut converted = String::new();
3608 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3609
3610 println!("Bb =\t{}", converted);
3611 assert_eq!(converted, "PARK Youngho");
3612 assert_eq!(converted, message);
3613 println!();
3614
3615 // Normal case for the message of 16 bytes
3616 let key = 0x_1234567890ABCDEF_u64;
3617 println!("K =\t{:#016X}", key);
3618 let mut a_des = DES::new_with_key_u64(key);
3619
3620 let message = "고맙습니다.";
3621 println!("M =\t{}", message);
3622 let iv = 0x_FEDCBA0987654321_u64;
3623 println!("IV = {}", iv);
3624 let mut cipher = Vec::<u8>::new();
3625 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3626 print!("C =\t");
3627 for c in cipher.clone()
3628 { print!("{:02X} ", c); }
3629 println!();
3630 let mut txt = String::new();
3631 for c in cipher.clone()
3632 { write!(txt, "{:02X} ", c); }
3633 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
3634
3635 let mut recovered = Vec::<u8>::new();
3636 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3637 print!("Ba =\t");
3638 for b in recovered.clone()
3639 { print!("{:02X} ", b); }
3640 println!();
3641 let mut txt = String::new();
3642 for c in recovered.clone()
3643 { write!(txt, "{:02X} ", c); }
3644 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3645
3646 let mut converted = String::new();
3647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3648
3649 println!("Bb =\t{}", converted);
3650 assert_eq!(converted, "고맙습니다.");
3651 assert_eq!(converted, message);
3652 println!("-------------------------------");
3653}
3654
3655fn des_decrypt_cfb_into_array()
3656{
3657 println!("des_decrypt_cfb_into_array()");
3658 use std::io::Write;
3659 use std::fmt::Write as _;
3660 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
3661
3662 // Normal case
3663 let key = 0x_1234567890ABCDEF_u64;
3664 println!("K =\t{:#016X}", key);
3665 let mut a_des = DES::new_with_key_u64(key);
3666
3667 let message = "In the beginning God created the heavens and the earth.";
3668 println!("M =\t{}", message);
3669 let iv = 0x_FEDCBA0987654321_u64;
3670 println!("IV = {}", iv);
3671 let mut cipher = Vec::<u8>::new();
3672 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3673 print!("C (16 rounds) =\t");
3674 for c in cipher.clone()
3675 { print!("{:02X} ", c); }
3676 println!();
3677 let mut txt = String::new();
3678 for c in cipher.clone()
3679 { write!(txt, "{:02X} ", c); }
3680 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
3681
3682 let mut recovered = [0u8; 56];
3683 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3684 print!("Ba (16 rounds) =\t");
3685 for b in recovered.clone()
3686 { print!("{:02X} ", b); }
3687 println!();
3688 let mut txt = String::new();
3689 for c in recovered.clone()
3690 { write!(txt, "{:02X} ", c); }
3691 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3692
3693 let mut converted = String::new();
3694 unsafe { converted.as_mut_vec() }.write(&recovered);
3695 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3696 println!("Bb (16 rounds) =\t{}", converted);
3697 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3698 assert_eq!(converted, message);
3699 println!();
3700
3701 // Expanded case for 128 rounds
3702 let key = 0x_1234567890ABCDEF_u64;
3703 println!("K =\t{:#016X}", key);
3704 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3705
3706 let message = "In the beginning God created the heavens and the earth.";
3707 println!("M =\t{}", message);
3708 let iv = 0x_FEDCBA0987654321_u64;
3709 println!("IV = {}", iv);
3710 let mut cipher = Vec::<u8>::new();
3711 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3712 print!("C (128 rounds) =\t");
3713 for c in cipher.clone()
3714 { print!("{:02X} ", c); }
3715 println!();
3716 let mut txt = String::new();
3717 for c in cipher.clone()
3718 { write!(txt, "{:02X} ", c); }
3719 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
3720
3721 let mut recovered = [0u8; 56];
3722 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3723 print!("Ba (16 rounds) =\t");
3724 for b in recovered.clone()
3725 { print!("{:02X} ", b); }
3726 println!();
3727 let mut txt = String::new();
3728 for c in recovered.clone()
3729 { write!(txt, "{:02X} ", c); }
3730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3731
3732 let mut converted = String::new();
3733 unsafe { converted.as_mut_vec() }.write(&recovered);
3734 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3735 println!("Bb (16 rounds) =\t{}", converted);
3736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3737 assert_eq!(converted, message);
3738 println!();
3739
3740 // Expanded case for 0 rounds which means that key is meaningless
3741 let key1 = 0x_1234567890ABCDEF_u64;
3742 let key2 = 0_u64;
3743 println!("K =\t{:#016X}", key);
3744 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3745 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3746
3747 let message = "In the beginning God created the heavens and the earth.";
3748 println!("M =\t{}", message);
3749 let iv = 0x_FEDCBA0987654321_u64;
3750 println!("IV = {}", iv);
3751 let mut cipher1 = Vec::<u8>::new();
3752 let mut cipher2 = Vec::<u8>::new();
3753 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
3754 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
3755 print!("C (0 rounds) =\t");
3756 for c in cipher1.clone()
3757 { print!("{:02X} ", c); }
3758 println!();
3759 let mut txt = String::new();
3760 for c in cipher1.clone()
3761 { write!(txt, "{:02X} ", c); }
3762 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
3763 print!("D (0 rounds) =\t");
3764 for c in cipher2.clone()
3765 { print!("{:02X} ", c); }
3766 println!();
3767 let mut txt = String::new();
3768 for c in cipher2.clone()
3769 { write!(txt, "{:02X} ", c); }
3770 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
3771
3772 let mut recovered1 = [0u8; 56];
3773 let mut recovered2 = [0u8; 56];
3774 let len1 = c_des.decrypt_into_array(iv, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3775 let len2 = d_des.decrypt_into_array(iv, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3776 print!("B1a (0 rounds) =\t");
3777 for b in recovered1.clone()
3778 { print!("{:02X} ", b); }
3779 println!();
3780 let mut txt = String::new();
3781 for c in recovered1.clone()
3782 { write!(txt, "{:02X} ", c); }
3783 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3784 print!("B2a (0 rounds) =\t");
3785 for b in recovered2.clone()
3786 { print!("{:02X} ", b); }
3787 println!();
3788 let mut txt = String::new();
3789 for c in recovered.clone()
3790 { write!(txt, "{:02X} ", c); }
3791 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3792
3793 let mut converted1 = String::new();
3794 let mut converted2 = String::new();
3795 unsafe { converted1.as_mut_vec() }.write(&recovered1);
3796 unsafe { converted2.as_mut_vec() }.write(&recovered2);
3797 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3798 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3799 println!("B1b (0 rounds) =\t{}", converted1);
3800 println!("B2b (0 rounds) =\t{}", converted2);
3801 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3802 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3803 assert_eq!(converted1, message);
3804 assert_eq!(converted2, message);
3805 assert_eq!(converted1, converted2);
3806 println!();
3807
3808 // Normal case for the message of 0 bytes
3809 let key = 0x_1234567890ABCDEF_u64;
3810 println!("K =\t{:#016X}", key);
3811 let mut a_des = DES::new_with_key_u64(key);
3812
3813 let message = "";
3814 println!("M =\t{}", message);
3815 let iv = 0x_FEDCBA0987654321_u64;
3816 println!("IV = {}", iv);
3817 let mut cipher = Vec::<u8>::new();
3818 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3819 print!("C =\t");
3820 for c in cipher.clone()
3821 { print!("{:02X} ", c); }
3822 println!();
3823 let mut txt = String::new();
3824 for c in cipher.clone()
3825 { write!(txt, "{:02X} ", c); }
3826 assert_eq!(txt, "");
3827
3828 let mut recovered = [0u8; 8];
3829 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3830
3831 print!("Ba =\t");
3832 for b in recovered.clone()
3833 { print!("{:02X} ", b); }
3834 println!();
3835 let mut txt = String::new();
3836 for c in recovered.clone()
3837 { write!(txt, "{:02X} ", c); }
3838 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3839
3840 let mut converted = String::new();
3841 unsafe { converted.as_mut_vec() }.write(&recovered);
3842 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3843 println!("Bb =\t{}", converted);
3844 assert_eq!(converted, "");
3845 assert_eq!(converted, message);
3846 println!();
3847
3848 // Normal case for the message shorter than 8 bytes
3849 let key = 0x_1234567890ABCDEF_u64;
3850 println!("K =\t{:#016X}", key);
3851 let mut a_des = DES::new_with_key_u64(key);
3852
3853 let message = "7 bytes";
3854 println!("M =\t{}", message);
3855 let iv = 0x_FEDCBA0987654321_u64;
3856 println!("IV = {}", iv);
3857 let mut cipher = Vec::<u8>::new();
3858 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3859 print!("C =\t");
3860 for c in cipher.clone()
3861 { print!("{:02X} ", c); }
3862 println!();
3863 let mut txt = String::new();
3864 for c in cipher.clone()
3865 { write!(txt, "{:02X} ", c); }
3866 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
3867
3868 let mut recovered = [0u8; 8];
3869 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3870
3871 print!("Ba =\t");
3872 for b in recovered.clone()
3873 { print!("{:02X} ", b); }
3874 println!();
3875 let mut txt = String::new();
3876 for c in recovered.clone()
3877 { write!(txt, "{:02X} ", c); }
3878 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3879
3880 let mut converted = String::new();
3881 unsafe { converted.as_mut_vec() }.write(&recovered);
3882 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3883 println!("Bb =\t{}", converted);
3884 assert_eq!(converted, "7 bytes");
3885 assert_eq!(converted, message);
3886 println!();
3887
3888 // Normal case for the message of 8 bytes
3889 let key = 0x_1234567890ABCDEF_u64;
3890 println!("K =\t{:#016X}", key);
3891 let mut a_des = DES::new_with_key_u64(key);
3892
3893 let message = "I am OK.";
3894 println!("M =\t{}", message);
3895 let iv = 0x_FEDCBA0987654321_u64;
3896 println!("IV = {}", iv);
3897 let mut cipher = Vec::<u8>::new();
3898 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3899 print!("C =\t");
3900 for c in cipher.clone()
3901 { print!("{:02X} ", c); }
3902 println!();
3903 let mut txt = String::new();
3904 for c in cipher.clone()
3905 { write!(txt, "{:02X} ", c); }
3906 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
3907
3908 let mut recovered = [0u8; 16];
3909 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3910
3911 print!("Ba =\t");
3912 for b in recovered.clone()
3913 { print!("{:02X} ", b); }
3914 println!();
3915 let mut txt = String::new();
3916 for c in recovered.clone()
3917 { write!(txt, "{:02X} ", c); }
3918 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3919
3920 let mut converted = String::new();
3921 unsafe { converted.as_mut_vec() }.write(&recovered);
3922 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3923 println!("Bb =\t{}", converted);
3924 assert_eq!(converted, "I am OK.");
3925 assert_eq!(converted, message);
3926 println!();
3927
3928 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3929 let key = 0x_1234567890ABCDEF_u64;
3930 println!("K =\t{:#016X}", key);
3931 let mut a_des = DES::new_with_key_u64(key);
3932
3933 let message = "PARK Youngho";
3934 println!("M =\t{}", message);
3935 let iv = 0x_FEDCBA0987654321_u64;
3936 println!("IV = {}", iv);
3937 let mut cipher = Vec::<u8>::new();
3938 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3939 print!("C =\t");
3940 for c in cipher.clone()
3941 { print!("{:02X} ", c); }
3942 println!();
3943 let mut txt = String::new();
3944 for c in cipher.clone()
3945 { write!(txt, "{:02X} ", c); }
3946 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
3947
3948 let mut recovered = [0u8; 16];
3949 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3950
3951 print!("Ba =\t");
3952 for b in recovered.clone()
3953 { print!("{:02X} ", b); }
3954 println!();
3955 let mut txt = String::new();
3956 for c in recovered.clone()
3957 { write!(txt, "{:02X} ", c); }
3958 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3959
3960 let mut converted = String::new();
3961 unsafe { converted.as_mut_vec() }.write(&recovered);
3962 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3963 println!("Bb =\t{}", converted);
3964 assert_eq!(converted, "PARK Youngho");
3965 assert_eq!(converted, message);
3966 println!();
3967
3968 // Normal case for the message of 16 bytes
3969 let key = 0x_1234567890ABCDEF_u64;
3970 println!("K =\t{:#016X}", key);
3971 let mut a_des = DES::new_with_key_u64(key);
3972
3973 let message = "고맙습니다.";
3974 println!("M =\t{}", message);
3975 let iv = 0x_FEDCBA0987654321_u64;
3976 println!("IV = {}", iv);
3977 let mut cipher = Vec::<u8>::new();
3978 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3979 print!("C =\t");
3980 for c in cipher.clone()
3981 { print!("{:02X} ", c); }
3982 println!();
3983 let mut txt = String::new();
3984 for c in cipher.clone()
3985 { write!(txt, "{:02X} ", c); }
3986 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
3987
3988 let mut recovered = [0u8; 24];
3989 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3990
3991 print!("Ba =\t");
3992 for b in recovered.clone()
3993 { print!("{:02X} ", b); }
3994 println!();
3995 let mut txt = String::new();
3996 for c in recovered.clone()
3997 { write!(txt, "{:02X} ", c); }
3998 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3999
4000 let mut converted = String::new();
4001 unsafe { converted.as_mut_vec() }.write(&recovered);
4002 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4003 println!("Bb =\t{}", converted);
4004 assert_eq!(converted, "고맙습니다.");
4005 assert_eq!(converted, message);
4006 println!("-------------------------------");
4007}
4008
4009fn des_decrypt_cfb_into_string()
4010{
4011 println!("des_decrypt_cfb_into_string()");
4012 use std::io::Write;
4013 use std::fmt::Write as _;
4014 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
4015
4016 // Normal case
4017 let key = 0x_1234567890ABCDEF_u64;
4018 println!("K =\t{:#016X}", key);
4019 let mut a_des = DES::new_with_key_u64(key);
4020
4021 let message = "In the beginning God created the heavens and the earth.";
4022 println!("M =\t{}", message);
4023 let iv = 0x_FEDCBA0987654321_u64;
4024 println!("IV = {}", iv);
4025 let mut cipher = Vec::<u8>::new();
4026 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4027 print!("C (16 rounds) =\t");
4028 for c in cipher.clone()
4029 { print!("{:02X} ", c); }
4030 println!();
4031 let mut txt = String::new();
4032 for c in cipher.clone()
4033 { write!(txt, "{:02X} ", c); }
4034 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
4035
4036 let mut recovered = String::new();
4037 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4038 println!("B (16 rounds) =\t{}", recovered);
4039 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4040 assert_eq!(recovered, message);
4041 println!();
4042
4043 // Expanded case for 128 rounds
4044 let key = 0x_1234567890ABCDEF_u64;
4045 println!("K =\t{:#016X}", key);
4046 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4047
4048 let message = "In the beginning God created the heavens and the earth.";
4049 println!("M =\t{}", message);
4050 let iv = 0x_FEDCBA0987654321_u64;
4051 println!("IV = {}", iv);
4052 let mut cipher = Vec::<u8>::new();
4053 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4054 print!("C (128 rounds) =\t");
4055 for c in cipher.clone()
4056 { print!("{:02X} ", c); }
4057 println!();
4058 let mut txt = String::new();
4059 for c in cipher.clone()
4060 { write!(txt, "{:02X} ", c); }
4061 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
4062
4063 let mut recovered = String::new();
4064 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4065 println!("B (128 rounds) =\t{}", recovered);
4066 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4067 assert_eq!(recovered, message);
4068 println!();
4069
4070 // Expanded case for 0 rounds which means that key is meaningless
4071 let key1 = 0x_1234567890ABCDEF_u64;
4072 let key2 = 0_u64;
4073 println!("K =\t{:#016X}", key);
4074 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4075 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4076
4077 let message = "In the beginning God created the heavens and the earth.";
4078 println!("M =\t{}", message);
4079 let iv = 0x_FEDCBA0987654321_u64;
4080 println!("IV = {}", iv);
4081 let mut cipher1 = Vec::<u8>::new();
4082 let mut cipher2 = Vec::<u8>::new();
4083 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
4084 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
4085 print!("C (0 rounds) =\t");
4086 for c in cipher1.clone()
4087 { print!("{:02X} ", c); }
4088 println!();
4089 let mut txt = String::new();
4090 for c in cipher1.clone()
4091 { write!(txt, "{:02X} ", c); }
4092 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
4093 print!("D (0 rounds) =\t");
4094 for c in cipher2.clone()
4095 { print!("{:02X} ", c); }
4096 println!();
4097 let mut txt = String::new();
4098 for c in cipher2.clone()
4099 { write!(txt, "{:02X} ", c); }
4100 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
4101
4102 let mut recovered1 = String::new();
4103 let mut recovered2 = String::new();
4104 c_des.decrypt_into_string(iv, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
4105 d_des.decrypt_into_string(iv, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
4106 println!("B1 (0 rounds) =\t{}", recovered1);
4107 println!("B2 (0 rounds) =\t{}", recovered2);
4108 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
4109 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
4110 assert_eq!(recovered1, message);
4111 assert_eq!(recovered2, message);
4112 assert_eq!(recovered1, recovered2);
4113 println!();
4114
4115 // Normal case for the message of 0 bytes
4116 let key = 0x_1234567890ABCDEF_u64;
4117 println!("K =\t{:#016X}", key);
4118 let mut a_des = DES::new_with_key_u64(key);
4119
4120 let message = "";
4121 println!("M =\t{}", message);
4122 let iv = 0x_FEDCBA0987654321_u64;
4123 println!("IV = {}", iv);
4124 let mut cipher = Vec::<u8>::new();
4125 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4126 print!("C =\t");
4127 for c in cipher.clone()
4128 { print!("{:02X} ", c); }
4129 println!();
4130 let mut txt = String::new();
4131 for c in cipher.clone()
4132 { write!(txt, "{:02X} ", c); }
4133 assert_eq!(txt, "");
4134
4135 let mut recovered = String::new();
4136 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4137 println!("B =\t{}", recovered);
4138 assert_eq!(recovered, "");
4139 assert_eq!(recovered, message);
4140 println!();
4141
4142 // Normal case for the message shorter than 8 bytes
4143 let key = 0x_1234567890ABCDEF_u64;
4144 println!("K =\t{:#016X}", key);
4145 let mut a_des = DES::new_with_key_u64(key);
4146
4147 let message = "7 bytes";
4148 println!("M =\t{}", message);
4149 let iv = 0x_FEDCBA0987654321_u64;
4150 println!("IV = {}", iv);
4151 let mut cipher = Vec::<u8>::new();
4152 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4153 print!("C =\t");
4154 for c in cipher.clone()
4155 { print!("{:02X} ", c); }
4156 println!();
4157 let mut txt = String::new();
4158 for c in cipher.clone()
4159 { write!(txt, "{:02X} ", c); }
4160 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
4161
4162 let mut recovered = String::new();
4163 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4164 println!("B =\t{}", recovered);
4165 assert_eq!(recovered, "7 bytes");
4166 assert_eq!(recovered, message);
4167 println!();
4168
4169 // Normal case for the message of 8 bytes
4170 let key = 0x_1234567890ABCDEF_u64;
4171 println!("K =\t{:#016X}", key);
4172 let mut a_des = DES::new_with_key_u64(key);
4173
4174 let message = "I am OK.";
4175 println!("M =\t{}", message);
4176 let iv = 0x_FEDCBA0987654321_u64;
4177 println!("IV = {}", iv);
4178 let mut cipher = Vec::<u8>::new();
4179 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4180 print!("C =\t");
4181 for c in cipher.clone()
4182 { print!("{:02X} ", c); }
4183 println!();
4184 let mut txt = String::new();
4185 for c in cipher.clone()
4186 { write!(txt, "{:02X} ", c); }
4187 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
4188
4189 let mut recovered = String::new();
4190 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4191 println!("B =\t{}", recovered);
4192 assert_eq!(recovered, "I am OK.");
4193 assert_eq!(recovered, message);
4194 println!();
4195
4196 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4197 let key = 0x_1234567890ABCDEF_u64;
4198 println!("K =\t{:#016X}", key);
4199 let mut a_des = DES::new_with_key_u64(key);
4200
4201 let message = "PARK Youngho";
4202 println!("M =\t{}", message);
4203 let iv = 0x_FEDCBA0987654321_u64;
4204 println!("IV = {}", iv);
4205 let mut cipher = Vec::<u8>::new();
4206 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4207 print!("C =\t");
4208 for c in cipher.clone()
4209 { print!("{:02X} ", c); }
4210 println!();
4211 let mut txt = String::new();
4212 for c in cipher.clone()
4213 { write!(txt, "{:02X} ", c); }
4214 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
4215
4216 let mut recovered = String::new();
4217 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4218 println!("B =\t{}", recovered);
4219 assert_eq!(recovered, "PARK Youngho");
4220 assert_eq!(recovered, message);
4221 println!();
4222
4223 // Normal case for the message of 16 bytes
4224 let key = 0x_1234567890ABCDEF_u64;
4225 println!("K =\t{:#016X}", key);
4226 let mut a_des = DES::new_with_key_u64(key);
4227
4228 let message = "고맙습니다.";
4229 println!("M =\t{}", message);
4230 let iv = 0x_FEDCBA0987654321_u64;
4231 println!("IV = {}", iv);
4232 let mut cipher = Vec::<u8>::new();
4233 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4234 print!("C =\t");
4235 for c in cipher.clone()
4236 { print!("{:02X} ", c); }
4237 println!();
4238 let mut txt = String::new();
4239 for c in cipher.clone()
4240 { write!(txt, "{:02X} ", c); }
4241 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
4242
4243 let mut recovered = String::new();
4244 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4245 println!("B =\t{}", recovered);
4246 assert_eq!(recovered, "고맙습니다.");
4247 assert_eq!(recovered, message);
4248 println!("-------------------------------");
4249}
4250
4251fn des_decrypt_vec_cfb()
4252{
4253 println!("des_decrypt_vec_cfb()");
4254 use std::io::Write;
4255 use std::fmt::Write as _;
4256 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
4257
4258 // Normal case
4259 let key = 0x_1234567890ABCDEF_u64;
4260 println!("K =\t{:#016X}", key);
4261 let mut a_des = DES::new_with_key_u64(key);
4262
4263 let message = "In the beginning God created the heavens and the earth.";
4264 println!("M =\t{}", message);
4265 let iv = 0x_FEDCBA0987654321_u64;
4266 println!("IV = {}", iv);
4267 let mut cipher = Vec::<u8>::new();
4268 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4269 print!("C (16 rounds) =\t");
4270 for c in cipher.clone()
4271 { print!("{:02X} ", c); }
4272 println!();
4273 let mut txt = String::new();
4274 for c in cipher.clone()
4275 { write!(txt, "{:02X} ", c); }
4276 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
4277
4278 let mut recovered = vec![0; 55];
4279 a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4280 print!("Ba (16 rounds) =\t");
4281 for b in recovered.clone()
4282 { print!("{:02X} ", b); }
4283 println!();
4284 let mut txt = String::new();
4285 for c in recovered.clone()
4286 { write!(txt, "{:02X} ", c); }
4287 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4288
4289 let mut converted = String::new();
4290 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4291
4292 println!("Bb (16 rounds) =\t{}", converted);
4293 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4294 assert_eq!(converted, message);
4295 println!();
4296
4297 // Expanded case for 128 rounds
4298 let key = 0x_1234567890ABCDEF_u64;
4299 println!("K =\t{:#016X}", key);
4300 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4301
4302 let message = "In the beginning God created the heavens and the earth.";
4303 println!("M =\t{}", message);
4304 let iv = 0x_FEDCBA0987654321_u64;
4305 println!("IV = {}", iv);
4306 let mut cipher = Vec::<u8>::new();
4307 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4308 print!("C (128 rounds) =\t");
4309 for c in cipher.clone()
4310 { print!("{:02X} ", c); }
4311 println!();
4312 let mut txt = String::new();
4313 for c in cipher.clone()
4314 { write!(txt, "{:02X} ", c); }
4315 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
4316
4317 let mut recovered = vec![0; 55];
4318 a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4319 print!("Ba (128 rounds) =\t");
4320 for b in recovered.clone()
4321 { print!("{:02X} ", b); }
4322 println!();
4323 let mut txt = String::new();
4324 for c in recovered.clone()
4325 { write!(txt, "{:02X} ", c); }
4326 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4327
4328 let mut converted = String::new();
4329 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4330
4331 println!("Bb (128 rounds) =\t{}", converted);
4332 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4333 assert_eq!(converted, message);
4334 println!();
4335
4336 // Expanded case for 0 rounds which means that key is meaningless
4337 let key1 = 0x_1234567890ABCDEF_u64;
4338 let key2 = 0_u64;
4339 println!("K =\t{:#016X}", key);
4340 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4341 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4342
4343 let message = "In the beginning God created the heavens and the earth.";
4344 println!("M =\t{}", message);
4345 let iv = 0x_FEDCBA0987654321_u64;
4346 println!("IV = {}", iv);
4347 let mut cipher1 = Vec::<u8>::new();
4348 let mut cipher2 = Vec::<u8>::new();
4349 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
4350 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
4351 print!("C (0 rounds) =\t");
4352 for c in cipher1.clone()
4353 { print!("{:02X} ", c); }
4354 println!();
4355 let mut txt = String::new();
4356 for c in cipher1.clone()
4357 { write!(txt, "{:02X} ", c); }
4358 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
4359 print!("D (0 rounds) =\t");
4360 for c in cipher2.clone()
4361 { print!("{:02X} ", c); }
4362 println!();
4363 let mut txt = String::new();
4364 for c in cipher2.clone()
4365 { write!(txt, "{:02X} ", c); }
4366 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
4367
4368 let mut recovered1 = vec![0; 55];
4369 let mut recovered2 = vec![0; 55];
4370 c_des.decrypt_vec(iv, &cipher1, recovered1.as_mut_ptr());
4371 d_des.decrypt_vec(iv, &cipher2, recovered2.as_mut_ptr());
4372 print!("B1a (0 rounds) =\t");
4373 for b in recovered1.clone()
4374 { print!("{:02X} ", b); }
4375 println!();
4376 let mut txt = String::new();
4377 for c in recovered1.clone()
4378 { write!(txt, "{:02X} ", c); }
4379 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4380 print!("B2a (0 rounds) =\t");
4381 for b in recovered2.clone()
4382 { print!("{:02X} ", b); }
4383 println!();
4384 let mut txt = String::new();
4385 for c in recovered2.clone()
4386 { write!(txt, "{:02X} ", c); }
4387 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4388
4389 let mut converted1 = String::new();
4390 let mut converted2 = String::new();
4391 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4392 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4393
4394 println!("B1b (0 rounds) =\t{}", converted1);
4395 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4396 assert_eq!(converted1, message);
4397 println!("B2b (0 rounds) =\t{}", converted2);
4398 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4399 assert_eq!(converted2, message);
4400 assert_eq!(converted1, converted1);
4401 println!();
4402
4403 // Normal case for the message of 0 bytes
4404 let key = 0x_1234567890ABCDEF_u64;
4405 println!("K =\t{:#016X}", key);
4406 let mut a_des = DES::new_with_key_u64(key);
4407
4408 let message = "";
4409 println!("M =\t{}", message);
4410 let iv = 0x_FEDCBA0987654321_u64;
4411 println!("IV = {}", iv);
4412 let mut cipher = Vec::<u8>::new();
4413 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4414 print!("C =\t");
4415 for c in cipher.clone()
4416 { print!("{:02X} ", c); }
4417 println!();
4418 let mut txt = String::new();
4419 for c in cipher.clone()
4420 { write!(txt, "{:02X} ", c); }
4421 assert_eq!(txt, "");
4422
4423 let mut recovered = vec![0; 8];
4424 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4425 print!("Ba =\t");
4426 for b in recovered.clone()
4427 { print!("{:02X} ", b); }
4428 println!();
4429 let mut txt = String::new();
4430 for c in recovered.clone()
4431 { write!(txt, "{:02X} ", c); }
4432 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4433
4434 let mut converted = String::new();
4435 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4436 converted.truncate(len as usize);
4437
4438 println!("Bb =\t{}", converted);
4439 assert_eq!(converted, "");
4440 assert_eq!(converted, message);
4441 println!();
4442
4443 // Normal case for the message shorter than 8 bytes
4444 let key = 0x_1234567890ABCDEF_u64;
4445 println!("K =\t{:#016X}", key);
4446 let mut a_des = DES::new_with_key_u64(key);
4447
4448 let message = "7 bytes";
4449 println!("M =\t{}", message);
4450 let iv = 0x_FEDCBA0987654321_u64;
4451 println!("IV = {}", iv);
4452 let mut cipher = Vec::<u8>::new();
4453 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4454 print!("C =\t");
4455 for c in cipher.clone()
4456 { print!("{:02X} ", c); }
4457 println!();
4458 let mut txt = String::new();
4459 for c in cipher.clone()
4460 { write!(txt, "{:02X} ", c); }
4461 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
4462
4463 let mut recovered = vec![0; 8];
4464 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4465 print!("Ba =\t");
4466 for b in recovered.clone()
4467 { print!("{:02X} ", b); }
4468 println!();
4469 let mut txt = String::new();
4470 for c in recovered.clone()
4471 { write!(txt, "{:02X} ", c); }
4472 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4473
4474 let mut converted = String::new();
4475 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4476 converted.truncate(len as usize);
4477
4478 println!("Bb =\t{}", converted);
4479 assert_eq!(converted, "7 bytes");
4480 assert_eq!(converted, message);
4481 println!();
4482
4483 // Normal case for the message of 8 bytes
4484 let key = 0x_1234567890ABCDEF_u64;
4485 println!("K =\t{:#016X}", key);
4486 let mut a_des = DES::new_with_key_u64(key);
4487
4488 let message = "I am OK.";
4489 println!("M =\t{}", message);
4490 let iv = 0x_FEDCBA0987654321_u64;
4491 println!("IV = {}", iv);
4492 let mut cipher = Vec::<u8>::new();
4493 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4494 print!("C =\t");
4495 for c in cipher.clone()
4496 { print!("{:02X} ", c); }
4497 println!();
4498 let mut txt = String::new();
4499 for c in cipher.clone()
4500 { write!(txt, "{:02X} ", c); }
4501 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
4502
4503 let mut recovered = vec![0; 16];
4504 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4505 print!("Ba =\t");
4506 for b in recovered.clone()
4507 { print!("{:02X} ", b); }
4508 println!();
4509 let mut txt = String::new();
4510 for c in recovered.clone()
4511 { write!(txt, "{:02X} ", c); }
4512 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4513
4514 let mut converted = String::new();
4515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4516 converted.truncate(len as usize);
4517
4518 println!("Bb =\t{}", converted);
4519 assert_eq!(converted, "I am OK.");
4520 assert_eq!(converted, message);
4521 println!();
4522
4523 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4524 let key = 0x_1234567890ABCDEF_u64;
4525 println!("K =\t{:#016X}", key);
4526 let mut a_des = DES::new_with_key_u64(key);
4527
4528 let message = "PARK Youngho";
4529 println!("M =\t{}", message);
4530 let iv = 0x_FEDCBA0987654321_u64;
4531 println!("IV = {}", iv);
4532 let mut cipher = Vec::<u8>::new();
4533 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4534 print!("C =\t");
4535 for c in cipher.clone()
4536 { print!("{:02X} ", c); }
4537 println!();
4538 let mut txt = String::new();
4539 for c in cipher.clone()
4540 { write!(txt, "{:02X} ", c); }
4541 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
4542
4543 let mut recovered = vec![0; 16];
4544 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4545 print!("Ba =\t");
4546 for b in recovered.clone()
4547 { print!("{:02X} ", b); }
4548 println!();
4549 let mut txt = String::new();
4550 for c in recovered.clone()
4551 { write!(txt, "{:02X} ", c); }
4552 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4553
4554 let mut converted = String::new();
4555 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4556 converted.truncate(len as usize);
4557
4558 println!("Bb =\t{}", converted);
4559 assert_eq!(converted, "PARK Youngho");
4560 assert_eq!(converted, message);
4561 println!();
4562
4563 // Normal case for the message of 16 bytes
4564 let key = 0x_1234567890ABCDEF_u64;
4565 println!("K =\t{:#016X}", key);
4566 let mut a_des = DES::new_with_key_u64(key);
4567
4568 let message = "고맙습니다.";
4569 println!("M =\t{}", message);
4570 let iv = 0x_FEDCBA0987654321_u64;
4571 println!("IV = {}", iv);
4572 let mut cipher = Vec::<u8>::new();
4573 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4574 print!("C =\t");
4575 for c in cipher.clone()
4576 { print!("{:02X} ", c); }
4577 println!();
4578 let mut txt = String::new();
4579 for c in cipher.clone()
4580 { write!(txt, "{:02X} ", c); }
4581 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
4582
4583 let mut recovered = vec![0; 24];
4584 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4585 print!("Ba =\t");
4586 for b in recovered.clone()
4587 { print!("{:02X} ", b); }
4588 println!();
4589 let mut txt = String::new();
4590 for c in recovered.clone()
4591 { write!(txt, "{:02X} ", c); }
4592 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4593
4594 let mut converted = String::new();
4595 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4596 converted.truncate(len as usize);
4597
4598 println!("Bb =\t{}", converted);
4599 assert_eq!(converted, "고맙습니다.");
4600 assert_eq!(converted, message);
4601 println!("-------------------------------");
4602}
4603
4604fn des_decrypt_vec_cfb_into_vec()
4605{
4606 println!("des_decrypt_vec_cfb_into_vec()");
4607 use std::io::Write;
4608 use std::fmt::Write as _;
4609 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
4610
4611 // Normal case
4612 let key = 0x_1234567890ABCDEF_u64;
4613 println!("K =\t{:#016X}", key);
4614 let mut a_des = DES::new_with_key_u64(key);
4615
4616 let message = "In the beginning God created the heavens and the earth.";
4617 println!("M =\t{}", message);
4618 let iv = 0x_FEDCBA0987654321_u64;
4619 println!("IV = {}", iv);
4620 let mut cipher = Vec::<u8>::new();
4621 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4622 print!("C (16 rounds) =\t");
4623 for c in cipher.clone()
4624 { print!("{:02X} ", c); }
4625 println!();
4626 let mut txt = String::new();
4627 for c in cipher.clone()
4628 { write!(txt, "{:02X} ", c); }
4629 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
4630
4631 let mut recovered = Vec::<u8>::new();
4632 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4633 print!("Ba (16 rounds) =\t");
4634 for b in recovered.clone()
4635 { print!("{:02X} ", b); }
4636 println!();
4637 let mut txt = String::new();
4638 for c in recovered.clone()
4639 { write!(txt, "{:02X} ", c); }
4640 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4641
4642 let mut converted = String::new();
4643 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4644
4645 println!("Bb (16 rounds) =\t{}", converted);
4646 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4647 assert_eq!(converted, message);
4648 println!();
4649
4650 // Expanded case for 128 rounds
4651 let key = 0x_1234567890ABCDEF_u64;
4652 println!("K =\t{:#016X}", key);
4653 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4654
4655 let message = "In the beginning God created the heavens and the earth.";
4656 println!("M =\t{}", message);
4657 let iv = 0x_FEDCBA0987654321_u64;
4658 println!("IV = {}", iv);
4659 let mut cipher = Vec::<u8>::new();
4660 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4661 print!("C (128 rounds) =\t");
4662 for c in cipher.clone()
4663 { print!("{:02X} ", c); }
4664 println!();
4665 let mut txt = String::new();
4666 for c in cipher.clone()
4667 { write!(txt, "{:02X} ", c); }
4668 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
4669
4670 let mut recovered = Vec::<u8>::new();
4671 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4672 print!("Ba (128 rounds) =\t");
4673 for b in recovered.clone()
4674 { print!("{:02X} ", b); }
4675 println!();
4676 let mut txt = String::new();
4677 for c in recovered.clone()
4678 { write!(txt, "{:02X} ", c); }
4679 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4680
4681 let mut converted = String::new();
4682 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4683
4684 println!("Bb (128 rounds) =\t{}", converted);
4685 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4686 assert_eq!(converted, message);
4687 println!();
4688
4689 // Expanded case for 0 rounds which means that key is meaningless
4690 let key1 = 0x_1234567890ABCDEF_u64;
4691 let key2 = 0_u64;
4692 println!("K =\t{:#016X}", key);
4693 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4694 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4695
4696 let message = "In the beginning God created the heavens and the earth.";
4697 println!("M =\t{}", message);
4698 let iv = 0x_FEDCBA0987654321_u64;
4699 println!("IV = {}", iv);
4700 let mut cipher1 = Vec::<u8>::new();
4701 let mut cipher2 = Vec::<u8>::new();
4702 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
4703 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
4704 print!("C (0 rounds) =\t");
4705 for c in cipher1.clone()
4706 { print!("{:02X} ", c); }
4707 println!();
4708 let mut txt = String::new();
4709 for c in cipher1.clone()
4710 { write!(txt, "{:02X} ", c); }
4711 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
4712 print!("D (0 rounds) =\t");
4713 for c in cipher2.clone()
4714 { print!("{:02X} ", c); }
4715 println!();
4716 let mut txt = String::new();
4717 for c in cipher2.clone()
4718 { write!(txt, "{:02X} ", c); }
4719 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
4720
4721 let mut recovered1 = Vec::<u8>::new();
4722 let mut recovered2 = Vec::<u8>::new();
4723 c_des.decrypt_vec_into_vec(iv, &cipher1, &mut recovered1);
4724 d_des.decrypt_vec_into_vec(iv, &cipher2, &mut recovered2);
4725 print!("B1a (0 rounds) =\t");
4726 for b in recovered1.clone()
4727 { print!("{:02X} ", b); }
4728 println!();
4729 let mut txt = String::new();
4730 for c in recovered1.clone()
4731 { write!(txt, "{:02X} ", c); }
4732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4733 print!("B2a (0 rounds) =\t");
4734 for b in recovered2.clone()
4735 { print!("{:02X} ", b); }
4736 println!();
4737 let mut txt = String::new();
4738 for c in recovered2.clone()
4739 { write!(txt, "{:02X} ", c); }
4740 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4741
4742 let mut converted1 = String::new();
4743 let mut converted2 = String::new();
4744 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4745 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4746
4747 println!("B1b (0 rounds) =\t{}", converted1);
4748 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4749 assert_eq!(converted1, message);
4750 println!("B2b (0 rounds) =\t{}", converted2);
4751 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4752 assert_eq!(converted2, message);
4753 assert_eq!(converted1, converted1);
4754 println!();
4755
4756 // Normal case for the message of 0 bytes
4757 let key = 0x_1234567890ABCDEF_u64;
4758 println!("K =\t{:#016X}", key);
4759 let mut a_des = DES::new_with_key_u64(key);
4760
4761 let message = "";
4762 println!("M =\t{}", message);
4763 let iv = 0x_FEDCBA0987654321_u64;
4764 println!("IV = {}", iv);
4765 let mut cipher = Vec::<u8>::new();
4766 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4767 print!("C =\t");
4768 for c in cipher.clone()
4769 { print!("{:02X} ", c); }
4770 println!();
4771 let mut txt = String::new();
4772 for c in cipher.clone()
4773 { write!(txt, "{:02X} ", c); }
4774 assert_eq!(txt, "");
4775
4776 let mut recovered = Vec::<u8>::new();
4777 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4778 print!("Ba =\t");
4779 for b in recovered.clone()
4780 { print!("{:02X} ", b); }
4781 println!();
4782 let mut txt = String::new();
4783 for c in recovered.clone()
4784 { write!(txt, "{:02X} ", c); }
4785 assert_eq!(txt, "");
4786
4787 let mut converted = String::new();
4788 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4789
4790 println!("Bb =\t{}", converted);
4791 assert_eq!(converted, "");
4792 assert_eq!(converted, message);
4793 println!();
4794
4795 // Normal case for the message shorter than 8 bytes
4796 let key = 0x_1234567890ABCDEF_u64;
4797 println!("K =\t{:#016X}", key);
4798 let mut a_des = DES::new_with_key_u64(key);
4799
4800 let message = "7 bytes";
4801 println!("M =\t{}", message);
4802 let iv = 0x_FEDCBA0987654321_u64;
4803 println!("IV = {}", iv);
4804 let mut cipher = Vec::<u8>::new();
4805 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4806 print!("C =\t");
4807 for c in cipher.clone()
4808 { print!("{:02X} ", c); }
4809 println!();
4810 let mut txt = String::new();
4811 for c in cipher.clone()
4812 { write!(txt, "{:02X} ", c); }
4813 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
4814
4815 let mut recovered = Vec::<u8>::new();
4816 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4817 print!("Ba =\t");
4818 for b in recovered.clone()
4819 { print!("{:02X} ", b); }
4820 println!();
4821 let mut txt = String::new();
4822 for c in recovered.clone()
4823 { write!(txt, "{:02X} ", c); }
4824 assert_eq!(txt, "37 20 62 79 74 65 73 ");
4825
4826 let mut converted = String::new();
4827 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4828
4829 println!("Bb =\t{}", converted);
4830 assert_eq!(converted, "7 bytes");
4831 assert_eq!(converted, message);
4832 println!();
4833
4834 // Normal case for the message of 8 bytes
4835 let key = 0x_1234567890ABCDEF_u64;
4836 println!("K =\t{:#016X}", key);
4837 let mut a_des = DES::new_with_key_u64(key);
4838
4839 let message = "I am OK.";
4840 println!("M =\t{}", message);
4841 let iv = 0x_FEDCBA0987654321_u64;
4842 println!("IV = {}", iv);
4843 let mut cipher = Vec::<u8>::new();
4844 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4845 print!("C =\t");
4846 for c in cipher.clone()
4847 { print!("{:02X} ", c); }
4848 println!();
4849 let mut txt = String::new();
4850 for c in cipher.clone()
4851 { write!(txt, "{:02X} ", c); }
4852 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
4853
4854 let mut recovered = Vec::<u8>::new();
4855 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4856 print!("Ba =\t");
4857 for b in recovered.clone()
4858 { print!("{:02X} ", b); }
4859 println!();
4860 let mut txt = String::new();
4861 for c in recovered.clone()
4862 { write!(txt, "{:02X} ", c); }
4863 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4864
4865 let mut converted = String::new();
4866 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4867
4868 println!("Bb =\t{}", converted);
4869 assert_eq!(converted, "I am OK.");
4870 assert_eq!(converted, message);
4871 println!();
4872
4873 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4874 let key = 0x_1234567890ABCDEF_u64;
4875 println!("K =\t{:#016X}", key);
4876 let mut a_des = DES::new_with_key_u64(key);
4877
4878 let message = "PARK Youngho";
4879 println!("M =\t{}", message);
4880 let iv = 0x_FEDCBA0987654321_u64;
4881 println!("IV = {}", iv);
4882 let mut cipher = Vec::<u8>::new();
4883 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4884 print!("C =\t");
4885 for c in cipher.clone()
4886 { print!("{:02X} ", c); }
4887 println!();
4888 let mut txt = String::new();
4889 for c in cipher.clone()
4890 { write!(txt, "{:02X} ", c); }
4891 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
4892
4893 let mut recovered = Vec::<u8>::new();
4894 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4895 print!("Ba =\t");
4896 for b in recovered.clone()
4897 { print!("{:02X} ", b); }
4898 println!();
4899 let mut txt = String::new();
4900 for c in recovered.clone()
4901 { write!(txt, "{:02X} ", c); }
4902 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4903
4904 let mut converted = String::new();
4905 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4906
4907 println!("Bb =\t{}", converted);
4908 assert_eq!(converted, "PARK Youngho");
4909 assert_eq!(converted, message);
4910 println!();
4911
4912 // Normal case for the message of 16 bytes
4913 let key = 0x_1234567890ABCDEF_u64;
4914 println!("K =\t{:#016X}", key);
4915 let mut a_des = DES::new_with_key_u64(key);
4916
4917 let message = "고맙습니다.";
4918 println!("M =\t{}", message);
4919 let iv = 0x_FEDCBA0987654321_u64;
4920 println!("IV = {}", iv);
4921 let mut cipher = Vec::<u8>::new();
4922 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4923 print!("C =\t");
4924 for c in cipher.clone()
4925 { print!("{:02X} ", c); }
4926 println!();
4927 let mut txt = String::new();
4928 for c in cipher.clone()
4929 { write!(txt, "{:02X} ", c); }
4930 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
4931
4932 let mut recovered = Vec::<u8>::new();
4933 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4934 print!("Ba =\t");
4935 for b in recovered.clone()
4936 { print!("{:02X} ", b); }
4937 println!();
4938 let mut txt = String::new();
4939 for c in recovered.clone()
4940 { write!(txt, "{:02X} ", c); }
4941 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4942
4943 let mut converted = String::new();
4944 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4945
4946 println!("Bb =\t{}", converted);
4947 assert_eq!(converted, "고맙습니다.");
4948 assert_eq!(converted, message);
4949 println!("-------------------------------");
4950}
4951
4952fn des_decrypt_vec_cfb_into_array()
4953{
4954 println!("des_decrypt_vec_cfb_into_array()");
4955 use std::io::Write;
4956 use std::fmt::Write as _;
4957 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
4958
4959 // Normal case
4960 let key = 0x_1234567890ABCDEF_u64;
4961 println!("K =\t{:#016X}", key);
4962 let mut a_des = DES::new_with_key_u64(key);
4963
4964 let message = "In the beginning God created the heavens and the earth.";
4965 println!("M =\t{}", message);
4966 let iv = 0x_FEDCBA0987654321_u64;
4967 println!("IV = {}", iv);
4968 let mut cipher = Vec::<u8>::new();
4969 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4970 print!("C (16 rounds) =\t");
4971 for c in cipher.clone()
4972 { print!("{:02X} ", c); }
4973 println!();
4974 let mut txt = String::new();
4975 for c in cipher.clone()
4976 { write!(txt, "{:02X} ", c); }
4977 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
4978
4979 let mut recovered = [0u8; 56];
4980 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
4981 print!("Ba (16 rounds) =\t");
4982 for b in recovered.clone()
4983 { print!("{:02X} ", b); }
4984 println!();
4985 let mut txt = String::new();
4986 for c in recovered.clone()
4987 { write!(txt, "{:02X} ", c); }
4988 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4989
4990 let mut converted = String::new();
4991 unsafe { converted.as_mut_vec() }.write(&recovered);
4992 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4993 println!("Bb (16 rounds) =\t{}", converted);
4994 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4995 assert_eq!(converted, message);
4996 println!();
4997
4998 // Expanded case for 128 rounds
4999 let key = 0x_1234567890ABCDEF_u64;
5000 println!("K =\t{:#016X}", key);
5001 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5002
5003 let message = "In the beginning God created the heavens and the earth.";
5004 println!("M =\t{}", message);
5005 let iv = 0x_FEDCBA0987654321_u64;
5006 println!("IV = {}", iv);
5007 let mut cipher = Vec::<u8>::new();
5008 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5009 print!("C (128 rounds) =\t");
5010 for c in cipher.clone()
5011 { print!("{:02X} ", c); }
5012 println!();
5013 let mut txt = String::new();
5014 for c in cipher.clone()
5015 { write!(txt, "{:02X} ", c); }
5016 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
5017
5018 let mut recovered = [0u8; 56];
5019 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5020 print!("Ba (16 rounds) =\t");
5021 for b in recovered.clone()
5022 { print!("{:02X} ", b); }
5023 println!();
5024 let mut txt = String::new();
5025 for c in recovered.clone()
5026 { write!(txt, "{:02X} ", c); }
5027 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5028
5029 let mut converted = String::new();
5030 unsafe { converted.as_mut_vec() }.write(&recovered);
5031 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5032 println!("Bb (16 rounds) =\t{}", converted);
5033 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5034 assert_eq!(converted, message);
5035 println!();
5036
5037 // Expanded case for 0 rounds which means that key is meaningless
5038 let key1 = 0x_1234567890ABCDEF_u64;
5039 let key2 = 0_u64;
5040 println!("K =\t{:#016X}", key);
5041 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5042 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5043
5044 let message = "In the beginning God created the heavens and the earth.";
5045 println!("M =\t{}", message);
5046 let iv = 0x_FEDCBA0987654321_u64;
5047 println!("IV = {}", iv);
5048 let mut cipher1 = Vec::<u8>::new();
5049 let mut cipher2 = Vec::<u8>::new();
5050 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
5051 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
5052 print!("C (0 rounds) =\t");
5053 for c in cipher1.clone()
5054 { print!("{:02X} ", c); }
5055 println!();
5056 let mut txt = String::new();
5057 for c in cipher1.clone()
5058 { write!(txt, "{:02X} ", c); }
5059 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
5060 print!("D (0 rounds) =\t");
5061 for c in cipher2.clone()
5062 { print!("{:02X} ", c); }
5063 println!();
5064 let mut txt = String::new();
5065 for c in cipher2.clone()
5066 { write!(txt, "{:02X} ", c); }
5067 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
5068
5069 let mut recovered1 = [0u8; 56];
5070 let mut recovered2 = [0u8; 56];
5071 let len1 = c_des.decrypt_vec_into_array(iv, &cipher1, &mut recovered1);
5072 let len2 = d_des.decrypt_vec_into_array(iv, &cipher2, &mut recovered2);
5073 print!("B1a (0 rounds) =\t");
5074 for b in recovered1.clone()
5075 { print!("{:02X} ", b); }
5076 println!();
5077 let mut txt = String::new();
5078 for c in recovered1.clone()
5079 { write!(txt, "{:02X} ", c); }
5080 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5081 print!("B2a (0 rounds) =\t");
5082 for b in recovered2.clone()
5083 { print!("{:02X} ", b); }
5084 println!();
5085 let mut txt = String::new();
5086 for c in recovered.clone()
5087 { write!(txt, "{:02X} ", c); }
5088 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5089
5090 let mut converted1 = String::new();
5091 let mut converted2 = String::new();
5092 unsafe { converted1.as_mut_vec() }.write(&recovered1);
5093 unsafe { converted2.as_mut_vec() }.write(&recovered2);
5094 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
5095 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
5096 println!("B1b (0 rounds) =\t{}", converted1);
5097 println!("B2b (0 rounds) =\t{}", converted2);
5098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5099 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5100 assert_eq!(converted1, message);
5101 assert_eq!(converted2, message);
5102 assert_eq!(converted1, converted2);
5103 println!();
5104
5105 // Normal case for the message of 0 bytes
5106 let key = 0x_1234567890ABCDEF_u64;
5107 println!("K =\t{:#016X}", key);
5108 let mut a_des = DES::new_with_key_u64(key);
5109
5110 let message = "";
5111 println!("M =\t{}", message);
5112 let iv = 0x_FEDCBA0987654321_u64;
5113 println!("IV = {}", iv);
5114 let mut cipher = Vec::<u8>::new();
5115 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5116 print!("C =\t");
5117 for c in cipher.clone()
5118 { print!("{:02X} ", c); }
5119 println!();
5120 let mut txt = String::new();
5121 for c in cipher.clone()
5122 { write!(txt, "{:02X} ", c); }
5123 assert_eq!(txt, "");
5124
5125 let mut recovered = [0u8; 8];
5126 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5127
5128 print!("Ba =\t");
5129 for b in recovered.clone()
5130 { print!("{:02X} ", b); }
5131 println!();
5132 let mut txt = String::new();
5133 for c in recovered.clone()
5134 { write!(txt, "{:02X} ", c); }
5135 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
5136
5137 let mut converted = String::new();
5138 unsafe { converted.as_mut_vec() }.write(&recovered);
5139 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5140 println!("Bb =\t{}", converted);
5141 assert_eq!(converted, "");
5142 assert_eq!(converted, message);
5143 println!();
5144
5145 // Normal case for the message shorter than 8 bytes
5146 let key = 0x_1234567890ABCDEF_u64;
5147 println!("K =\t{:#016X}", key);
5148 let mut a_des = DES::new_with_key_u64(key);
5149
5150 let message = "7 bytes";
5151 println!("M =\t{}", message);
5152 let iv = 0x_FEDCBA0987654321_u64;
5153 println!("IV = {}", iv);
5154 let mut cipher = Vec::<u8>::new();
5155 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5156 print!("C =\t");
5157 for c in cipher.clone()
5158 { print!("{:02X} ", c); }
5159 println!();
5160 let mut txt = String::new();
5161 for c in cipher.clone()
5162 { write!(txt, "{:02X} ", c); }
5163 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
5164
5165 let mut recovered = [0u8; 8];
5166 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5167
5168 print!("Ba =\t");
5169 for b in recovered.clone()
5170 { print!("{:02X} ", b); }
5171 println!();
5172 let mut txt = String::new();
5173 for c in recovered.clone()
5174 { write!(txt, "{:02X} ", c); }
5175 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
5176
5177 let mut converted = String::new();
5178 unsafe { converted.as_mut_vec() }.write(&recovered);
5179 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5180 println!("Bb =\t{}", converted);
5181 assert_eq!(converted, "7 bytes");
5182 assert_eq!(converted, message);
5183 println!();
5184
5185 // Normal case for the message of 8 bytes
5186 let key = 0x_1234567890ABCDEF_u64;
5187 println!("K =\t{:#016X}", key);
5188 let mut a_des = DES::new_with_key_u64(key);
5189
5190 let message = "I am OK.";
5191 println!("M =\t{}", message);
5192 let iv = 0x_FEDCBA0987654321_u64;
5193 println!("IV = {}", iv);
5194 let mut cipher = Vec::<u8>::new();
5195 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5196 print!("C =\t");
5197 for c in cipher.clone()
5198 { print!("{:02X} ", c); }
5199 println!();
5200 let mut txt = String::new();
5201 for c in cipher.clone()
5202 { write!(txt, "{:02X} ", c); }
5203 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
5204
5205 let mut recovered = [0u8; 16];
5206 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5207
5208 print!("Ba =\t");
5209 for b in recovered.clone()
5210 { print!("{:02X} ", b); }
5211 println!();
5212 let mut txt = String::new();
5213 for c in recovered.clone()
5214 { write!(txt, "{:02X} ", c); }
5215 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
5216
5217 let mut converted = String::new();
5218 unsafe { converted.as_mut_vec() }.write(&recovered);
5219 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5220 println!("Bb =\t{}", converted);
5221 assert_eq!(converted, "I am OK.");
5222 assert_eq!(converted, message);
5223 println!();
5224
5225 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5226 let key = 0x_1234567890ABCDEF_u64;
5227 println!("K =\t{:#016X}", key);
5228 let mut a_des = DES::new_with_key_u64(key);
5229
5230 let message = "PARK Youngho";
5231 println!("M =\t{}", message);
5232 let iv = 0x_FEDCBA0987654321_u64;
5233 println!("IV = {}", iv);
5234 let mut cipher = Vec::<u8>::new();
5235 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5236 print!("C =\t");
5237 for c in cipher.clone()
5238 { print!("{:02X} ", c); }
5239 println!();
5240 let mut txt = String::new();
5241 for c in cipher.clone()
5242 { write!(txt, "{:02X} ", c); }
5243 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
5244
5245 let mut recovered = [0u8; 16];
5246 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5247
5248 print!("Ba =\t");
5249 for b in recovered.clone()
5250 { print!("{:02X} ", b); }
5251 println!();
5252 let mut txt = String::new();
5253 for c in recovered.clone()
5254 { write!(txt, "{:02X} ", c); }
5255 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
5256
5257 let mut converted = String::new();
5258 unsafe { converted.as_mut_vec() }.write(&recovered);
5259 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5260 println!("Bb =\t{}", converted);
5261 assert_eq!(converted, "PARK Youngho");
5262 assert_eq!(converted, message);
5263 println!();
5264
5265 // Normal case for the message of 16 bytes
5266 let key = 0x_1234567890ABCDEF_u64;
5267 println!("K =\t{:#016X}", key);
5268 let mut a_des = DES::new_with_key_u64(key);
5269
5270 let message = "고맙습니다.";
5271 println!("M =\t{}", message);
5272 let iv = 0x_FEDCBA0987654321_u64;
5273 println!("IV = {}", iv);
5274 let mut cipher = Vec::<u8>::new();
5275 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5276 print!("C =\t");
5277 for c in cipher.clone()
5278 { print!("{:02X} ", c); }
5279 println!();
5280 let mut txt = String::new();
5281 for c in cipher.clone()
5282 { write!(txt, "{:02X} ", c); }
5283 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
5284
5285 let mut recovered = [0u8; 24];
5286 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5287
5288 print!("Ba =\t");
5289 for b in recovered.clone()
5290 { print!("{:02X} ", b); }
5291 println!();
5292 let mut txt = String::new();
5293 for c in recovered.clone()
5294 { write!(txt, "{:02X} ", c); }
5295 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
5296
5297 let mut converted = String::new();
5298 unsafe { converted.as_mut_vec() }.write(&recovered);
5299 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5300 println!("Bb =\t{}", converted);
5301 assert_eq!(converted, "고맙습니다.");
5302 assert_eq!(converted, message);
5303 println!("-------------------------------");
5304}
5305
5306fn des_decrypt_vec_cfb_into_string()
5307{
5308 println!("des_decrypt_vec_cfb_into_string()");
5309 use std::io::Write;
5310 use std::fmt::Write as _;
5311 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
5312
5313 // Normal case
5314 let key = 0x_1234567890ABCDEF_u64;
5315 println!("K =\t{:#016X}", key);
5316 let mut a_des = DES::new_with_key_u64(key);
5317
5318 let message = "In the beginning God created the heavens and the earth.";
5319 println!("M =\t{}", message);
5320 let iv = 0x_FEDCBA0987654321_u64;
5321 println!("IV = {}", iv);
5322 let mut cipher = Vec::<u8>::new();
5323 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5324 print!("C (16 rounds) =\t");
5325 for c in cipher.clone()
5326 { print!("{:02X} ", c); }
5327 println!();
5328 let mut txt = String::new();
5329 for c in cipher.clone()
5330 { write!(txt, "{:02X} ", c); }
5331 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
5332
5333 let mut recovered = String::new();
5334 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5335 println!("B (16 rounds) =\t{}", recovered);
5336 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5337 assert_eq!(recovered, message);
5338 println!();
5339
5340 // Expanded case for 128 rounds
5341 let key = 0x_1234567890ABCDEF_u64;
5342 println!("K =\t{:#016X}", key);
5343 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5344
5345 let message = "In the beginning God created the heavens and the earth.";
5346 println!("M =\t{}", message);
5347 let iv = 0x_FEDCBA0987654321_u64;
5348 println!("IV = {}", iv);
5349 let mut cipher = Vec::<u8>::new();
5350 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5351 print!("C (128 rounds) =\t");
5352 for c in cipher.clone()
5353 { print!("{:02X} ", c); }
5354 println!();
5355 let mut txt = String::new();
5356 for c in cipher.clone()
5357 { write!(txt, "{:02X} ", c); }
5358 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
5359
5360 let mut recovered = String::new();
5361 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5362 println!("B (128 rounds) =\t{}", recovered);
5363 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5364 assert_eq!(recovered, message);
5365 println!();
5366
5367 // Expanded case for 0 rounds which means that key is meaningless
5368 let key1 = 0x_1234567890ABCDEF_u64;
5369 let key2 = 0_u64;
5370 println!("K =\t{:#016X}", key);
5371 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5372 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5373
5374 let message = "In the beginning God created the heavens and the earth.";
5375 println!("M =\t{}", message);
5376 let iv = 0x_FEDCBA0987654321_u64;
5377 println!("IV = {}", iv);
5378 let mut cipher1 = Vec::<u8>::new();
5379 let mut cipher2 = Vec::<u8>::new();
5380 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
5381 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
5382 print!("C (0 rounds) =\t");
5383 for c in cipher1.clone()
5384 { print!("{:02X} ", c); }
5385 println!();
5386 let mut txt = String::new();
5387 for c in cipher1.clone()
5388 { write!(txt, "{:02X} ", c); }
5389 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
5390 print!("D (0 rounds) =\t");
5391 for c in cipher2.clone()
5392 { print!("{:02X} ", c); }
5393 println!();
5394 let mut txt = String::new();
5395 for c in cipher2.clone()
5396 { write!(txt, "{:02X} ", c); }
5397 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
5398
5399 let mut recovered1 = String::new();
5400 let mut recovered2 = String::new();
5401 c_des.decrypt_vec_into_string(iv, &cipher1, &mut recovered1);
5402 d_des.decrypt_vec_into_string(iv, &cipher2, &mut recovered2);
5403 println!("B1 (0 rounds) =\t{}", recovered1);
5404 println!("B2 (0 rounds) =\t{}", recovered2);
5405 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5406 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5407 assert_eq!(recovered1, message);
5408 assert_eq!(recovered2, message);
5409 assert_eq!(recovered1, recovered2);
5410 println!();
5411
5412 // Normal case for the message of 0 bytes
5413 let key = 0x_1234567890ABCDEF_u64;
5414 println!("K =\t{:#016X}", key);
5415 let mut a_des = DES::new_with_key_u64(key);
5416
5417 let message = "";
5418 println!("M =\t{}", message);
5419 let iv = 0x_FEDCBA0987654321_u64;
5420 println!("IV = {}", iv);
5421 let mut cipher = Vec::<u8>::new();
5422 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5423 print!("C =\t");
5424 for c in cipher.clone()
5425 { print!("{:02X} ", c); }
5426 println!();
5427 let mut txt = String::new();
5428 for c in cipher.clone()
5429 { write!(txt, "{:02X} ", c); }
5430 assert_eq!(txt, "");
5431
5432 let mut recovered = String::new();
5433 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5434 println!("B =\t{}", recovered);
5435 assert_eq!(recovered, "");
5436 assert_eq!(recovered, message);
5437 println!();
5438
5439 // Normal case for the message shorter than 8 bytes
5440 let key = 0x_1234567890ABCDEF_u64;
5441 println!("K =\t{:#016X}", key);
5442 let mut a_des = DES::new_with_key_u64(key);
5443
5444 let message = "7 bytes";
5445 println!("M =\t{}", message);
5446 let iv = 0x_FEDCBA0987654321_u64;
5447 println!("IV = {}", iv);
5448 let mut cipher = Vec::<u8>::new();
5449 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5450 print!("C =\t");
5451 for c in cipher.clone()
5452 { print!("{:02X} ", c); }
5453 println!();
5454 let mut txt = String::new();
5455 for c in cipher.clone()
5456 { write!(txt, "{:02X} ", c); }
5457 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
5458
5459 let mut recovered = String::new();
5460 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5461 println!("B =\t{}", recovered);
5462 assert_eq!(recovered, "7 bytes");
5463 assert_eq!(recovered, message);
5464 println!();
5465
5466 // Normal case for the message of 8 bytes
5467 let key = 0x_1234567890ABCDEF_u64;
5468 println!("K =\t{:#016X}", key);
5469 let mut a_des = DES::new_with_key_u64(key);
5470
5471 let message = "I am OK.";
5472 println!("M =\t{}", message);
5473 let iv = 0x_FEDCBA0987654321_u64;
5474 println!("IV = {}", iv);
5475 let mut cipher = Vec::<u8>::new();
5476 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5477 print!("C =\t");
5478 for c in cipher.clone()
5479 { print!("{:02X} ", c); }
5480 println!();
5481 let mut txt = String::new();
5482 for c in cipher.clone()
5483 { write!(txt, "{:02X} ", c); }
5484 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
5485
5486 let mut recovered = String::new();
5487 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5488 println!("B =\t{}", recovered);
5489 assert_eq!(recovered, "I am OK.");
5490 assert_eq!(recovered, message);
5491 println!();
5492
5493 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5494 let key = 0x_1234567890ABCDEF_u64;
5495 println!("K =\t{:#016X}", key);
5496 let mut a_des = DES::new_with_key_u64(key);
5497
5498 let message = "PARK Youngho";
5499 println!("M =\t{}", message);
5500 let iv = 0x_FEDCBA0987654321_u64;
5501 println!("IV = {}", iv);
5502 let mut cipher = Vec::<u8>::new();
5503 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5504 print!("C =\t");
5505 for c in cipher.clone()
5506 { print!("{:02X} ", c); }
5507 println!();
5508 let mut txt = String::new();
5509 for c in cipher.clone()
5510 { write!(txt, "{:02X} ", c); }
5511 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
5512
5513 let mut recovered = String::new();
5514 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5515 println!("B =\t{}", recovered);
5516 assert_eq!(recovered, "PARK Youngho");
5517 assert_eq!(recovered, message);
5518 println!();
5519
5520 // Normal case for the message of 16 bytes
5521 let key = 0x_1234567890ABCDEF_u64;
5522 println!("K =\t{:#016X}", key);
5523 let mut a_des = DES::new_with_key_u64(key);
5524
5525 let message = "고맙습니다.";
5526 println!("M =\t{}", message);
5527 let iv = 0x_FEDCBA0987654321_u64;
5528 println!("IV = {}", iv);
5529 let mut cipher = Vec::<u8>::new();
5530 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5531 print!("C =\t");
5532 for c in cipher.clone()
5533 { print!("{:02X} ", c); }
5534 println!();
5535 let mut txt = String::new();
5536 for c in cipher.clone()
5537 { write!(txt, "{:02X} ", c); }
5538 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
5539
5540 let mut recovered = String::new();
5541 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5542 println!("B =\t{}", recovered);
5543 assert_eq!(recovered, "고맙습니다.");
5544 assert_eq!(recovered, message);
5545 println!("-------------------------------");
5546}
5547
5548fn des_decrypt_array_cfb()
5549{
5550 println!("des_decrypt_array_cfb()");
5551 use std::io::Write;
5552 use std::fmt::Write as _;
5553 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
5554
5555 // Normal case
5556 let key = 0x_1234567890ABCDEF_u64;
5557 println!("K =\t{:#016X}", key);
5558 let mut a_des = DES::new_with_key_u64(key);
5559
5560 let message = "In the beginning God created the heavens and the earth.";
5561 println!("M =\t{}", message);
5562 let iv = 0x_FEDCBA0987654321_u64;
5563 println!("IV = {}", iv);
5564 let mut cipher = [0_u8; 55];
5565 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5566 print!("C (16 rounds) =\t");
5567 for c in cipher.clone()
5568 { print!("{:02X} ", c); }
5569 println!();
5570 let mut txt = String::new();
5571 for c in cipher.clone()
5572 { write!(txt, "{:02X} ", c); }
5573 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
5574
5575 let mut recovered = vec![0; 55];
5576 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5577 recovered.truncate(len as usize);
5578 print!("Ba (16 rounds) =\t");
5579 for b in recovered.clone()
5580 { print!("{:02X} ", b); }
5581 println!();
5582 let mut txt = String::new();
5583 for c in recovered.clone()
5584 { write!(txt, "{:02X} ", c); }
5585 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5586
5587 let mut converted = String::new();
5588 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5589
5590 println!("Bb (16 rounds) =\t{}", converted);
5591 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5592 assert_eq!(converted, message);
5593 println!();
5594
5595 // Expanded case for 128 rounds
5596 let key = 0x_1234567890ABCDEF_u64;
5597 println!("K =\t{:#016X}", key);
5598 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5599
5600 let message = "In the beginning God created the heavens and the earth.";
5601 println!("M =\t{}", message);
5602 let iv = 0x_FEDCBA0987654321_u64;
5603 println!("IV = {}", iv);
5604 let mut cipher = [0_u8; 55];
5605 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5606 print!("C (128 rounds) =\t");
5607 for c in cipher.clone()
5608 { print!("{:02X} ", c); }
5609 println!();
5610 let mut txt = String::new();
5611 for c in cipher.clone()
5612 { write!(txt, "{:02X} ", c); }
5613 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
5614
5615 let mut recovered = vec![0; 55];
5616 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5617 recovered.truncate(len as usize);
5618 print!("Ba (128 rounds) =\t");
5619 for b in recovered.clone()
5620 { print!("{:02X} ", b); }
5621 println!();
5622 let mut txt = String::new();
5623 for c in recovered.clone()
5624 { write!(txt, "{:02X} ", c); }
5625 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5626
5627 let mut converted = String::new();
5628 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5629
5630 println!("Bb (128 rounds) =\t{}", converted);
5631 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5632 assert_eq!(converted, message);
5633 println!();
5634
5635 // Expanded case for 0 rounds which means that key is meaningless
5636 let key1 = 0x_1234567890ABCDEF_u64;
5637 let key2 = 0_u64;
5638 println!("K =\t{:#016X}", key);
5639 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5640 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5641
5642 let message = "In the beginning God created the heavens and the earth.";
5643 println!("M =\t{}", message);
5644 let iv = 0x_FEDCBA0987654321_u64;
5645 println!("IV = {}", iv);
5646 let mut cipher1 = [0_u8; 55];
5647 let mut cipher2 = [0_u8; 55];
5648 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
5649 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
5650 print!("C (0 rounds) =\t");
5651 for c in cipher1.clone()
5652 { print!("{:02X} ", c); }
5653 println!();
5654 let mut txt = String::new();
5655 for c in cipher1.clone()
5656 { write!(txt, "{:02X} ", c); }
5657 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
5658 print!("D (0 rounds) =\t");
5659 for c in cipher2.clone()
5660 { print!("{:02X} ", c); }
5661 println!();
5662 let mut txt = String::new();
5663 for c in cipher2.clone()
5664 { write!(txt, "{:02X} ", c); }
5665 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
5666
5667 let mut recovered1 = vec![0; 55];
5668 let mut recovered2 = vec![0; 55];
5669 let len1 = c_des.decrypt_array(iv, &cipher1, recovered1.as_mut_ptr());
5670 let len2 = d_des.decrypt_array(iv, &cipher2, recovered2.as_mut_ptr());
5671 recovered1.truncate(len1 as usize);
5672 recovered2.truncate(len2 as usize);
5673
5674 print!("B1a (0 rounds) =\t");
5675 for b in recovered1.clone()
5676 { print!("{:02X} ", b); }
5677 println!();
5678 let mut txt = String::new();
5679 for c in recovered1.clone()
5680 { write!(txt, "{:02X} ", c); }
5681 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5682 print!("B2a (0 rounds) =\t");
5683 for b in recovered2.clone()
5684 { print!("{:02X} ", b); }
5685 println!();
5686 let mut txt = String::new();
5687 for c in recovered2.clone()
5688 { write!(txt, "{:02X} ", c); }
5689 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5690
5691 let mut converted1 = String::new();
5692 let mut converted2 = String::new();
5693 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5694 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5695
5696 println!("B1b (0 rounds) =\t{}", converted1);
5697 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5698 assert_eq!(converted1, message);
5699 println!("B2b (0 rounds) =\t{}", converted2);
5700 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5701 assert_eq!(converted2, message);
5702 assert_eq!(converted1, converted1);
5703 println!();
5704
5705 // Normal case for the message of 0 bytes
5706 let key = 0x_1234567890ABCDEF_u64;
5707 println!("K =\t{:#016X}", key);
5708 let mut a_des = DES::new_with_key_u64(key);
5709
5710 let message = "";
5711 println!("M =\t{}", message);
5712 let iv = 0x_FEDCBA0987654321_u64;
5713 println!("IV = {}", iv);
5714 let mut cipher = [0_u8; 0];
5715 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5716 print!("C =\t");
5717 for c in cipher.clone()
5718 { print!("{:02X} ", c); }
5719 println!();
5720 let mut txt = String::new();
5721 for c in cipher.clone()
5722 { write!(txt, "{:02X} ", c); }
5723 assert_eq!(txt, "");
5724
5725 let mut recovered = vec![0; 8];
5726 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5727 recovered.truncate(len as usize);
5728
5729 print!("Ba =\t");
5730 for b in recovered.clone()
5731 { print!("{:02X} ", b); }
5732 println!();
5733 let mut txt = String::new();
5734 for c in recovered.clone()
5735 { write!(txt, "{:02X} ", c); }
5736 assert_eq!(txt, "");
5737
5738 let mut converted = String::new();
5739 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5740
5741 println!("Bb =\t{}", converted);
5742 assert_eq!(converted, "");
5743 assert_eq!(converted, message);
5744 println!();
5745
5746 // Normal case for the message shorter than 8 bytes
5747 let key = 0x_1234567890ABCDEF_u64;
5748 println!("K =\t{:#016X}", key);
5749 let mut a_des = DES::new_with_key_u64(key);
5750
5751 let message = "7 bytes";
5752 println!("M =\t{}", message);
5753 let iv = 0x_FEDCBA0987654321_u64;
5754 println!("IV = {}", iv);
5755 let mut cipher = [0_u8; 7];
5756 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5757 print!("C =\t");
5758 for c in cipher.clone()
5759 { print!("{:02X} ", c); }
5760 println!();
5761 let mut txt = String::new();
5762 for c in cipher.clone()
5763 { write!(txt, "{:02X} ", c); }
5764 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
5765
5766 let mut recovered = vec![0; 8];
5767 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5768 recovered.truncate(len as usize);
5769
5770 print!("Ba =\t");
5771 for b in recovered.clone()
5772 { print!("{:02X} ", b); }
5773 println!();
5774 let mut txt = String::new();
5775 for c in recovered.clone()
5776 { write!(txt, "{:02X} ", c); }
5777 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5778
5779 let mut converted = String::new();
5780 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5781
5782 println!("Bb =\t{}", converted);
5783 assert_eq!(converted, "7 bytes");
5784 assert_eq!(converted, message);
5785 println!();
5786
5787 // Normal case for the message of 8 bytes
5788 let key = 0x_1234567890ABCDEF_u64;
5789 println!("K =\t{:#016X}", key);
5790 let mut a_des = DES::new_with_key_u64(key);
5791
5792 let message = "I am OK.";
5793 println!("M =\t{}", message);
5794 let iv = 0x_FEDCBA0987654321_u64;
5795 println!("IV = {}", iv);
5796 let mut cipher = [0_u8; 8];
5797 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5798 print!("C =\t");
5799 for c in cipher.clone()
5800 { print!("{:02X} ", c); }
5801 println!();
5802 let mut txt = String::new();
5803 for c in cipher.clone()
5804 { write!(txt, "{:02X} ", c); }
5805 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
5806
5807 let mut recovered = vec![0; 16];
5808 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5809 recovered.truncate(len as usize);
5810
5811 print!("Ba =\t");
5812 for b in recovered.clone()
5813 { print!("{:02X} ", b); }
5814 println!();
5815 let mut txt = String::new();
5816 for c in recovered.clone()
5817 { write!(txt, "{:02X} ", c); }
5818 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5819
5820 let mut converted = String::new();
5821 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5822
5823 println!("Bb =\t{}", converted);
5824 assert_eq!(converted, "I am OK.");
5825 assert_eq!(converted, message);
5826 println!();
5827
5828 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5829 let key = 0x_1234567890ABCDEF_u64;
5830 println!("K =\t{:#016X}", key);
5831 let mut a_des = DES::new_with_key_u64(key);
5832
5833 let message = "PARK Youngho";
5834 println!("M =\t{}", message);
5835 let iv = 0x_FEDCBA0987654321_u64;
5836 println!("IV = {}", iv);
5837 let mut cipher = [0_u8; 12];
5838 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5839 print!("C =\t");
5840 for c in cipher.clone()
5841 { print!("{:02X} ", c); }
5842 println!();
5843 let mut txt = String::new();
5844 for c in cipher.clone()
5845 { write!(txt, "{:02X} ", c); }
5846 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
5847
5848 let mut recovered = vec![0; 16];
5849 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5850 recovered.truncate(len as usize);
5851 print!("Ba =\t");
5852 for b in recovered.clone()
5853 { print!("{:02X} ", b); }
5854 println!();
5855 let mut txt = String::new();
5856 for c in recovered.clone()
5857 { write!(txt, "{:02X} ", c); }
5858 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5859
5860 let mut converted = String::new();
5861 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5862
5863 println!("Bb =\t{}", converted);
5864 assert_eq!(converted, "PARK Youngho");
5865 assert_eq!(converted, message);
5866 println!();
5867
5868 // Normal case for the message of 16 bytes
5869 let key = 0x_1234567890ABCDEF_u64;
5870 println!("K =\t{:#016X}", key);
5871 let mut a_des = DES::new_with_key_u64(key);
5872
5873 let message = "고맙습니다.";
5874 println!("M =\t{}", message);
5875 let iv = 0x_FEDCBA0987654321_u64;
5876 println!("IV = {}", iv);
5877 let mut cipher = [0_u8; 16];
5878 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5879 print!("C =\t");
5880 for c in cipher.clone()
5881 { print!("{:02X} ", c); }
5882 println!();
5883 let mut txt = String::new();
5884 for c in cipher.clone()
5885 { write!(txt, "{:02X} ", c); }
5886 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
5887
5888 let mut recovered = vec![0; 24];
5889 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5890 recovered.truncate(len as usize);
5891
5892 print!("Ba =\t");
5893 for b in recovered.clone()
5894 { print!("{:02X} ", b); }
5895 println!();
5896 let mut txt = String::new();
5897 for c in recovered.clone()
5898 { write!(txt, "{:02X} ", c); }
5899 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5900
5901 let mut converted = String::new();
5902 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5903
5904 println!("Bb =\t{}", converted);
5905 assert_eq!(converted, "고맙습니다.");
5906 assert_eq!(converted, message);
5907 println!("-------------------------------");
5908}
5909
5910fn des_decrypt_array_cfb_into_vec()
5911{
5912 println!("des_decrypt_array_cfb_into_vec()");
5913 use std::io::Write;
5914 use std::fmt::Write as _;
5915 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
5916
5917 // Normal case
5918 let key = 0x_1234567890ABCDEF_u64;
5919 println!("K =\t{:#016X}", key);
5920 let mut a_des = DES::new_with_key_u64(key);
5921
5922 let message = "In the beginning God created the heavens and the earth.";
5923 println!("M =\t{}", message);
5924 let iv = 0x_FEDCBA0987654321_u64;
5925 println!("IV = {}", iv);
5926 let mut cipher = [0_u8; 55];
5927 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5928 print!("C (16 rounds) =\t");
5929 for c in cipher.clone()
5930 { print!("{:02X} ", c); }
5931 println!();
5932 let mut txt = String::new();
5933 for c in cipher.clone()
5934 { write!(txt, "{:02X} ", c); }
5935 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
5936
5937 let mut recovered = Vec::<u8>::new();
5938 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
5939 print!("Ba (16 rounds) =\t");
5940 for b in recovered.clone()
5941 { print!("{:02X} ", b); }
5942 println!();
5943 let mut txt = String::new();
5944 for c in recovered.clone()
5945 { write!(txt, "{:02X} ", c); }
5946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5947
5948 let mut converted = String::new();
5949 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5950
5951 println!("Bb (16 rounds) =\t{}", converted);
5952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5953 assert_eq!(converted, message);
5954 println!();
5955
5956 // Expanded case for 128 rounds
5957 let key = 0x_1234567890ABCDEF_u64;
5958 println!("K =\t{:#016X}", key);
5959 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5960
5961 let message = "In the beginning God created the heavens and the earth.";
5962 println!("M =\t{}", message);
5963 let iv = 0x_FEDCBA0987654321_u64;
5964 println!("IV = {}", iv);
5965 let mut cipher = [0_u8; 55];
5966 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5967 print!("C (128 rounds) =\t");
5968 for c in cipher.clone()
5969 { print!("{:02X} ", c); }
5970 println!();
5971 let mut txt = String::new();
5972 for c in cipher.clone()
5973 { write!(txt, "{:02X} ", c); }
5974 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
5975
5976 let mut recovered = Vec::<u8>::new();
5977 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
5978 print!("Ba (128 rounds) =\t");
5979 for b in recovered.clone()
5980 { print!("{:02X} ", b); }
5981 println!();
5982 let mut txt = String::new();
5983 for c in recovered.clone()
5984 { write!(txt, "{:02X} ", c); }
5985 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5986
5987 let mut converted = String::new();
5988 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5989
5990 println!("Bb (128 rounds) =\t{}", converted);
5991 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5992 assert_eq!(converted, message);
5993 println!();
5994
5995 // Expanded case for 0 rounds which means that key is meaningless
5996 let key1 = 0x_1234567890ABCDEF_u64;
5997 let key2 = 0_u64;
5998 println!("K =\t{:#016X}", key);
5999 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6000 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6001
6002 let message = "In the beginning God created the heavens and the earth.";
6003 println!("M =\t{}", message);
6004 let iv = 0x_FEDCBA0987654321_u64;
6005 println!("IV = {}", iv);
6006 let mut cipher1 = [0_u8; 55];
6007 let mut cipher2 = [0_u8; 55];
6008 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
6009 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
6010 print!("C (0 rounds) =\t");
6011 for c in cipher1.clone()
6012 { print!("{:02X} ", c); }
6013 println!();
6014 let mut txt = String::new();
6015 for c in cipher1.clone()
6016 { write!(txt, "{:02X} ", c); }
6017 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
6018 print!("D (0 rounds) =\t");
6019 for c in cipher2.clone()
6020 { print!("{:02X} ", c); }
6021 println!();
6022 let mut txt = String::new();
6023 for c in cipher2.clone()
6024 { write!(txt, "{:02X} ", c); }
6025 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
6026
6027 let mut recovered1 = Vec::<u8>::new();
6028 let mut recovered2 = Vec::<u8>::new();
6029 c_des.decrypt_array_into_vec(iv, &cipher1, &mut recovered1);
6030 d_des.decrypt_array_into_vec(iv, &cipher2, &mut recovered2);
6031 print!("B1a (0 rounds) =\t");
6032 for b in recovered1.clone()
6033 { print!("{:02X} ", b); }
6034 println!();
6035 let mut txt = String::new();
6036 for c in recovered1.clone()
6037 { write!(txt, "{:02X} ", c); }
6038 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
6039 print!("B2a (0 rounds) =\t");
6040 for b in recovered2.clone()
6041 { print!("{:02X} ", b); }
6042 println!();
6043 let mut txt = String::new();
6044 for c in recovered2.clone()
6045 { write!(txt, "{:02X} ", c); }
6046 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
6047
6048 let mut converted1 = String::new();
6049 let mut converted2 = String::new();
6050 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
6051 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
6052
6053 println!("B1b (0 rounds) =\t{}", converted1);
6054 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6055 assert_eq!(converted1, message);
6056 println!("B2b (0 rounds) =\t{}", converted2);
6057 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6058 assert_eq!(converted2, message);
6059 assert_eq!(converted1, converted1);
6060 println!();
6061
6062 // Normal case for the message of 0 bytes
6063 let key = 0x_1234567890ABCDEF_u64;
6064 println!("K =\t{:#016X}", key);
6065 let mut a_des = DES::new_with_key_u64(key);
6066
6067 let message = "";
6068 println!("M =\t{}", message);
6069 let iv = 0x_FEDCBA0987654321_u64;
6070 println!("IV = {}", iv);
6071 let mut cipher = [0_u8; 0];
6072 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6073 print!("C =\t");
6074 for c in cipher.clone()
6075 { print!("{:02X} ", c); }
6076 println!();
6077 let mut txt = String::new();
6078 for c in cipher.clone()
6079 { write!(txt, "{:02X} ", c); }
6080 assert_eq!(txt, "");
6081
6082 let mut recovered = Vec::<u8>::new();
6083 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6084 print!("Ba =\t");
6085 for b in recovered.clone()
6086 { print!("{:02X} ", b); }
6087 println!();
6088 let mut txt = String::new();
6089 for c in recovered.clone()
6090 { write!(txt, "{:02X} ", c); }
6091 assert_eq!(txt, "");
6092
6093 let mut converted = String::new();
6094 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6095
6096 println!("Bb =\t{}", converted);
6097 assert_eq!(converted, "");
6098 assert_eq!(converted, message);
6099 println!();
6100
6101 // Normal case for the message shorter than 8 bytes
6102 let key = 0x_1234567890ABCDEF_u64;
6103 println!("K =\t{:#016X}", key);
6104 let mut a_des = DES::new_with_key_u64(key);
6105
6106 let message = "7 bytes";
6107 println!("M =\t{}", message);
6108 let iv = 0x_FEDCBA0987654321_u64;
6109 println!("IV = {}", iv);
6110 let mut cipher = [0_u8; 7];
6111 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6112 print!("C =\t");
6113 for c in cipher.clone()
6114 { print!("{:02X} ", c); }
6115 println!();
6116 let mut txt = String::new();
6117 for c in cipher.clone()
6118 { write!(txt, "{:02X} ", c); }
6119 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
6120
6121 let mut recovered = Vec::<u8>::new();
6122 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6123 print!("Ba =\t");
6124 for b in recovered.clone()
6125 { print!("{:02X} ", b); }
6126 println!();
6127 let mut txt = String::new();
6128 for c in recovered.clone()
6129 { write!(txt, "{:02X} ", c); }
6130 assert_eq!(txt, "37 20 62 79 74 65 73 ");
6131
6132 let mut converted = String::new();
6133 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6134
6135 println!("Bb =\t{}", converted);
6136 assert_eq!(converted, "7 bytes");
6137 assert_eq!(converted, message);
6138 println!();
6139
6140 // Normal case for the message of 8 bytes
6141 let key = 0x_1234567890ABCDEF_u64;
6142 println!("K =\t{:#016X}", key);
6143 let mut a_des = DES::new_with_key_u64(key);
6144
6145 let message = "I am OK.";
6146 println!("M =\t{}", message);
6147 let iv = 0x_FEDCBA0987654321_u64;
6148 println!("IV = {}", iv);
6149 let mut cipher = [0_u8; 8];
6150 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6151 print!("C =\t");
6152 for c in cipher.clone()
6153 { print!("{:02X} ", c); }
6154 println!();
6155 let mut txt = String::new();
6156 for c in cipher.clone()
6157 { write!(txt, "{:02X} ", c); }
6158 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
6159
6160 let mut recovered = Vec::<u8>::new();
6161 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6162 print!("Ba =\t");
6163 for b in recovered.clone()
6164 { print!("{:02X} ", b); }
6165 println!();
6166 let mut txt = String::new();
6167 for c in recovered.clone()
6168 { write!(txt, "{:02X} ", c); }
6169 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
6170
6171 let mut converted = String::new();
6172 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6173
6174 println!("Bb =\t{}", converted);
6175 assert_eq!(converted, "I am OK.");
6176 assert_eq!(converted, message);
6177 println!();
6178
6179 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6180 let key = 0x_1234567890ABCDEF_u64;
6181 println!("K =\t{:#016X}", key);
6182 let mut a_des = DES::new_with_key_u64(key);
6183
6184 let message = "PARK Youngho";
6185 println!("M =\t{}", message);
6186 let iv = 0x_FEDCBA0987654321_u64;
6187 println!("IV = {}", iv);
6188 let mut cipher = [0_u8; 12];
6189 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6190 print!("C =\t");
6191 for c in cipher.clone()
6192 { print!("{:02X} ", c); }
6193 println!();
6194 let mut txt = String::new();
6195 for c in cipher.clone()
6196 { write!(txt, "{:02X} ", c); }
6197 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
6198
6199 let mut recovered = Vec::<u8>::new();
6200 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6201 print!("Ba =\t");
6202 for b in recovered.clone()
6203 { print!("{:02X} ", b); }
6204 println!();
6205 let mut txt = String::new();
6206 for c in recovered.clone()
6207 { write!(txt, "{:02X} ", c); }
6208 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
6209
6210 let mut converted = String::new();
6211 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6212
6213 println!("Bb =\t{}", converted);
6214 assert_eq!(converted, "PARK Youngho");
6215 assert_eq!(converted, message);
6216 println!();
6217
6218 // Normal case for the message of 16 bytes
6219 let key = 0x_1234567890ABCDEF_u64;
6220 println!("K =\t{:#016X}", key);
6221 let mut a_des = DES::new_with_key_u64(key);
6222
6223 let message = "고맙습니다.";
6224 println!("M =\t{}", message);
6225 let iv = 0x_FEDCBA0987654321_u64;
6226 println!("IV = {}", iv);
6227 let mut cipher = [0_u8; 16];
6228 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6229 print!("C =\t");
6230 for c in cipher.clone()
6231 { print!("{:02X} ", c); }
6232 println!();
6233 let mut txt = String::new();
6234 for c in cipher.clone()
6235 { write!(txt, "{:02X} ", c); }
6236 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
6237
6238 let mut recovered = Vec::<u8>::new();
6239 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6240 print!("Ba =\t");
6241 for b in recovered.clone()
6242 { print!("{:02X} ", b); }
6243 println!();
6244 let mut txt = String::new();
6245 for c in recovered.clone()
6246 { write!(txt, "{:02X} ", c); }
6247 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
6248
6249 let mut converted = String::new();
6250 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6251
6252 println!("Bb =\t{}", converted);
6253 assert_eq!(converted, "고맙습니다.");
6254 assert_eq!(converted, message);
6255 println!("-------------------------------");
6256}
6257
6258fn des_decrypt_array_cfb_into_array()
6259{
6260 println!("des_decrypt_array_cfb_into_array()");
6261 use std::io::Write;
6262 use std::fmt::Write as _;
6263 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
6264
6265 // Normal case
6266 let key = 0x_1234567890ABCDEF_u64;
6267 println!("K =\t{:#016X}", key);
6268 let mut a_des = DES::new_with_key_u64(key);
6269
6270 let message = "In the beginning God created the heavens and the earth.";
6271 println!("M =\t{}", message);
6272 let iv = 0x_FEDCBA0987654321_u64;
6273 println!("IV = {}", iv);
6274 let mut cipher = [0_u8; 55];
6275 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6276 print!("C (16 rounds) =\t");
6277 for c in cipher.clone()
6278 { print!("{:02X} ", c); }
6279 println!();
6280 let mut txt = String::new();
6281 for c in cipher.clone()
6282 { write!(txt, "{:02X} ", c); }
6283 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
6284
6285 let mut recovered = [0u8; 56];
6286 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6287 print!("Ba (16 rounds) =\t");
6288 for b in recovered.clone()
6289 { print!("{:02X} ", b); }
6290 println!();
6291 let mut txt = String::new();
6292 for c in recovered.clone()
6293 { write!(txt, "{:02X} ", c); }
6294 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6295
6296 let mut converted = String::new();
6297 unsafe { converted.as_mut_vec() }.write(&recovered);
6298 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6299 println!("Bb (16 rounds) =\t{}", converted);
6300 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
6301 assert_eq!(converted, message);
6302 println!();
6303
6304 // Expanded case for 128 rounds
6305 let key = 0x_1234567890ABCDEF_u64;
6306 println!("K =\t{:#016X}", key);
6307 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6308
6309 let message = "In the beginning God created the heavens and the earth.";
6310 println!("M =\t{}", message);
6311 let iv = 0x_FEDCBA0987654321_u64;
6312 println!("IV = {}", iv);
6313 let mut cipher = [0_u8; 55];
6314 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6315 print!("C (128 rounds) =\t");
6316 for c in cipher.clone()
6317 { print!("{:02X} ", c); }
6318 println!();
6319 let mut txt = String::new();
6320 for c in cipher.clone()
6321 { write!(txt, "{:02X} ", c); }
6322 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
6323
6324 let mut recovered = [0u8; 56];
6325 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6326 print!("Ba (16 rounds) =\t");
6327 for b in recovered.clone()
6328 { print!("{:02X} ", b); }
6329 println!();
6330 let mut txt = String::new();
6331 for c in recovered.clone()
6332 { write!(txt, "{:02X} ", c); }
6333 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6334
6335 let mut converted = String::new();
6336 unsafe { converted.as_mut_vec() }.write(&recovered);
6337 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6338 println!("Bb (16 rounds) =\t{}", converted);
6339 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
6340 assert_eq!(converted, message);
6341 println!();
6342
6343 // Expanded case for 0 rounds which means that key is meaningless
6344 let key1 = 0x_1234567890ABCDEF_u64;
6345 let key2 = 0_u64;
6346 println!("K =\t{:#016X}", key);
6347 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6348 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6349
6350 let message = "In the beginning God created the heavens and the earth.";
6351 println!("M =\t{}", message);
6352 let iv = 0x_FEDCBA0987654321_u64;
6353 println!("IV = {}", iv);
6354 let mut cipher1 = [0_u8; 55];
6355 let mut cipher2 = [0_u8; 55];
6356 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
6357 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
6358 print!("C (0 rounds) =\t");
6359 for c in cipher1.clone()
6360 { print!("{:02X} ", c); }
6361 println!();
6362 let mut txt = String::new();
6363 for c in cipher1.clone()
6364 { write!(txt, "{:02X} ", c); }
6365 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
6366 print!("D (0 rounds) =\t");
6367 for c in cipher2.clone()
6368 { print!("{:02X} ", c); }
6369 println!();
6370 let mut txt = String::new();
6371 for c in cipher2.clone()
6372 { write!(txt, "{:02X} ", c); }
6373 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
6374
6375 let mut recovered1 = [0u8; 56];
6376 let mut recovered2 = [0u8; 56];
6377 let len1 = c_des.decrypt_array_into_array(iv, &cipher1, &mut recovered1);
6378 let len2 = d_des.decrypt_array_into_array(iv, &cipher2, &mut recovered2);
6379 print!("B1a (0 rounds) =\t");
6380 for b in recovered1.clone()
6381 { print!("{:02X} ", b); }
6382 println!();
6383 let mut txt = String::new();
6384 for c in recovered1.clone()
6385 { write!(txt, "{:02X} ", c); }
6386 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6387 print!("B2a (0 rounds) =\t");
6388 for b in recovered2.clone()
6389 { print!("{:02X} ", b); }
6390 println!();
6391 let mut txt = String::new();
6392 for c in recovered.clone()
6393 { write!(txt, "{:02X} ", c); }
6394 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6395
6396 let mut converted1 = String::new();
6397 let mut converted2 = String::new();
6398 unsafe { converted1.as_mut_vec() }.write(&recovered1);
6399 unsafe { converted2.as_mut_vec() }.write(&recovered2);
6400 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6401 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6402 println!("B1b (0 rounds) =\t{}", converted1);
6403 println!("B2b (0 rounds) =\t{}", converted2);
6404 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6405 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6406 assert_eq!(converted1, message);
6407 assert_eq!(converted2, message);
6408 assert_eq!(converted1, converted2);
6409 println!();
6410
6411 // Normal case for the message of 0 bytes
6412 let key = 0x_1234567890ABCDEF_u64;
6413 println!("K =\t{:#016X}", key);
6414 let mut a_des = DES::new_with_key_u64(key);
6415
6416 let message = "";
6417 println!("M =\t{}", message);
6418 let iv = 0x_FEDCBA0987654321_u64;
6419 println!("IV = {}", iv);
6420 let mut cipher = [0_u8; 0];
6421 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6422 print!("C =\t");
6423 for c in cipher.clone()
6424 { print!("{:02X} ", c); }
6425 println!();
6426 let mut txt = String::new();
6427 for c in cipher.clone()
6428 { write!(txt, "{:02X} ", c); }
6429 assert_eq!(txt, "");
6430
6431 let mut recovered = [0u8; 8];
6432 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6433
6434 print!("Ba =\t");
6435 for b in recovered.clone()
6436 { print!("{:02X} ", b); }
6437 println!();
6438 let mut txt = String::new();
6439 for c in recovered.clone()
6440 { write!(txt, "{:02X} ", c); }
6441 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6442
6443 let mut converted = String::new();
6444 unsafe { converted.as_mut_vec() }.write(&recovered);
6445 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6446 println!("Bb =\t{}", converted);
6447 assert_eq!(converted, "");
6448 assert_eq!(converted, message);
6449 println!();
6450
6451 // Normal case for the message shorter than 8 bytes
6452 let key = 0x_1234567890ABCDEF_u64;
6453 println!("K =\t{:#016X}", key);
6454 let mut a_des = DES::new_with_key_u64(key);
6455
6456 let message = "7 bytes";
6457 println!("M =\t{}", message);
6458 let iv = 0x_FEDCBA0987654321_u64;
6459 println!("IV = {}", iv);
6460 let mut cipher = [0_u8; 7];
6461 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6462 print!("C =\t");
6463 for c in cipher.clone()
6464 { print!("{:02X} ", c); }
6465 println!();
6466 let mut txt = String::new();
6467 for c in cipher.clone()
6468 { write!(txt, "{:02X} ", c); }
6469 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
6470
6471 let mut recovered = [0u8; 8];
6472 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6473
6474 print!("Ba =\t");
6475 for b in recovered.clone()
6476 { print!("{:02X} ", b); }
6477 println!();
6478 let mut txt = String::new();
6479 for c in recovered.clone()
6480 { write!(txt, "{:02X} ", c); }
6481 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6482
6483 let mut converted = String::new();
6484 unsafe { converted.as_mut_vec() }.write(&recovered);
6485 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6486 println!("Bb =\t{}", converted);
6487 assert_eq!(converted, "7 bytes");
6488 assert_eq!(converted, message);
6489 println!();
6490
6491 // Normal case for the message of 8 bytes
6492 let key = 0x_1234567890ABCDEF_u64;
6493 println!("K =\t{:#016X}", key);
6494 let mut a_des = DES::new_with_key_u64(key);
6495
6496 let message = "I am OK.";
6497 println!("M =\t{}", message);
6498 let iv = 0x_FEDCBA0987654321_u64;
6499 println!("IV = {}", iv);
6500 let mut cipher = [0_u8; 8];
6501 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6502 print!("C =\t");
6503 for c in cipher.clone()
6504 { print!("{:02X} ", c); }
6505 println!();
6506 let mut txt = String::new();
6507 for c in cipher.clone()
6508 { write!(txt, "{:02X} ", c); }
6509 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
6510
6511 let mut recovered = [0u8; 16];
6512 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6513
6514 print!("Ba =\t");
6515 for b in recovered.clone()
6516 { print!("{:02X} ", b); }
6517 println!();
6518 let mut txt = String::new();
6519 for c in recovered.clone()
6520 { write!(txt, "{:02X} ", c); }
6521 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6522
6523 let mut converted = String::new();
6524 unsafe { converted.as_mut_vec() }.write(&recovered);
6525 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6526 println!("Bb =\t{}", converted);
6527 assert_eq!(converted, "I am OK.");
6528 assert_eq!(converted, message);
6529 println!();
6530
6531 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6532 let key = 0x_1234567890ABCDEF_u64;
6533 println!("K =\t{:#016X}", key);
6534 let mut a_des = DES::new_with_key_u64(key);
6535
6536 let message = "PARK Youngho";
6537 println!("M =\t{}", message);
6538 let iv = 0x_FEDCBA0987654321_u64;
6539 println!("IV = {}", iv);
6540 let mut cipher = [0_u8; 12];
6541 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6542 print!("C =\t");
6543 for c in cipher.clone()
6544 { print!("{:02X} ", c); }
6545 println!();
6546 let mut txt = String::new();
6547 for c in cipher.clone()
6548 { write!(txt, "{:02X} ", c); }
6549 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
6550
6551 let mut recovered = [0u8; 16];
6552 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6553
6554 print!("Ba =\t");
6555 for b in recovered.clone()
6556 { print!("{:02X} ", b); }
6557 println!();
6558 let mut txt = String::new();
6559 for c in recovered.clone()
6560 { write!(txt, "{:02X} ", c); }
6561 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6562
6563 let mut converted = String::new();
6564 unsafe { converted.as_mut_vec() }.write(&recovered);
6565 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6566 println!("Bb =\t{}", converted);
6567 assert_eq!(converted, "PARK Youngho");
6568 assert_eq!(converted, message);
6569 println!();
6570
6571 // Normal case for the message of 16 bytes
6572 let key = 0x_1234567890ABCDEF_u64;
6573 println!("K =\t{:#016X}", key);
6574 let mut a_des = DES::new_with_key_u64(key);
6575
6576 let message = "고맙습니다.";
6577 println!("M =\t{}", message);
6578 let iv = 0x_FEDCBA0987654321_u64;
6579 println!("IV = {}", iv);
6580 let mut cipher = [0_u8; 16];
6581 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6582 print!("C =\t");
6583 for c in cipher.clone()
6584 { print!("{:02X} ", c); }
6585 println!();
6586 let mut txt = String::new();
6587 for c in cipher.clone()
6588 { write!(txt, "{:02X} ", c); }
6589 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
6590
6591 let mut recovered = [0u8; 24];
6592 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6593
6594 print!("Ba =\t");
6595 for b in recovered.clone()
6596 { print!("{:02X} ", b); }
6597 println!();
6598 let mut txt = String::new();
6599 for c in recovered.clone()
6600 { write!(txt, "{:02X} ", c); }
6601 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6602
6603 let mut converted = String::new();
6604 unsafe { converted.as_mut_vec() }.write(&recovered);
6605 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6606 println!("Bb =\t{}", converted);
6607 assert_eq!(converted, "고맙습니다.");
6608 assert_eq!(converted, message);
6609 println!("-------------------------------");
6610}
6611
6612fn des_decrypt_array_cfb_into_string()
6613{
6614 println!("des_decrypt_array_cfb_into_string()");
6615 use std::io::Write;
6616 use std::fmt::Write as _;
6617 use cryptocol::symmetric::{ DES, DES_Expanded, CFB};
6618
6619 // Normal case
6620 let key = 0x_1234567890ABCDEF_u64;
6621 println!("K =\t{:#016X}", key);
6622 let mut a_des = DES::new_with_key_u64(key);
6623
6624 let message = "In the beginning God created the heavens and the earth.";
6625 println!("M =\t{}", message);
6626 let iv = 0x_FEDCBA0987654321_u64;
6627 println!("IV = {}", iv);
6628 let mut cipher = [0_u8; 55];
6629 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6630 print!("C (16 rounds) =\t");
6631 for c in cipher.clone()
6632 { print!("{:02X} ", c); }
6633 println!();
6634 let mut txt = String::new();
6635 for c in cipher.clone()
6636 { write!(txt, "{:02X} ", c); }
6637 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 79 3A A1 78 EC CD 02 72 6A C4 41 7C 25 A4 2C 07 FC 77 25 49 12 55 0F 8A ED 44 C3 E4 DC 91 69 0F 40 72 7F F2 D9 B7 54 9F 36 91 C5 85 4F 9B 30 ");
6638
6639 let mut recovered = String::new();
6640 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6641 println!("B (16 rounds) =\t{}", recovered);
6642 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6643 assert_eq!(recovered, message);
6644 println!();
6645
6646 // Expanded case for 128 rounds
6647 let key = 0x_1234567890ABCDEF_u64;
6648 println!("K =\t{:#016X}", key);
6649 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6650
6651 let message = "In the beginning God created the heavens and the earth.";
6652 println!("M =\t{}", message);
6653 let iv = 0x_FEDCBA0987654321_u64;
6654 println!("IV = {}", iv);
6655 let mut cipher = [0_u8; 55];
6656 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6657 print!("C (128 rounds) =\t");
6658 for c in cipher.clone()
6659 { print!("{:02X} ", c); }
6660 println!();
6661 let mut txt = String::new();
6662 for c in cipher.clone()
6663 { write!(txt, "{:02X} ", c); }
6664 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 F2 9A 70 44 D9 78 F5 E3 CF 55 0F EF BA F0 4A 7E BE 79 C9 B4 68 F4 99 09 48 93 00 D2 22 9D 29 6C 20 74 FF E3 E2 01 0C D3 7E 8D 4D 30 8F EC D6 ");
6665
6666 let mut recovered = String::new();
6667 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6668 println!("B (128 rounds) =\t{}", recovered);
6669 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6670 assert_eq!(recovered, message);
6671 println!();
6672
6673 // Expanded case for 0 rounds which means that key is meaningless
6674 let key1 = 0x_1234567890ABCDEF_u64;
6675 let key2 = 0_u64;
6676 println!("K =\t{:#016X}", key);
6677 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6678 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6679
6680 let message = "In the beginning God created the heavens and the earth.";
6681 println!("M =\t{}", message);
6682 let iv = 0x_FEDCBA0987654321_u64;
6683 println!("IV = {}", iv);
6684 let mut cipher1 = [0_u8; 55];
6685 let mut cipher2 = [0_u8; 55];
6686 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
6687 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
6688 print!("C (0 rounds) =\t");
6689 for c in cipher1.clone()
6690 { print!("{:02X} ", c); }
6691 println!();
6692 let mut txt = String::new();
6693 for c in cipher1.clone()
6694 { write!(txt, "{:02X} ", c); }
6695 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
6696 print!("D (0 rounds) =\t");
6697 for c in cipher2.clone()
6698 { print!("{:02X} ", c); }
6699 println!();
6700 let mut txt = String::new();
6701 for c in cipher2.clone()
6702 { write!(txt, "{:02X} ", c); }
6703 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F C2 B9 1C 51 F3 49 A2 08 E1 31 43 C6 D3 E5 23 61 B3 46 E6 AD C3 AE 7B F7 53 E1 BC 3F B5 38 D9 88 83 B3 12 5B 5A 40 8E 21 63 16 40 D5 D1 E8 63 ");
6704
6705 let mut recovered1 = String::new();
6706 let mut recovered2 = String::new();
6707 c_des.decrypt_array_into_string(iv, &cipher1, &mut recovered1);
6708 d_des.decrypt_array_into_string(iv, &cipher2, &mut recovered2);
6709 println!("B1 (0 rounds) =\t{}", recovered1);
6710 println!("B2 (0 rounds) =\t{}", recovered2);
6711 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6712 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6713 assert_eq!(recovered1, message);
6714 assert_eq!(recovered2, message);
6715 assert_eq!(recovered1, recovered2);
6716 println!();
6717
6718 // Normal case for the message of 0 bytes
6719 let key = 0x_1234567890ABCDEF_u64;
6720 println!("K =\t{:#016X}", key);
6721 let mut a_des = DES::new_with_key_u64(key);
6722
6723 let message = "";
6724 println!("M =\t{}", message);
6725 let iv = 0x_FEDCBA0987654321_u64;
6726 println!("IV = {}", iv);
6727 let mut cipher = [0_u8; 0];
6728 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6729 print!("C =\t");
6730 for c in cipher.clone()
6731 { print!("{:02X} ", c); }
6732 println!();
6733 let mut txt = String::new();
6734 for c in cipher.clone()
6735 { write!(txt, "{:02X} ", c); }
6736 assert_eq!(txt, "");
6737
6738 let mut recovered = String::new();
6739 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6740 println!("B =\t{}", recovered);
6741 assert_eq!(recovered, "");
6742 assert_eq!(recovered, message);
6743 println!();
6744
6745 // Normal case for the message shorter than 8 bytes
6746 let key = 0x_1234567890ABCDEF_u64;
6747 println!("K =\t{:#016X}", key);
6748 let mut a_des = DES::new_with_key_u64(key);
6749
6750 let message = "7 bytes";
6751 println!("M =\t{}", message);
6752 let iv = 0x_FEDCBA0987654321_u64;
6753 println!("IV = {}", iv);
6754 let mut cipher = [0_u8; 7];
6755 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6756 print!("C =\t");
6757 for c in cipher.clone()
6758 { print!("{:02X} ", c); }
6759 println!();
6760 let mut txt = String::new();
6761 for c in cipher.clone()
6762 { write!(txt, "{:02X} ", c); }
6763 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
6764
6765 let mut recovered = String::new();
6766 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6767 println!("B =\t{}", recovered);
6768 assert_eq!(recovered, "7 bytes");
6769 assert_eq!(recovered, message);
6770 println!();
6771
6772 // Normal case for the message of 8 bytes
6773 let key = 0x_1234567890ABCDEF_u64;
6774 println!("K =\t{:#016X}", key);
6775 let mut a_des = DES::new_with_key_u64(key);
6776
6777 let message = "I am OK.";
6778 println!("M =\t{}", message);
6779 let iv = 0x_FEDCBA0987654321_u64;
6780 println!("IV = {}", iv);
6781 let mut cipher = [0_u8; 8];
6782 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6783 print!("C =\t");
6784 for c in cipher.clone()
6785 { print!("{:02X} ", c); }
6786 println!();
6787 let mut txt = String::new();
6788 for c in cipher.clone()
6789 { write!(txt, "{:02X} ", c); }
6790 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
6791
6792 let mut recovered = String::new();
6793 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6794 println!("B =\t{}", recovered);
6795 assert_eq!(recovered, "I am OK.");
6796 assert_eq!(recovered, message);
6797 println!();
6798
6799 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6800 let key = 0x_1234567890ABCDEF_u64;
6801 println!("K =\t{:#016X}", key);
6802 let mut a_des = DES::new_with_key_u64(key);
6803
6804 let message = "PARK Youngho";
6805 println!("M =\t{}", message);
6806 let iv = 0x_FEDCBA0987654321_u64;
6807 println!("IV = {}", iv);
6808 let mut cipher = [0_u8; 12];
6809 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6810 print!("C =\t");
6811 for c in cipher.clone()
6812 { print!("{:02X} ", c); }
6813 println!();
6814 let mut txt = String::new();
6815 for c in cipher.clone()
6816 { write!(txt, "{:02X} ", c); }
6817 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 74 F9 B6 4F ");
6818
6819 let mut recovered = String::new();
6820 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6821 println!("B =\t{}", recovered);
6822 assert_eq!(recovered, "PARK Youngho");
6823 assert_eq!(recovered, message);
6824 println!();
6825
6826 // Normal case for the message of 16 bytes
6827 let key = 0x_1234567890ABCDEF_u64;
6828 println!("K =\t{:#016X}", key);
6829 let mut a_des = DES::new_with_key_u64(key);
6830
6831 let message = "고맙습니다.";
6832 println!("M =\t{}", message);
6833 let iv = 0x_FEDCBA0987654321_u64;
6834 println!("IV = {}", iv);
6835 let mut cipher = [0_u8; 16];
6836 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6837 print!("C =\t");
6838 for c in cipher.clone()
6839 { print!("{:02X} ", c); }
6840 println!();
6841 let mut txt = String::new();
6842 for c in cipher.clone()
6843 { write!(txt, "{:02X} ", c); }
6844 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 F4 FC 94 B5 94 1F B9 BD ");
6845
6846 let mut recovered = String::new();
6847 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6848 println!("B =\t{}", recovered);
6849 assert_eq!(recovered, "고맙습니다.");
6850 assert_eq!(recovered, message);
6851 println!("-------------------------------");
6852}54fn des_encrypt_ofb()
55{
56 println!("des_encrypt_ofb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
60
61 // Normal case
62 let key = 0x_1234567890ABCDEF_u64;
63 println!("K =\t{:#016X}", key);
64 let mut a_des = DES::new_with_key_u64(key);
65
66 let message = "In the beginning God created the heavens and the earth.";
67 println!("M =\t{}", message);
68 let iv = 0x_FEDCBA0987654321_u64;
69 println!("IV = {}", iv);
70 let mut cipher = [0_u8; 55];
71 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
72 print!("C (16 rounds) =\t");
73 for c in cipher.clone()
74 { print!("{:02X} ", c); }
75 println!();
76 let mut txt = String::new();
77 for c in cipher.clone()
78 { write!(txt, "{:02X} ", c); }
79 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
80 println!();
81
82 // Expanded case for 128 rounds
83 let key = 0x_1234567890ABCDEF_u64;
84 println!("K =\t{:#016X}", key);
85 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
86
87 let message = "In the beginning God created the heavens and the earth.";
88 println!("M =\t{}", message);
89
90 let iv = 0x_FEDCBA0987654321_u64;
91 println!("IV = {}", iv);
92 let mut cipher = [0_u8; 55];
93 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
94 print!("C (128 rounds) =\t");
95 for c in cipher.clone()
96 { print!("{:02X} ", c); }
97 println!();
98 let mut txt = String::new();
99 for c in cipher.clone()
100 { write!(txt, "{:02X} ", c); }
101 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
102 println!();
103
104 // Expanded case for 0 rounds which means that key is meaningless
105 let key1 = 0x_1234567890ABCDEF_u64;
106 let key2 = 0_u64;
107 println!("K =\t{:#016X}", key);
108 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
109 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
110
111 let message = "In the beginning God created the heavens and the earth.";
112 println!("M =\t{}", message);
113 let iv = 0x_FEDCBA0987654321_u64;
114 println!("IV = {}", iv);
115 let mut cipher1 = [0_u8; 55];
116 let mut cipher2 = [0_u8; 55];
117 c_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher1.as_mut_ptr());
118 d_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher2.as_mut_ptr());
119 print!("C (0 rounds) =\t");
120 for c in cipher1.clone()
121 { print!("{:02X} ", c); }
122 println!();
123 let mut txt = String::new();
124 for c in cipher1.clone()
125 { write!(txt, "{:02X} ", c); }
126 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
127 print!("D (0 rounds) =\t");
128 for c in cipher2.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher2.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
135 println!();
136
137 // Normal case for the message of 0 bytes
138 let key = 0x_1234567890ABCDEF_u64;
139 println!("K =\t{:#016X}", key);
140 let mut a_des = DES::new_with_key_u64(key);
141
142 let message = "";
143 println!("M =\t{}", message);
144 let iv = 0x_FEDCBA0987654321_u64;
145 println!("IV = {}", iv);
146 let mut cipher = [0_u8; 0];
147 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
148 print!("C =\t");
149 for c in cipher.clone()
150 { print!("{:02X} ", c); }
151 println!();
152 let mut txt = String::new();
153 for c in cipher.clone()
154 { write!(txt, "{:02X} ", c); }
155 assert_eq!(txt, "");
156 println!();
157
158 // Normal case for the message shorter than 8 bytes
159 let key = 0x_1234567890ABCDEF_u64;
160 println!("K =\t{:#016X}", key);
161 let mut a_des = DES::new_with_key_u64(key);
162
163 let message = "7 bytes";
164 println!("M =\t{}", message);
165 let iv = 0x_FEDCBA0987654321_u64;
166 println!("IV = {}", iv);
167 let mut cipher = [0_u8; 7];
168 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
169 print!("C =\t");
170 for c in cipher.clone()
171 { print!("{:02X} ", c); }
172 println!();
173 let mut txt = String::new();
174 for c in cipher.clone()
175 { write!(txt, "{:02X} ", c); }
176 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
177 println!();
178
179 // Normal case for the message of 8 bytes
180 let key = 0x_1234567890ABCDEF_u64;
181 println!("K =\t{:#016X}", key);
182 let mut a_des = DES::new_with_key_u64(key);
183
184 let message = "I am OK.";
185 println!("M =\t{}", message);
186 let iv = 0x_FEDCBA0987654321_u64;
187 println!("IV = {}", iv);
188 let mut cipher = [0_u8; 8];
189 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
190 print!("C =\t");
191 for c in cipher.clone()
192 { print!("{:02X} ", c); }
193 println!();
194 let mut txt = String::new();
195 for c in cipher.clone()
196 { write!(txt, "{:02X} ", c); }
197 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
198 println!();
199
200 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
201 let key = 0x_1234567890ABCDEF_u64;
202 println!("K =\t{:#016X}", key);
203 let mut a_des = DES::new_with_key_u64(key);
204
205 let message = "PARK Youngho";
206 println!("M =\t{}", message);
207 let iv = 0x_FEDCBA0987654321_u64;
208 println!("IV = {}", iv);
209 let mut cipher = [0_u8; 12];
210 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
211 print!("C =\t");
212 for c in cipher.clone()
213 { print!("{:02X} ", c); }
214 println!();
215 let mut txt = String::new();
216 for c in cipher.clone()
217 { write!(txt, "{:02X} ", c); }
218 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
219 println!();
220
221 // Normal case for the message of 16 bytes
222 let key = 0x_1234567890ABCDEF_u64;
223 println!("K =\t{:#016X}", key);
224 let mut a_des = DES::new_with_key_u64(key);
225
226 let message = "고맙습니다.";
227 println!("M =\t{}", message);
228 let iv = 0x_FEDCBA0987654321_u64;
229 println!("IV = {}", iv);
230 let mut cipher = [0_u8; 16];
231 a_des.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
232 print!("C =\t");
233 for c in cipher.clone()
234 { print!("{:02X} ", c); }
235 println!();
236 let mut txt = String::new();
237 for c in cipher.clone()
238 { write!(txt, "{:02X} ", c); }
239 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
240 println!("-------------------------------");
241}
242
243fn des_encrypt_ofb_into_vec()
244{
245 println!("des_encrypt_ofb_into_vec()");
246 use std::io::Write;
247 use std::fmt::Write as _;
248 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
249
250 // Normal case
251 let key = 0x_1234567890ABCDEF_u64;
252 println!("K =\t{:#016X}", key);
253 let mut a_des = DES::new_with_key_u64(key);
254
255 let message = "In the beginning God created the heavens and the earth.";
256 println!("M =\t{}", message);
257 let iv = 0x_FEDCBA0987654321_u64;
258 println!("IV = {}", iv);
259 let mut cipher = Vec::<u8>::new();
260 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
261 print!("C (16 rounds) =\t");
262 for c in cipher.clone()
263 { print!("{:02X} ", c); }
264 println!();
265 let mut txt = String::new();
266 for c in cipher.clone()
267 { write!(txt, "{:02X} ", c); }
268 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
269 println!();
270
271 // Expanded case for 128 rounds
272 let key = 0x_1234567890ABCDEF_u64;
273 println!("K =\t{:#016X}", key);
274 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
275
276 let message = "In the beginning God created the heavens and the earth.";
277 println!("M =\t{}", message);
278 let iv = 0x_FEDCBA0987654321_u64;
279 println!("IV = {}", iv);
280 let mut cipher = Vec::<u8>::new();
281 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
282 print!("C (128 rounds) =\t");
283 for c in cipher.clone()
284 { print!("{:02X} ", c); }
285 println!();
286 let mut txt = String::new();
287 for c in cipher.clone()
288 { write!(txt, "{:02X} ", c); }
289 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
290 println!();
291
292 // Expanded case for 0 rounds which means that key is meaningless
293 let key1 = 0x_1234567890ABCDEF_u64;
294 let key2 = 0_u64;
295 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
296 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
297 println!("K =\t{:#016X}", key);
298
299 let message = "In the beginning God created the heavens and the earth.";
300 println!("M =\t{}", message);
301 let iv = 0x_FEDCBA0987654321_u64;
302 println!("IV = {}", iv);
303 let mut cipher1 = Vec::<u8>::new();
304 let mut cipher2 = Vec::<u8>::new();
305 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
306 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
307 print!("C (0 rounds) =\t");
308 for c in cipher1.clone()
309 { print!("{:02X} ", c); }
310 println!();
311 let mut txt = String::new();
312 for c in cipher1.clone()
313 { write!(txt, "{:02X} ", c); }
314 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
315 print!("D (0 rounds) =\t");
316 for c in cipher2.clone()
317 { print!("{:02X} ", c); }
318 println!();
319 let mut txt = String::new();
320 for c in cipher2.clone()
321 { write!(txt, "{:02X} ", c); }
322 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
323 println!();
324
325 // Normal case for the message of 0 bytes
326 let key = 0x_1234567890ABCDEF_u64;
327 println!("K =\t{:#016X}", key);
328 let mut a_des = DES::new_with_key_u64(key);
329
330 let message = "";
331 println!("M =\t{}", message);
332 let iv = 0x_FEDCBA0987654321_u64;
333 println!("IV = {}", iv);
334 let mut cipher = Vec::<u8>::new();
335 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
336 print!("C =\t");
337 for c in cipher.clone()
338 { print!("{:02X} ", c); }
339 println!();
340 let mut txt = String::new();
341 for c in cipher.clone()
342 { write!(txt, "{:02X} ", c); }
343 assert_eq!(txt, "");
344 println!();
345
346 // Normal case for the message shorter than 8 bytes
347 let key = 0x_1234567890ABCDEF_u64;
348 println!("K =\t{:#016X}", key);
349 let mut a_des = DES::new_with_key_u64(key);
350
351 let message = "7 bytes";
352 println!("M =\t{}", message);
353 let iv = 0x_FEDCBA0987654321_u64;
354 println!("IV = {}", iv);
355 let mut cipher = Vec::<u8>::new();
356 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
357 print!("C =\t");
358 for c in cipher.clone()
359 { print!("{:02X} ", c); }
360 println!();
361 let mut txt = String::new();
362 for c in cipher.clone()
363 { write!(txt, "{:02X} ", c); }
364 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
365 println!();
366
367 // Normal case for the message of 8 bytes
368 let key = 0x_1234567890ABCDEF_u64;
369 println!("K =\t{:#016X}", key);
370 let mut a_des = DES::new_with_key_u64(key);
371
372 let message = "I am OK.";
373 println!("M =\t{}", message);
374 let iv = 0x_FEDCBA0987654321_u64;
375 println!("IV = {}", iv);
376 let mut cipher = Vec::<u8>::new();
377 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
378 print!("C =\t");
379 for c in cipher.clone()
380 { print!("{:02X} ", c); }
381 println!();
382 let mut txt = String::new();
383 for c in cipher.clone()
384 { write!(txt, "{:02X} ", c); }
385 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
386 println!();
387
388 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
389 let key = 0x_1234567890ABCDEF_u64;
390 println!("K =\t{:#016X}", key);
391 let mut a_des = DES::new_with_key_u64(key);
392
393 let message = "PARK Youngho";
394 println!("M =\t{}", message);
395 let iv = 0x_FEDCBA0987654321_u64;
396 println!("IV = {}", iv);
397 let mut cipher = Vec::<u8>::new();
398 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
399 print!("C =\t");
400 for c in cipher.clone()
401 { print!("{:02X} ", c); }
402 println!();
403 let mut txt = String::new();
404 for c in cipher.clone()
405 { write!(txt, "{:02X} ", c); }
406 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
407 println!();
408
409 // Normal case for the message of 16 bytes
410 let key = 0x_1234567890ABCDEF_u64;
411 println!("K =\t{:#016X}", key);
412 let mut a_des = DES::new_with_key_u64(key);
413
414 let message = "고맙습니다.";
415 println!("M =\t{}", message);
416 let iv = 0x_FEDCBA0987654321_u64;
417 println!("IV = {}", iv);
418 let mut cipher = Vec::<u8>::new();
419 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
420 print!("C =\t");
421 for c in cipher.clone()
422 { print!("{:02X} ", c); }
423 println!();
424 let mut txt = String::new();
425 for c in cipher.clone()
426 { write!(txt, "{:02X} ", c); }
427 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
428 println!("-------------------------------");
429}
430
431fn des_encrypt_ofb_into_array()
432{
433 println!("des_encrypt_ofb_into_array()");
434 use std::io::Write;
435 use std::fmt::Write as _;
436 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
437
438 // Normal case
439 let key = 0x_1234567890ABCDEF_u64;
440 println!("K =\t{:#016X}", key);
441 let mut a_des = DES::new_with_key_u64(key);
442
443 let message = "In the beginning God created the heavens and the earth.";
444 println!("M =\t{}", message);
445 let iv = 0x_FEDCBA0987654321_u64;
446 println!("IV = {}", iv);
447 let mut cipher = [0_u8; 55];
448 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
449 print!("C (16 rounds) =\t");
450 for c in cipher.clone()
451 { print!("{:02X} ", c); }
452 println!();
453 let mut txt = String::new();
454 for c in cipher.clone()
455 { write!(txt, "{:02X} ", c); }
456 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
457 println!();
458
459 // Expanded case for 128 rounds
460 let key = 0x_1234567890ABCDEF_u64;
461 println!("K =\t{:#016X}", key);
462 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
463
464 let message = "In the beginning God created the heavens and the earth.";
465 println!("M =\t{}", message);
466 let iv = 0x_FEDCBA0987654321_u64;
467 println!("IV = {}", iv);
468 let mut cipher = [0_u8; 55];
469 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
470 print!("C (128 rounds) =\t");
471 for c in cipher.clone()
472 { print!("{:02X} ", c); }
473 println!();
474 let mut txt = String::new();
475 for c in cipher.clone()
476 { write!(txt, "{:02X} ", c); }
477 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
478 println!();
479
480 // Expanded case for 0 rounds which means that key is meaningless
481 let key1 = 0x_1234567890ABCDEF_u64;
482 let key2 = 0_u64;
483 println!("K =\t{:#016X}", key);
484 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
485 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
486
487 let message = "In the beginning God created the heavens and the earth.";
488 println!("M =\t{}", message);
489 let iv = 0x_FEDCBA0987654321_u64;
490 println!("IV = {}", iv);
491 let mut cipher1 = [0_u8; 55];
492 let mut cipher2 = [0_u8; 55];
493 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
494 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
495 print!("C (0 rounds) =\t");
496 for c in cipher1.clone()
497 { print!("{:02X} ", c); }
498 println!();
499 let mut txt = String::new();
500 for c in cipher1.clone()
501 { write!(txt, "{:02X} ", c); }
502 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
503 print!("D (0 rounds) =\t");
504 for c in cipher2.clone()
505 { print!("{:02X} ", c); }
506 println!();
507 let mut txt = String::new();
508 for c in cipher2.clone()
509 { write!(txt, "{:02X} ", c); }
510 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
511 println!();
512
513 // Normal case for the message of 0 bytes
514 let key = 0x_1234567890ABCDEF_u64;
515 println!("K =\t{:#016X}", key);
516 let mut a_des = DES::new_with_key_u64(key);
517
518 let message = "";
519 println!("M =\t{}", message);
520 let iv = 0x_FEDCBA0987654321_u64;
521 println!("IV = {}", iv);
522 let mut cipher = [0_u8; 0];
523 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
524 print!("C =\t");
525 for c in cipher.clone()
526 { print!("{:02X} ", c); }
527 println!();
528 let mut txt = String::new();
529 for c in cipher.clone()
530 { write!(txt, "{:02X} ", c); }
531 assert_eq!(txt, "");
532 println!();
533
534 // Normal case for the message shorter than 8 bytes
535 let key = 0x_1234567890ABCDEF_u64;
536 println!("K =\t{:#016X}", key);
537 let mut a_des = DES::new_with_key_u64(key);
538
539 let message = "7 bytes";
540 println!("M =\t{}", message);
541 let iv = 0x_FEDCBA0987654321_u64;
542 println!("IV = {}", iv);
543 let mut cipher = [0_u8; 7];
544 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
545 print!("C =\t");
546 for c in cipher.clone()
547 { print!("{:02X} ", c); }
548 println!();
549 let mut txt = String::new();
550 for c in cipher.clone()
551 { write!(txt, "{:02X} ", c); }
552 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
553 println!();
554
555 // Normal case for the message of 8 bytes
556 let key = 0x_1234567890ABCDEF_u64;
557 println!("K =\t{:#016X}", key);
558 let mut a_des = DES::new_with_key_u64(key);
559
560 let message = "I am OK.";
561 println!("M =\t{}", message);
562 let iv = 0x_FEDCBA0987654321_u64;
563 println!("IV = {}", iv);
564 let mut cipher = [0_u8; 8];
565 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
566 print!("C =\t");
567 for c in cipher.clone()
568 { print!("{:02X} ", c); }
569 println!();
570 let mut txt = String::new();
571 for c in cipher.clone()
572 { write!(txt, "{:02X} ", c); }
573 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
574 println!();
575
576 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
577 let key = 0x_1234567890ABCDEF_u64;
578 println!("K =\t{:#016X}", key);
579 let mut a_des = DES::new_with_key_u64(key);
580
581 let message = "PARK Youngho";
582 println!("M =\t{}", message);
583 let iv = 0x_FEDCBA0987654321_u64;
584 println!("IV = {}", iv);
585 let mut cipher = [0_u8; 12];
586 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
587 print!("C =\t");
588 for c in cipher.clone()
589 { print!("{:02X} ", c); }
590 println!();
591 let mut txt = String::new();
592 for c in cipher.clone()
593 { write!(txt, "{:02X} ", c); }
594 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
595 println!();
596
597 // Normal case for the message of 16 bytes
598 let key = 0x_1234567890ABCDEF_u64;
599 println!("K =\t{:#016X}", key);
600 let mut a_des = DES::new_with_key_u64(key);
601
602 let message = "고맙습니다.";
603 println!("M =\t{}", message);
604 let iv = 0x_FEDCBA0987654321_u64;
605 println!("IV = {}", iv);
606 let mut cipher = [0_u8; 16];
607 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
608 print!("C =\t");
609 for c in cipher.clone()
610 { print!("{:02X} ", c); }
611 println!();
612 let mut txt = String::new();
613 for c in cipher.clone()
614 { write!(txt, "{:02X} ", c); }
615 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
616 println!("-------------------------------");
617}
618
619fn des_encrypt_str_ofb()
620{
621 println!("des_encrypt_str_ofb()");
622 use std::io::Write;
623 use std::fmt::Write as _;
624 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
625
626 // Normal case
627 let key = 0x_1234567890ABCDEF_u64;
628 println!("K =\t{:#016X}", key);
629 let mut a_des = DES::new_with_key_u64(key);
630
631 let message = "In the beginning God created the heavens and the earth.";
632 println!("M =\t{}", message);
633 let iv = 0x_FEDCBA0987654321_u64;
634 println!("IV = {}", iv);
635 let mut cipher = [0_u8; 55];
636 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
637 print!("C (16 rounds) =\t");
638 for c in cipher.clone()
639 { print!("{:02X} ", c); }
640 println!();
641 let mut txt = String::new();
642 for c in cipher.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
645 println!();
646
647 // Expanded case for 128 rounds
648 let key = 0x_1234567890ABCDEF_u64;
649 println!("K =\t{:#016X}", key);
650 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
651
652 let message = "In the beginning God created the heavens and the earth.";
653 println!("M =\t{}", message);
654 let iv = 0x_FEDCBA0987654321_u64;
655 println!("IV = {}", iv);
656 let mut cipher = [0_u8; 55];
657 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
658 print!("C (128 rounds) =\t");
659 for c in cipher.clone()
660 { print!("{:02X} ", c); }
661 println!();
662 let mut txt = String::new();
663 for c in cipher.clone()
664 { write!(txt, "{:02X} ", c); }
665 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
666 println!();
667
668 // Expanded case for 0 rounds which means that key is meaningless
669 let key1 = 0x_1234567890ABCDEF_u64;
670 let key2 = 0_u64;
671 println!("K =\t{:#016X}", key);
672 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
673 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
674
675 let message = "In the beginning God created the heavens and the earth.";
676 println!("M =\t{}", message);
677 let iv = 0x_FEDCBA0987654321_u64;
678 println!("IV = {}", iv);
679 let mut cipher1 = [0_u8; 55];
680 let mut cipher2 = [0_u8; 55];
681 c_des.encrypt_str(iv, &message, cipher1.as_mut_ptr());
682 d_des.encrypt_str(iv, &message, cipher2.as_mut_ptr());
683 print!("C (0 rounds) =\t");
684 for c in cipher1.clone()
685 { print!("{:02X} ", c); }
686 println!();
687 let mut txt = String::new();
688 for c in cipher1.clone()
689 { write!(txt, "{:02X} ", c); }
690 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
691 print!("D (0 rounds) =\t");
692 for c in cipher2.clone()
693 { print!("{:02X} ", c); }
694 println!();
695 let mut txt = String::new();
696 for c in cipher2.clone()
697 { write!(txt, "{:02X} ", c); }
698 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
699 println!();
700
701 // Normal case for the message of 0 bytes
702 let key = 0x_1234567890ABCDEF_u64;
703 println!("K =\t{:#016X}", key);
704 let mut a_des = DES::new_with_key_u64(key);
705
706 let message = "";
707 println!("M =\t{}", message);
708 let iv = 0x_FEDCBA0987654321_u64;
709 println!("IV = {}", iv);
710 let mut cipher = [0_u8; 0];
711 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "");
720 println!();
721
722 // Normal case for the message shorter than 8 bytes
723 let key = 0x_1234567890ABCDEF_u64;
724 println!("K =\t{:#016X}", key);
725 let mut a_des = DES::new_with_key_u64(key);
726
727 let message = "7 bytes";
728 println!("M =\t{}", message);
729 let iv = 0x_FEDCBA0987654321_u64;
730 println!("IV = {}", iv);
731 let mut cipher = [0_u8; 7];
732 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
733 print!("C =\t");
734 for c in cipher.clone()
735 { print!("{:02X} ", c); }
736 println!();
737 let mut txt = String::new();
738 for c in cipher.clone()
739 { write!(txt, "{:02X} ", c); }
740 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
741 println!();
742
743 // Normal case for the message of 8 bytes
744 let key = 0x_1234567890ABCDEF_u64;
745 println!("K =\t{:#016X}", key);
746 let mut a_des = DES::new_with_key_u64(key);
747
748 let message = "I am OK.";
749 println!("M =\t{}", message);
750 let iv = 0x_FEDCBA0987654321_u64;
751 println!("IV = {}", iv);
752 let mut cipher = [0_u8; 8];
753 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
754 print!("C =\t");
755 for c in cipher.clone()
756 { print!("{:02X} ", c); }
757 println!();
758 let mut txt = String::new();
759 for c in cipher.clone()
760 { write!(txt, "{:02X} ", c); }
761 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
762 println!();
763
764 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
765 let key = 0x_1234567890ABCDEF_u64;
766 println!("K =\t{:#016X}", key);
767 let mut a_des = DES::new_with_key_u64(key);
768
769 let message = "PARK Youngho";
770 println!("M =\t{}", message);
771 let iv = 0x_FEDCBA0987654321_u64;
772 println!("IV = {}", iv);
773 let mut cipher = [0_u8; 12];
774 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
775 print!("C =\t");
776 for c in cipher.clone()
777 { print!("{:02X} ", c); }
778 println!();
779 let mut txt = String::new();
780 for c in cipher.clone()
781 { write!(txt, "{:02X} ", c); }
782 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
783 println!();
784
785 // Normal case for the message of 16 bytes
786 let key = 0x_1234567890ABCDEF_u64;
787 println!("K =\t{:#016X}", key);
788 let mut a_des = DES::new_with_key_u64(key);
789
790 let message = "고맙습니다.";
791 println!("M =\t{}", message);
792 let iv = 0x_FEDCBA0987654321_u64;
793 println!("IV = {}", iv);
794 let mut cipher = [0_u8; 16];
795 a_des.encrypt_str(iv, &message, cipher.as_mut_ptr());
796 print!("C =\t");
797 for c in cipher.clone()
798 { print!("{:02X} ", c); }
799 println!();
800 let mut txt = String::new();
801 for c in cipher.clone()
802 { write!(txt, "{:02X} ", c); }
803 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
804 println!("-------------------------------");
805}
806
807fn des_encrypt_str_ofb_into_vec()
808{
809 println!("des_encrypt_str_ofb_into_vec()");
810 use std::io::Write;
811 use std::fmt::Write as _;
812 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
813
814 // Normal case
815 let key = 0x_1234567890ABCDEF_u64;
816 println!("K =\t{:#016X}", key);
817 let mut a_des = DES::new_with_key_u64(key);
818
819 let message = "In the beginning God created the heavens and the earth.";
820 println!("M =\t{}", message);
821 let iv = 0x_FEDCBA0987654321_u64;
822 println!("IV = {}", iv);
823 let mut cipher = Vec::<u8>::new();
824 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
825 print!("C (16 rounds) =\t");
826 for c in cipher.clone()
827 { print!("{:02X} ", c); }
828 println!();
829 let mut txt = String::new();
830 for c in cipher.clone()
831 { write!(txt, "{:02X} ", c); }
832 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
833 println!();
834
835 // Expanded case for 128 rounds
836 let key = 0x_1234567890ABCDEF_u64;
837 println!("K =\t{:#016X}", key);
838 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
839
840 let message = "In the beginning God created the heavens and the earth.";
841 println!("M =\t{}", message);
842 let iv = 0x_FEDCBA0987654321_u64;
843 println!("IV = {}", iv);
844 let mut cipher = Vec::<u8>::new();
845 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
846 print!("C (128 rounds) =\t");
847 for c in cipher.clone()
848 { print!("{:02X} ", c); }
849 println!();
850 let mut txt = String::new();
851 for c in cipher.clone()
852 { write!(txt, "{:02X} ", c); }
853 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
854 println!();
855
856 // Expanded case for 0 rounds which means that key is meaningless
857 let key1 = 0x_1234567890ABCDEF_u64;
858 let key2 = 0_u64;
859 println!("K =\t{:#016X}", key);
860 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
861 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
862
863 let message = "In the beginning God created the heavens and the earth.";
864 println!("M =\t{}", message);
865 let iv = 0x_FEDCBA0987654321_u64;
866 println!("IV = {}", iv);
867 let mut cipher1 = Vec::<u8>::new();
868 let mut cipher2 = Vec::<u8>::new();
869 c_des.encrypt_str_into_vec(iv, &message, &mut cipher1);
870 d_des.encrypt_str_into_vec(iv, &message, &mut cipher2);
871 print!("C (0 rounds) =\t");
872 for c in cipher1.clone()
873 { print!("{:02X} ", c); }
874 println!();
875 let mut txt = String::new();
876 for c in cipher1.clone()
877 { write!(txt, "{:02X} ", c); }
878 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
879 print!("D (0 rounds) =\t");
880 for c in cipher2.clone()
881 { print!("{:02X} ", c); }
882 println!();
883 let mut txt = String::new();
884 for c in cipher2.clone()
885 { write!(txt, "{:02X} ", c); }
886 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
887 println!();
888
889 // Normal case for the message of 0 bytes
890 let key = 0x_1234567890ABCDEF_u64;
891 println!("K =\t{:#016X}", key);
892 let mut a_des = DES::new_with_key_u64(key);
893
894 let message = "";
895 println!("M =\t{}", message);
896 let iv = 0x_FEDCBA0987654321_u64;
897 println!("IV = {}", iv);
898 let mut cipher = Vec::<u8>::new();
899 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
900 print!("C =\t");
901 for c in cipher.clone()
902 { print!("{:02X} ", c); }
903 println!();
904 let mut txt = String::new();
905 for c in cipher.clone()
906 { write!(txt, "{:02X} ", c); }
907 assert_eq!(txt, "");
908 println!();
909
910 // Normal case for the message shorter than 8 bytes
911 let key = 0x_1234567890ABCDEF_u64;
912 println!("K =\t{:#016X}", key);
913 let mut a_des = DES::new_with_key_u64(key);
914
915 let message = "7 bytes";
916 println!("M =\t{}", message);
917 let iv = 0x_FEDCBA0987654321_u64;
918 println!("IV = {}", iv);
919 let mut cipher = Vec::<u8>::new();
920 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
921 print!("C =\t");
922 for c in cipher.clone()
923 { print!("{:02X} ", c); }
924 println!();
925 let mut txt = String::new();
926 for c in cipher.clone()
927 { write!(txt, "{:02X} ", c); }
928 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
929 println!();
930
931 // Normal case for the message of 8 bytes
932 let key = 0x_1234567890ABCDEF_u64;
933 println!("K =\t{:#016X}", key);
934 let mut a_des = DES::new_with_key_u64(key);
935
936 let message = "I am OK.";
937 println!("M =\t{}", message);
938 let iv = 0x_FEDCBA0987654321_u64;
939 println!("IV = {}", iv);
940 let mut cipher = Vec::<u8>::new();
941 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
942 print!("C =\t");
943 for c in cipher.clone()
944 { print!("{:02X} ", c); }
945 println!();
946 let mut txt = String::new();
947 for c in cipher.clone()
948 { write!(txt, "{:02X} ", c); }
949 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
950 println!();
951
952 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
953 let key = 0x_1234567890ABCDEF_u64;
954 println!("K =\t{:#016X}", key);
955 let mut a_des = DES::new_with_key_u64(key);
956
957 let message = "PARK Youngho";
958 println!("M =\t{}", message);
959 let iv = 0x_FEDCBA0987654321_u64;
960 println!("IV = {}", iv);
961 let mut cipher = Vec::<u8>::new();
962 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
963 print!("C =\t");
964 for c in cipher.clone()
965 { print!("{:02X} ", c); }
966 println!();
967 let mut txt = String::new();
968 for c in cipher.clone()
969 { write!(txt, "{:02X} ", c); }
970 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
971 println!();
972
973 // Normal case for the message of 16 bytes
974 let key = 0x_1234567890ABCDEF_u64;
975 println!("K =\t{:#016X}", key);
976 let mut a_des = DES::new_with_key_u64(key);
977
978 let message = "고맙습니다.";
979 println!("M =\t{}", message);
980 let iv = 0x_FEDCBA0987654321_u64;
981 println!("IV = {}", iv);
982 let mut cipher = Vec::<u8>::new();
983 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
984 print!("C =\t");
985 for c in cipher.clone()
986 { print!("{:02X} ", c); }
987 println!();
988 let mut txt = String::new();
989 for c in cipher.clone()
990 { write!(txt, "{:02X} ", c); }
991 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
992 println!("-------------------------------");
993}
994
995fn des_encrypt_str_ofb_into_array()
996{
997 println!("des_encrypt_str_ofb_into_array()");
998 use std::io::Write;
999 use std::fmt::Write as _;
1000 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
1001
1002 // Normal case
1003 let key = 0x_1234567890ABCDEF_u64;
1004 println!("K =\t{:#016X}", key);
1005 let mut a_des = DES::new_with_key_u64(key);
1006
1007 let message = "In the beginning God created the heavens and the earth.";
1008 println!("M =\t{}", message);
1009 let iv = 0x_FEDCBA0987654321_u64;
1010 println!("IV = {}", iv);
1011 let mut cipher = [0_u8; 55];
1012 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1013 print!("C (16 rounds) =\t");
1014 for c in cipher.clone()
1015 { print!("{:02X} ", c); }
1016 println!();
1017 let mut txt = String::new();
1018 for c in cipher.clone()
1019 { write!(txt, "{:02X} ", c); }
1020 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
1021 println!();
1022
1023 // Expanded case for 128 rounds
1024 let key = 0x_1234567890ABCDEF_u64;
1025 println!("K =\t{:#016X}", key);
1026 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1027
1028 let message = "In the beginning God created the heavens and the earth.";
1029 println!("M =\t{}", message);
1030 let iv = 0x_FEDCBA0987654321_u64;
1031 println!("IV = {}", iv);
1032 let mut cipher = [0_u8; 55];
1033 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1034 print!("C (128 rounds) =\t");
1035 for c in cipher.clone()
1036 { print!("{:02X} ", c); }
1037 println!();
1038 let mut txt = String::new();
1039 for c in cipher.clone()
1040 { write!(txt, "{:02X} ", c); }
1041 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
1042 println!();
1043
1044 // Expanded case for 0 rounds which means that key is meaningless
1045 let key1 = 0x_1234567890ABCDEF_u64;
1046 let key2 = 0_u64;
1047 println!("K =\t{:#016X}", key);
1048 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1049 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1050
1051 let message = "In the beginning God created the heavens and the earth.";
1052 println!("M =\t{}", message);
1053 let iv = 0x_FEDCBA0987654321_u64;
1054 println!("IV = {}", iv);
1055 let mut cipher1 = [0_u8; 55];
1056 let mut cipher2 = [0_u8; 55];
1057 c_des.encrypt_str_into_array(iv, &message, &mut cipher1);
1058 d_des.encrypt_str_into_array(iv, &message, &mut cipher2);
1059 print!("C (0 rounds) =\t");
1060 for c in cipher1.clone()
1061 { print!("{:02X} ", c); }
1062 println!();
1063 let mut txt = String::new();
1064 for c in cipher1.clone()
1065 { write!(txt, "{:02X} ", c); }
1066 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1067 print!("D (0 rounds) =\t");
1068 for c in cipher2.clone()
1069 { print!("{:02X} ", c); }
1070 println!();
1071 let mut txt = String::new();
1072 for c in cipher2.clone()
1073 { write!(txt, "{:02X} ", c); }
1074 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1075 println!();
1076
1077 // Normal case for the message of 0 bytes
1078 let key = 0x_1234567890ABCDEF_u64;
1079 println!("K =\t{:#016X}", key);
1080 let mut a_des = DES::new_with_key_u64(key);
1081
1082 let message = "";
1083 println!("M =\t{}", message);
1084 let iv = 0x_FEDCBA0987654321_u64;
1085 println!("IV = {}", iv);
1086 let mut cipher = [0_u8; 0];
1087 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1088 print!("C =\t");
1089 for c in cipher.clone()
1090 { print!("{:02X} ", c); }
1091 println!();
1092 let mut txt = String::new();
1093 for c in cipher.clone()
1094 { write!(txt, "{:02X} ", c); }
1095 assert_eq!(txt, "");
1096 println!();
1097
1098 // Normal case for the message shorter than 8 bytes
1099 let key = 0x_1234567890ABCDEF_u64;
1100 println!("K =\t{:#016X}", key);
1101 let mut a_des = DES::new_with_key_u64(key);
1102
1103 let message = "7 bytes";
1104 println!("M =\t{}", message);
1105 let iv = 0x_FEDCBA0987654321_u64;
1106 println!("IV = {}", iv);
1107 let mut cipher = [0_u8; 7];
1108 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1109 print!("C =\t");
1110 for c in cipher.clone()
1111 { print!("{:02X} ", c); }
1112 println!();
1113 let mut txt = String::new();
1114 for c in cipher.clone()
1115 { write!(txt, "{:02X} ", c); }
1116 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1117 println!();
1118
1119 // Normal case for the message of 8 bytes
1120 let key = 0x_1234567890ABCDEF_u64;
1121 println!("K =\t{:#016X}", key);
1122 let mut a_des = DES::new_with_key_u64(key);
1123
1124 let message = "I am OK.";
1125 println!("M =\t{}", message);
1126 let iv = 0x_FEDCBA0987654321_u64;
1127 println!("IV = {}", iv);
1128 let mut cipher = [0_u8; 8];
1129 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1130 print!("C =\t");
1131 for c in cipher.clone()
1132 { print!("{:02X} ", c); }
1133 println!();
1134 let mut txt = String::new();
1135 for c in cipher.clone()
1136 { write!(txt, "{:02X} ", c); }
1137 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1138 println!();
1139
1140 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1141 let key = 0x_1234567890ABCDEF_u64;
1142 println!("K =\t{:#016X}", key);
1143 let mut a_des = DES::new_with_key_u64(key);
1144
1145 let message = "PARK Youngho";
1146 println!("M =\t{}", message);
1147 let iv = 0x_FEDCBA0987654321_u64;
1148 println!("IV = {}", iv);
1149 let mut cipher = [0_u8; 12];
1150 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1151 print!("C =\t");
1152 for c in cipher.clone()
1153 { print!("{:02X} ", c); }
1154 println!();
1155 let mut txt = String::new();
1156 for c in cipher.clone()
1157 { write!(txt, "{:02X} ", c); }
1158 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
1159 println!();
1160
1161 // Normal case for the message of 16 bytes
1162 let key = 0x_1234567890ABCDEF_u64;
1163 println!("K =\t{:#016X}", key);
1164 let mut a_des = DES::new_with_key_u64(key);
1165
1166 let message = "고맙습니다.";
1167 println!("M =\t{}", message);
1168 let iv = 0x_FEDCBA0987654321_u64;
1169 println!("IV = {}", iv);
1170 let mut cipher = [0_u8; 16];
1171 a_des.encrypt_str_into_array(iv, &message, &mut cipher);
1172 print!("C =\t");
1173 for c in cipher.clone()
1174 { print!("{:02X} ", c); }
1175 println!();
1176 let mut txt = String::new();
1177 for c in cipher.clone()
1178 { write!(txt, "{:02X} ", c); }
1179 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
1180 println!("-------------------------------");
1181}
1182
1183fn des_encrypt_string_ofb()
1184{
1185 println!("des_encrypt_string_ofb()");
1186 use std::io::Write;
1187 use std::fmt::Write as _;
1188 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
1189
1190 // Normal case
1191 let key = 0x_1234567890ABCDEF_u64;
1192 println!("K =\t{:#016X}", key);
1193 let mut a_des = DES::new_with_key_u64(key);
1194
1195 let message = "In the beginning God created the heavens and the earth.".to_string();
1196 println!("M =\t{}", message);
1197 let iv = 0x_FEDCBA0987654321_u64;
1198 println!("IV = {}", iv);
1199 let mut cipher = [0_u8; 55];
1200 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1201 print!("C (16 rounds) =\t");
1202 for c in cipher.clone()
1203 { print!("{:02X} ", c); }
1204 println!();
1205 let mut txt = String::new();
1206 for c in cipher.clone()
1207 { write!(txt, "{:02X} ", c); }
1208 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
1209 println!();
1210
1211 // Expanded case for 128 rounds
1212 let key = 0x_1234567890ABCDEF_u64;
1213 println!("K =\t{:#016X}", key);
1214 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1215
1216 let message = "In the beginning God created the heavens and the earth.".to_string();
1217 println!("M =\t{}", message);
1218 let iv = 0x_FEDCBA0987654321_u64;
1219 println!("IV = {}", iv);
1220 let mut cipher = [0_u8; 55];
1221 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1222 print!("C (128 rounds) =\t");
1223 for c in cipher.clone()
1224 { print!("{:02X} ", c); }
1225 println!();
1226 let mut txt = String::new();
1227 for c in cipher.clone()
1228 { write!(txt, "{:02X} ", c); }
1229 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
1230 println!();
1231
1232 // Expanded case for 0 rounds which means that key is meaningless
1233 let key1 = 0x_1234567890ABCDEF_u64;
1234 let key2 = 0_u64;
1235 println!("K =\t{:#016X}", key);
1236 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1237 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1238
1239 let message = "In the beginning God created the heavens and the earth.".to_string();
1240 println!("M =\t{}", message);
1241 let iv = 0x_FEDCBA0987654321_u64;
1242 println!("IV = {}", iv);
1243 let mut cipher1 = [0_u8; 55];
1244 let mut cipher2 = [0_u8; 55];
1245 c_des.encrypt_string(iv, &message, cipher1.as_mut_ptr());
1246 d_des.encrypt_string(iv, &message, cipher2.as_mut_ptr());
1247 print!("C (0 rounds) =\t");
1248 for c in cipher1.clone()
1249 { print!("{:02X} ", c); }
1250 println!();
1251 let mut txt = String::new();
1252 for c in cipher1.clone()
1253 { write!(txt, "{:02X} ", c); }
1254 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1255 print!("D (0 rounds) =\t");
1256 for c in cipher2.clone()
1257 { print!("{:02X} ", c); }
1258 println!();
1259 let mut txt = String::new();
1260 for c in cipher2.clone()
1261 { write!(txt, "{:02X} ", c); }
1262 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1263 println!();
1264
1265 // Normal case for the message of 0 bytes
1266 let key = 0x_1234567890ABCDEF_u64;
1267 println!("K =\t{:#016X}", key);
1268 let mut a_des = DES::new_with_key_u64(key);
1269
1270 let message = "".to_string();
1271 println!("M =\t{}", message);
1272 let iv = 0x_FEDCBA0987654321_u64;
1273 println!("IV = {}", iv);
1274 let mut cipher = [0_u8; 0];
1275 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1276 print!("C =\t");
1277 for c in cipher.clone()
1278 { print!("{:02X} ", c); }
1279 println!();
1280 let mut txt = String::new();
1281 for c in cipher.clone()
1282 { write!(txt, "{:02X} ", c); }
1283 assert_eq!(txt, "");
1284 println!();
1285
1286 // Normal case for the message shorter than 8 bytes
1287 let key = 0x_1234567890ABCDEF_u64;
1288 println!("K =\t{:#016X}", key);
1289 let mut a_des = DES::new_with_key_u64(key);
1290
1291 let message = "7 bytes".to_string();
1292 println!("M =\t{}", message);
1293 let iv = 0x_FEDCBA0987654321_u64;
1294 println!("IV = {}", iv);
1295 let mut cipher = [0_u8; 7];
1296 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1297 print!("C =\t");
1298 for c in cipher.clone()
1299 { print!("{:02X} ", c); }
1300 println!();
1301 let mut txt = String::new();
1302 for c in cipher.clone()
1303 { write!(txt, "{:02X} ", c); }
1304 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1305 println!();
1306
1307 // Normal case for the message of 8 bytes
1308 let key = 0x_1234567890ABCDEF_u64;
1309 println!("K =\t{:#016X}", key);
1310 let mut a_des = DES::new_with_key_u64(key);
1311
1312 let message = "I am OK.".to_string();
1313 println!("M =\t{}", message);
1314 let iv = 0x_FEDCBA0987654321_u64;
1315 println!("IV = {}", iv);
1316 let mut cipher = [0_u8; 8];
1317 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1318 print!("C =\t");
1319 for c in cipher.clone()
1320 { print!("{:02X} ", c); }
1321 println!();
1322 let mut txt = String::new();
1323 for c in cipher.clone()
1324 { write!(txt, "{:02X} ", c); }
1325 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1326 println!();
1327
1328 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1329 let key = 0x_1234567890ABCDEF_u64;
1330 println!("K =\t{:#016X}", key);
1331 let mut a_des = DES::new_with_key_u64(key);
1332
1333 let message = "PARK Youngho".to_string();
1334 println!("M =\t{}", message);
1335 let iv = 0x_FEDCBA0987654321_u64;
1336 println!("IV = {}", iv);
1337 let mut cipher = [0_u8; 12];
1338 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1339 print!("C =\t");
1340 for c in cipher.clone()
1341 { print!("{:02X} ", c); }
1342 println!();
1343 let mut txt = String::new();
1344 for c in cipher.clone()
1345 { write!(txt, "{:02X} ", c); }
1346 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
1347 println!();
1348
1349 // Normal case for the message of 16 bytes
1350 let key = 0x_1234567890ABCDEF_u64;
1351 println!("K =\t{:#016X}", key);
1352 let mut a_des = DES::new_with_key_u64(key);
1353
1354 let message = "고맙습니다.".to_string();
1355 println!("M =\t{}", message);
1356 let iv = 0x_FEDCBA0987654321_u64;
1357 println!("IV = {}", iv);
1358 let mut cipher = [0_u8; 16];
1359 a_des.encrypt_string(iv, &message, cipher.as_mut_ptr());
1360 print!("C =\t");
1361 for c in cipher.clone()
1362 { print!("{:02X} ", c); }
1363 println!();
1364 let mut txt = String::new();
1365 for c in cipher.clone()
1366 { write!(txt, "{:02X} ", c); }
1367 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
1368 println!("-------------------------------");
1369}
1370
1371fn des_encrypt_string_ofb_into_vec()
1372{
1373 println!("des_encrypt_string_ofb_into_vec()");
1374 use std::io::Write;
1375 use std::fmt::Write as _;
1376 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
1377
1378 // Normal case
1379 let key = 0x_1234567890ABCDEF_u64;
1380 println!("K =\t{:#016X}", key);
1381 let mut a_des = DES::new_with_key_u64(key);
1382
1383 let message = "In the beginning God created the heavens and the earth.".to_string();
1384 println!("M =\t{}", message);
1385 let iv = 0x_FEDCBA0987654321_u64;
1386 println!("IV = {}", iv);
1387 let mut cipher = Vec::<u8>::new();
1388 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1389 print!("C (16 rounds) =\t");
1390 for c in cipher.clone()
1391 { print!("{:02X} ", c); }
1392 println!();
1393 let mut txt = String::new();
1394 for c in cipher.clone()
1395 { write!(txt, "{:02X} ", c); }
1396 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
1397 println!();
1398
1399 // Expanded case for 128 rounds
1400 let key = 0x_1234567890ABCDEF_u64;
1401 println!("K =\t{:#016X}", key);
1402 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1403
1404 let message = "In the beginning God created the heavens and the earth.".to_string();
1405 println!("M =\t{}", message);
1406 let iv = 0x_FEDCBA0987654321_u64;
1407 println!("IV = {}", iv);
1408 let mut cipher = Vec::<u8>::new();
1409 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1410 print!("C (128 rounds) =\t");
1411 for c in cipher.clone()
1412 { print!("{:02X} ", c); }
1413 println!();
1414 let mut txt = String::new();
1415 for c in cipher.clone()
1416 { write!(txt, "{:02X} ", c); }
1417 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
1418 println!();
1419
1420 // Expanded case for 0 rounds which means that key is meaningless
1421 let key1 = 0x_1234567890ABCDEF_u64;
1422 let key2 = 0_u64;
1423 println!("K =\t{:#016X}", key);
1424 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1425 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1426
1427 let message = "In the beginning God created the heavens and the earth.".to_string();
1428 println!("M =\t{}", message);
1429 let iv = 0x_FEDCBA0987654321_u64;
1430 println!("IV = {}", iv);
1431 let mut cipher1 = Vec::<u8>::new();
1432 let mut cipher2 = Vec::<u8>::new();
1433 c_des.encrypt_string_into_vec(iv, &message, &mut cipher1);
1434 d_des.encrypt_string_into_vec(iv, &message, &mut cipher2);
1435 print!("C (0 rounds) =\t");
1436 for c in cipher1.clone()
1437 { print!("{:02X} ", c); }
1438 println!();
1439 let mut txt = String::new();
1440 for c in cipher1.clone()
1441 { write!(txt, "{:02X} ", c); }
1442 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1443 print!("D (0 rounds) =\t");
1444 for c in cipher2.clone()
1445 { print!("{:02X} ", c); }
1446 println!();
1447 let mut txt = String::new();
1448 for c in cipher2.clone()
1449 { write!(txt, "{:02X} ", c); }
1450 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1451 println!();
1452
1453 // Normal case for the message of 0 bytes
1454 let key = 0x_1234567890ABCDEF_u64;
1455 println!("K =\t{:#016X}", key);
1456 let mut a_des = DES::new_with_key_u64(key);
1457
1458 let message = "".to_string();
1459 println!("M =\t{}", message);
1460 let iv = 0x_FEDCBA0987654321_u64;
1461 println!("IV = {}", iv);
1462 let mut cipher = Vec::<u8>::new();
1463 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1464 print!("C =\t");
1465 for c in cipher.clone()
1466 { print!("{:02X} ", c); }
1467 println!();
1468 let mut txt = String::new();
1469 for c in cipher.clone()
1470 { write!(txt, "{:02X} ", c); }
1471 assert_eq!(txt, "");
1472 println!();
1473
1474 // Normal case for the message shorter than 8 bytes
1475 let key = 0x_1234567890ABCDEF_u64;
1476 println!("K =\t{:#016X}", key);
1477 let mut a_des = DES::new_with_key_u64(key);
1478
1479 let message = "7 bytes".to_string();
1480 println!("M =\t{}", message);
1481 let iv = 0x_FEDCBA0987654321_u64;
1482 println!("IV = {}", iv);
1483 let mut cipher = Vec::<u8>::new();
1484 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1485 print!("C =\t");
1486 for c in cipher.clone()
1487 { print!("{:02X} ", c); }
1488 println!();
1489 let mut txt = String::new();
1490 for c in cipher.clone()
1491 { write!(txt, "{:02X} ", c); }
1492 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1493 println!();
1494
1495 // Normal case for the message of 8 bytes
1496 let key = 0x_1234567890ABCDEF_u64;
1497 println!("K =\t{:#016X}", key);
1498 let mut a_des = DES::new_with_key_u64(key);
1499
1500 let message = "I am OK.".to_string();
1501 println!("M =\t{}", message);
1502 let iv = 0x_FEDCBA0987654321_u64;
1503 println!("IV = {}", iv);
1504 let mut cipher = Vec::<u8>::new();
1505 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1506 print!("C =\t");
1507 for c in cipher.clone()
1508 { print!("{:02X} ", c); }
1509 println!();
1510 let mut txt = String::new();
1511 for c in cipher.clone()
1512 { write!(txt, "{:02X} ", c); }
1513 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1514 println!();
1515
1516 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1517 let key = 0x_1234567890ABCDEF_u64;
1518 println!("K =\t{:#016X}", key);
1519 let mut a_des = DES::new_with_key_u64(key);
1520
1521 let message = "PARK Youngho".to_string();
1522 println!("M =\t{}", message);
1523 let iv = 0x_FEDCBA0987654321_u64;
1524 println!("IV = {}", iv);
1525 let mut cipher = Vec::<u8>::new();
1526 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1527 print!("C =\t");
1528 for c in cipher.clone()
1529 { print!("{:02X} ", c); }
1530 println!();
1531 let mut txt = String::new();
1532 for c in cipher.clone()
1533 { write!(txt, "{:02X} ", c); }
1534 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
1535 println!();
1536
1537 // Normal case for the message of 16 bytes
1538 let key = 0x_1234567890ABCDEF_u64;
1539 println!("K =\t{:#016X}", key);
1540 let mut a_des = DES::new_with_key_u64(key);
1541
1542 let message = "고맙습니다.".to_string();
1543 println!("M =\t{}", message);
1544 let iv = 0x_FEDCBA0987654321_u64;
1545 println!("IV = {}", iv);
1546 let mut cipher = Vec::<u8>::new();
1547 a_des.encrypt_string_into_vec(iv, &message, &mut cipher);
1548 print!("C =\t");
1549 for c in cipher.clone()
1550 { print!("{:02X} ", c); }
1551 println!();
1552 let mut txt = String::new();
1553 for c in cipher.clone()
1554 { write!(txt, "{:02X} ", c); }
1555 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
1556 println!("-------------------------------");
1557}
1558
1559fn des_encrypt_string_ofb_into_array()
1560{
1561 println!("des_encrypt_string_ofb_into_array()");
1562 use std::io::Write;
1563 use std::fmt::Write as _;
1564 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
1565
1566 // Normal case
1567 let key = 0x_1234567890ABCDEF_u64;
1568 println!("K =\t{:#016X}", key);
1569 let mut a_des = DES::new_with_key_u64(key);
1570
1571 let message = "In the beginning God created the heavens and the earth.".to_string();
1572 println!("M =\t{}", message);
1573 let iv = 0x_FEDCBA0987654321_u64;
1574 println!("IV = {}", iv);
1575 let mut cipher = [0_u8; 55];
1576 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1577 print!("C (16 rounds) =\t");
1578 for c in cipher.clone()
1579 { print!("{:02X} ", c); }
1580 println!();
1581 let mut txt = String::new();
1582 for c in cipher.clone()
1583 { write!(txt, "{:02X} ", c); }
1584 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
1585 println!();
1586
1587 // Expanded case for 128 rounds
1588 let key = 0x_1234567890ABCDEF_u64;
1589 println!("K =\t{:#016X}", key);
1590 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1591
1592 let message = "In the beginning God created the heavens and the earth.".to_string();
1593 println!("M =\t{}", message);
1594 let iv = 0x_FEDCBA0987654321_u64;
1595 println!("IV = {}", iv);
1596 let mut cipher = [0_u8; 55];
1597 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1598 print!("C (128 rounds) =\t");
1599 for c in cipher.clone()
1600 { print!("{:02X} ", c); }
1601 println!();
1602 let mut txt = String::new();
1603 for c in cipher.clone()
1604 { write!(txt, "{:02X} ", c); }
1605 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
1606 println!();
1607
1608 // Expanded case for 0 rounds which means that key is meaningless
1609 let key1 = 0x_1234567890ABCDEF_u64;
1610 let key2 = 0_u64;
1611 println!("K =\t{:#016X}", key);
1612 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1613 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1614
1615 let message = "In the beginning God created the heavens and the earth.".to_string();
1616 println!("M =\t{}", message);
1617 let iv = 0x_FEDCBA0987654321_u64;
1618 println!("IV = {}", iv);
1619 let mut cipher1 = [0_u8; 55];
1620 let mut cipher2 = [0_u8; 55];
1621 c_des.encrypt_string_into_array(iv, &message, &mut cipher1);
1622 d_des.encrypt_string_into_array(iv, &message, &mut cipher2);
1623 print!("C (0 rounds) =\t");
1624 for c in cipher1.clone()
1625 { print!("{:02X} ", c); }
1626 println!();
1627 let mut txt = String::new();
1628 for c in cipher1.clone()
1629 { write!(txt, "{:02X} ", c); }
1630 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1631 print!("D (0 rounds) =\t");
1632 for c in cipher2.clone()
1633 { print!("{:02X} ", c); }
1634 println!();
1635 let mut txt = String::new();
1636 for c in cipher2.clone()
1637 { write!(txt, "{:02X} ", c); }
1638 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1639 println!();
1640
1641 // Normal case for the message of 0 bytes
1642 let key = 0x_1234567890ABCDEF_u64;
1643 println!("K =\t{:#016X}", key);
1644 let mut a_des = DES::new_with_key_u64(key);
1645
1646 let message = "".to_string();
1647 println!("M =\t{}", message);
1648 let iv = 0x_FEDCBA0987654321_u64;
1649 println!("IV = {}", iv);
1650 let mut cipher = [0_u8; 0];
1651 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1652 print!("C =\t");
1653 for c in cipher.clone()
1654 { print!("{:02X} ", c); }
1655 println!();
1656 let mut txt = String::new();
1657 for c in cipher.clone()
1658 { write!(txt, "{:02X} ", c); }
1659 assert_eq!(txt, "");
1660 println!();
1661
1662 // Normal case for the message shorter than 8 bytes
1663 let key = 0x_1234567890ABCDEF_u64;
1664 println!("K =\t{:#016X}", key);
1665 let mut a_des = DES::new_with_key_u64(key);
1666
1667 let message = "7 bytes".to_string();
1668 println!("M =\t{}", message);
1669 let iv = 0x_FEDCBA0987654321_u64;
1670 println!("IV = {}", iv);
1671 let mut cipher = [0_u8; 7];
1672 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1673 print!("C =\t");
1674 for c in cipher.clone()
1675 { print!("{:02X} ", c); }
1676 println!();
1677 let mut txt = String::new();
1678 for c in cipher.clone()
1679 { write!(txt, "{:02X} ", c); }
1680 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1681 println!();
1682
1683 // Normal case for the message of 8 bytes
1684 let key = 0x_1234567890ABCDEF_u64;
1685 println!("K =\t{:#016X}", key);
1686 let mut a_des = DES::new_with_key_u64(key);
1687
1688 let message = "I am OK.".to_string();
1689 println!("M =\t{}", message);
1690 let iv = 0x_FEDCBA0987654321_u64;
1691 println!("IV = {}", iv);
1692 let mut cipher = [0_u8; 8];
1693 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1694 print!("C =\t");
1695 for c in cipher.clone()
1696 { print!("{:02X} ", c); }
1697 println!();
1698 let mut txt = String::new();
1699 for c in cipher.clone()
1700 { write!(txt, "{:02X} ", c); }
1701 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1702 println!();
1703
1704 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1705 let key = 0x_1234567890ABCDEF_u64;
1706 println!("K =\t{:#016X}", key);
1707 let mut a_des = DES::new_with_key_u64(key);
1708
1709 let message = "PARK Youngho".to_string();
1710 println!("M =\t{}", message);
1711 let iv = 0x_FEDCBA0987654321_u64;
1712 println!("IV = {}", iv);
1713 let mut cipher = [0_u8; 12];
1714 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1715 print!("C =\t");
1716 for c in cipher.clone()
1717 { print!("{:02X} ", c); }
1718 println!();
1719 let mut txt = String::new();
1720 for c in cipher.clone()
1721 { write!(txt, "{:02X} ", c); }
1722 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
1723 println!();
1724
1725 // Normal case for the message of 16 bytes
1726 let key = 0x_1234567890ABCDEF_u64;
1727 println!("K =\t{:#016X}", key);
1728 let mut a_des = DES::new_with_key_u64(key);
1729
1730 let message = "고맙습니다.".to_string();
1731 println!("M =\t{}", message);
1732 let iv = 0x_FEDCBA0987654321_u64;
1733 println!("IV = {}", iv);
1734 let mut cipher = [0_u8; 16];
1735 a_des.encrypt_string_into_array(iv, &message, &mut cipher);
1736 print!("C =\t");
1737 for c in cipher.clone()
1738 { print!("{:02X} ", c); }
1739 println!();
1740 let mut txt = String::new();
1741 for c in cipher.clone()
1742 { write!(txt, "{:02X} ", c); }
1743 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
1744 println!("-------------------------------");
1745}
1746
1747fn des_encrypt_vec_ofb()
1748{
1749 println!("des_encrypt_vec_ofb()");
1750 use std::io::Write;
1751 use std::fmt::Write as _;
1752 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
1753
1754 // Normal case
1755 let key = 0x_1234567890ABCDEF_u64;
1756 println!("K =\t{:#016X}", key);
1757 let mut a_des = DES::new_with_key_u64(key);
1758
1759 let message = "In the beginning God created the heavens and the earth.";
1760 println!("M =\t{}", message);
1761 let message = unsafe { message.to_string().as_mut_vec().clone() };
1762 let iv = 0x_FEDCBA0987654321_u64;
1763 println!("IV = {}", iv);
1764 let mut cipher = [0_u8; 55];
1765 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1766 print!("C (16 rounds) =\t");
1767 for c in cipher.clone()
1768 { print!("{:02X} ", c); }
1769 println!();
1770 let mut txt = String::new();
1771 for c in cipher.clone()
1772 { write!(txt, "{:02X} ", c); }
1773 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
1774 println!();
1775
1776 // Expanded case for 128 rounds
1777 let key = 0x_1234567890ABCDEF_u64;
1778 println!("K =\t{:#016X}", key);
1779 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1780
1781 let message = "In the beginning God created the heavens and the earth.";
1782 println!("M =\t{}", message);
1783 let message = unsafe { message.to_string().as_mut_vec().clone() };
1784 let iv = 0x_FEDCBA0987654321_u64;
1785 println!("IV = {}", iv);
1786 let mut cipher = [0_u8; 55];
1787 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1788 print!("C (128 rounds) =\t");
1789 for c in cipher.clone()
1790 { print!("{:02X} ", c); }
1791 println!();
1792 let mut txt = String::new();
1793 for c in cipher.clone()
1794 { write!(txt, "{:02X} ", c); }
1795 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
1796 println!();
1797
1798 // Expanded case for 0 rounds which means that key is meaningless
1799 let key1 = 0x_1234567890ABCDEF_u64;
1800 let key2 = 0_u64;
1801 println!("K1 =\t{:#016X}", key1);
1802 println!("K2 =\t{:#016X}", key2);
1803 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1804 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1805
1806 let message = "In the beginning God created the heavens and the earth.";
1807 println!("M =\t{}", message);
1808 let message = unsafe { message.to_string().as_mut_vec().clone() };
1809 let iv = 0x_FEDCBA0987654321_u64;
1810 println!("IV = {}", iv);
1811 let mut cipher1 = [0_u8; 55];
1812 let mut cipher2 = [0_u8; 55];
1813 c_des.encrypt_vec(iv, &message, cipher1.as_mut_ptr());
1814 d_des.encrypt_vec(iv, &message, cipher2.as_mut_ptr());
1815 print!("C (0 rounds) =\t");
1816 for c in cipher1.clone()
1817 { print!("{:02X} ", c); }
1818 println!();
1819 let mut txt = String::new();
1820 for c in cipher1.clone()
1821 { write!(txt, "{:02X} ", c); }
1822 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1823 print!("D (0 rounds) =\t");
1824 for c in cipher2.clone()
1825 { print!("{:02X} ", c); }
1826 println!();
1827 let mut txt = String::new();
1828 for c in cipher2.clone()
1829 { write!(txt, "{:02X} ", c); }
1830 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
1831 println!();
1832
1833 // Normal case for the message of 0 bytes
1834 let key = 0x_1234567890ABCDEF_u64;
1835 println!("K =\t{:#016X}", key);
1836 let mut a_des = DES::new_with_key_u64(key);
1837
1838 let message = "";
1839 println!("M =\t{}", message);
1840 let message = unsafe { message.to_string().as_mut_vec().clone() };
1841 let iv = 0x_FEDCBA0987654321_u64;
1842 println!("IV = {}", iv);
1843 let mut cipher = [0_u8; 0];
1844 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1845 print!("C =\t");
1846 for c in cipher.clone()
1847 { print!("{:02X} ", c); }
1848 println!();
1849 let mut txt = String::new();
1850 for c in cipher.clone()
1851 { write!(txt, "{:02X} ", c); }
1852 assert_eq!(txt, "");
1853 println!();
1854
1855 // Normal case for the message shorter than 8 bytes
1856 let key = 0x_1234567890ABCDEF_u64;
1857 println!("K =\t{:#016X}", key);
1858 let mut a_des = DES::new_with_key_u64(key);
1859
1860 let message = "7 bytes";
1861 println!("M =\t{}", message);
1862 let message = unsafe { message.to_string().as_mut_vec().clone() };
1863 let iv = 0x_FEDCBA0987654321_u64;
1864 println!("IV = {}", iv);
1865 let mut cipher = [0_u8; 7];
1866 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1867 print!("C =\t");
1868 for c in cipher.clone()
1869 { print!("{:02X} ", c); }
1870 println!();
1871 let mut txt = String::new();
1872 for c in cipher.clone()
1873 { write!(txt, "{:02X} ", c); }
1874 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
1875 println!();
1876
1877 // Normal case for the message of 8 bytes
1878 let key = 0x_1234567890ABCDEF_u64;
1879 println!("K =\t{:#016X}", key);
1880 let mut a_des = DES::new_with_key_u64(key);
1881
1882 let message = "I am OK.";
1883 println!("M =\t{}", message);
1884 let message = unsafe { message.to_string().as_mut_vec().clone() };
1885 let iv = 0x_FEDCBA0987654321_u64;
1886 println!("IV = {}", iv);
1887 let mut cipher = [0_u8; 8];
1888 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1889 print!("C =\t");
1890 for c in cipher.clone()
1891 { print!("{:02X} ", c); }
1892 println!();
1893 let mut txt = String::new();
1894 for c in cipher.clone()
1895 { write!(txt, "{:02X} ", c); }
1896 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
1897 println!();
1898
1899 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1900 let key = 0x_1234567890ABCDEF_u64;
1901 println!("K =\t{:#016X}", key);
1902 let mut a_des = DES::new_with_key_u64(key);
1903
1904 let message = "PARK Youngho";
1905 println!("M =\t{}", message);
1906 let message = unsafe { message.to_string().as_mut_vec().clone() };
1907 let iv = 0x_FEDCBA0987654321_u64;
1908 println!("IV = {}", iv);
1909 let mut cipher = [0_u8; 12];
1910 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1911 print!("C =\t");
1912 for c in cipher.clone()
1913 { print!("{:02X} ", c); }
1914 println!();
1915 let mut txt = String::new();
1916 for c in cipher.clone()
1917 { write!(txt, "{:02X} ", c); }
1918 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
1919 println!();
1920
1921 // Normal case for the message of 16 bytes
1922 let key = 0x_1234567890ABCDEF_u64;
1923 println!("K =\t{:#016X}", key);
1924 let mut a_des = DES::new_with_key_u64(key);
1925
1926 let message = "고맙습니다.";
1927 println!("M =\t{}", message);
1928 let message = unsafe { message.to_string().as_mut_vec().clone() };
1929 let iv = 0x_FEDCBA0987654321_u64;
1930 println!("IV = {}", iv);
1931 let mut cipher = [0_u8; 16];
1932 a_des.encrypt_vec(iv, &message, cipher.as_mut_ptr());
1933 print!("C =\t");
1934 for c in cipher.clone()
1935 { print!("{:02X} ", c); }
1936 println!();
1937 let mut txt = String::new();
1938 for c in cipher.clone()
1939 { write!(txt, "{:02X} ", c); }
1940 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
1941 println!("-------------------------------");
1942}
1943
1944fn des_encrypt_vec_ofb_into_vec()
1945{
1946 println!("des_encrypt_vec_ofb_into_vec()");
1947 use std::io::Write;
1948 use std::fmt::Write as _;
1949 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
1950
1951 // Normal case
1952 let key = 0x_1234567890ABCDEF_u64;
1953 println!("K =\t{:#016X}", key);
1954 let mut a_des = DES::new_with_key_u64(key);
1955
1956 let message = "In the beginning God created the heavens and the earth.";
1957 println!("M =\t{}", message);
1958 let message = unsafe { message.to_string().as_mut_vec().clone() };
1959 let iv = 0x_FEDCBA0987654321_u64;
1960 println!("IV = {}", iv);
1961 let mut cipher = Vec::<u8>::new();
1962 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
1963 print!("C (16 rounds) =\t");
1964 for c in cipher.clone()
1965 { print!("{:02X} ", c); }
1966 println!();
1967 let mut txt = String::new();
1968 for c in cipher.clone()
1969 { write!(txt, "{:02X} ", c); }
1970 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
1971 println!();
1972
1973 // Expanded case for 128 rounds
1974 let key = 0x_1234567890ABCDEF_u64;
1975 println!("K =\t{:#016X}", key);
1976 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1977
1978 let message = "In the beginning God created the heavens and the earth.";
1979 println!("M =\t{}", message);
1980 let message = unsafe { message.to_string().as_mut_vec().clone() };
1981 let iv = 0x_FEDCBA0987654321_u64;
1982 println!("IV = {}", iv);
1983 let mut cipher = Vec::<u8>::new();
1984 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
1985 print!("C (128 rounds) =\t");
1986 for c in cipher.clone()
1987 { print!("{:02X} ", c); }
1988 println!();
1989 let mut txt = String::new();
1990 for c in cipher.clone()
1991 { write!(txt, "{:02X} ", c); }
1992 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
1993 println!();
1994
1995 // Expanded case for 0 rounds which means that key is meaningless
1996 let key1 = 0x_1234567890ABCDEF_u64;
1997 let key2 = 0_u64;
1998 println!("K1 =\t{:#016X}", key1);
1999 println!("K2 =\t{:#016X}", key2);
2000 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2001 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2002
2003 let message = "In the beginning God created the heavens and the earth.";
2004 println!("M =\t{}", message);
2005 let message = unsafe { message.to_string().as_mut_vec().clone() };
2006
2007 let iv = 0x_FEDCBA0987654321_u64;
2008 println!("IV = {}", iv);
2009 let mut cipher1 = Vec::<u8>::new();
2010 let mut cipher2 = Vec::<u8>::new();
2011 c_des.encrypt_vec_into_vec(iv, &message, &mut cipher1);
2012 d_des.encrypt_vec_into_vec(iv, &message, &mut cipher2);
2013 print!("C (0 rounds) =\t");
2014 for c in cipher1.clone()
2015 { print!("{:02X} ", c); }
2016 println!();
2017 let mut txt = String::new();
2018 for c in cipher1.clone()
2019 { write!(txt, "{:02X} ", c); }
2020 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2021 print!("D (0 rounds) =\t");
2022 for c in cipher2.clone()
2023 { print!("{:02X} ", c); }
2024 println!();
2025 let mut txt = String::new();
2026 for c in cipher2.clone()
2027 { write!(txt, "{:02X} ", c); }
2028 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2029 println!();
2030
2031 // Normal case for the message of 0 bytes
2032 let key = 0x_1234567890ABCDEF_u64;
2033 println!("K =\t{:#016X}", key);
2034 let mut a_des = DES::new_with_key_u64(key);
2035
2036 let message = "";
2037 println!("M =\t{}", message);
2038 let message = unsafe { message.to_string().as_mut_vec().clone() };
2039 let iv = 0x_FEDCBA0987654321_u64;
2040 println!("IV = {}", iv);
2041 let mut cipher = Vec::<u8>::new();
2042 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2043 print!("C =\t");
2044 for c in cipher.clone()
2045 { print!("{:02X} ", c); }
2046 println!();
2047 let mut txt = String::new();
2048 for c in cipher.clone()
2049 { write!(txt, "{:02X} ", c); }
2050 assert_eq!(txt, "");
2051 println!();
2052
2053 // Normal case for the message shorter than 8 bytes
2054 let key = 0x_1234567890ABCDEF_u64;
2055 println!("K =\t{:#016X}", key);
2056 let mut a_des = DES::new_with_key_u64(key);
2057
2058 let message = "7 bytes";
2059 println!("M =\t{}", message);
2060 let message = unsafe { message.to_string().as_mut_vec().clone() };
2061 let iv = 0x_FEDCBA0987654321_u64;
2062 println!("IV = {}", iv);
2063 let mut cipher = Vec::<u8>::new();
2064 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2065 print!("C =\t");
2066 for c in cipher.clone()
2067 { print!("{:02X} ", c); }
2068 println!();
2069 let mut txt = String::new();
2070 for c in cipher.clone()
2071 { write!(txt, "{:02X} ", c); }
2072 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2073 println!();
2074
2075 // Normal case for the message of 8 bytes
2076 let key = 0x_1234567890ABCDEF_u64;
2077 println!("K =\t{:#016X}", key);
2078 let mut a_des = DES::new_with_key_u64(key);
2079
2080 let message = "I am OK.";
2081 println!("M =\t{}", message);
2082 let message = unsafe { message.to_string().as_mut_vec().clone() };
2083 let iv = 0x_FEDCBA0987654321_u64;
2084 println!("IV = {}", iv);
2085 let mut cipher = Vec::<u8>::new();
2086 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2087 print!("C =\t");
2088 for c in cipher.clone()
2089 { print!("{:02X} ", c); }
2090 println!();
2091 let mut txt = String::new();
2092 for c in cipher.clone()
2093 { write!(txt, "{:02X} ", c); }
2094 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2095 println!();
2096
2097 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2098 let key = 0x_1234567890ABCDEF_u64;
2099 println!("K =\t{:#016X}", key);
2100 let mut a_des = DES::new_with_key_u64(key);
2101
2102 let message = "PARK Youngho";
2103 println!("M =\t{}", message);
2104 let message = unsafe { message.to_string().as_mut_vec().clone() };
2105 let iv = 0x_FEDCBA0987654321_u64;
2106 println!("IV = {}", iv);
2107 let mut cipher = Vec::<u8>::new();
2108 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2109 print!("C =\t");
2110 for c in cipher.clone()
2111 { print!("{:02X} ", c); }
2112 println!();
2113 let mut txt = String::new();
2114 for c in cipher.clone()
2115 { write!(txt, "{:02X} ", c); }
2116 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
2117 println!();
2118
2119 // Normal case for the message of 16 bytes
2120 let key = 0x_1234567890ABCDEF_u64;
2121 println!("K =\t{:#016X}", key);
2122 let mut a_des = DES::new_with_key_u64(key);
2123
2124 let message = "고맙습니다.";
2125 println!("M =\t{}", message);
2126 let message = unsafe { message.to_string().as_mut_vec().clone() };
2127 let iv = 0x_FEDCBA0987654321_u64;
2128 println!("IV = {}", iv);
2129 let mut cipher = Vec::<u8>::new();
2130 a_des.encrypt_vec_into_vec(iv, &message, &mut cipher);
2131 print!("C =\t");
2132 for c in cipher.clone()
2133 { print!("{:02X} ", c); }
2134 println!();
2135 let mut txt = String::new();
2136 for c in cipher.clone()
2137 { write!(txt, "{:02X} ", c); }
2138 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
2139 println!("-------------------------------");
2140}
2141
2142fn des_encrypt_vec_ofb_into_array()
2143{
2144 println!("des_encrypt_vec_ofb_into_array()");
2145 use std::io::Write;
2146 use std::fmt::Write as _;
2147 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
2148
2149 // Normal case
2150 let key = 0x_1234567890ABCDEF_u64;
2151 println!("K =\t{:#016X}", key);
2152 let mut a_des = DES::new_with_key_u64(key);
2153
2154 let message = "In the beginning God created the heavens and the earth.";
2155 println!("M =\t{}", message);
2156 let message = unsafe { message.to_string().as_mut_vec().clone() };
2157 let iv = 0x_FEDCBA0987654321_u64;
2158 println!("IV = {}", iv);
2159 let mut cipher = [0_u8; 55];
2160 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2161 print!("C (16 rounds) =\t");
2162 for c in cipher.clone()
2163 { print!("{:02X} ", c); }
2164 println!();
2165 let mut txt = String::new();
2166 for c in cipher.clone()
2167 { write!(txt, "{:02X} ", c); }
2168 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
2169 println!();
2170
2171 // Expanded case for 128 rounds
2172 let key = 0x_1234567890ABCDEF_u64;
2173 println!("K =\t{:#016X}", key);
2174 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2175
2176 let message = "In the beginning God created the heavens and the earth.";
2177 println!("M =\t{}", message);
2178 let message = unsafe { message.to_string().as_mut_vec().clone() };
2179 let iv = 0x_FEDCBA0987654321_u64;
2180 println!("IV = {}", iv);
2181 let mut cipher = [0_u8; 55];
2182 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2183 print!("C (128 rounds) =\t");
2184 for c in cipher.clone()
2185 { print!("{:02X} ", c); }
2186 println!();
2187 let mut txt = String::new();
2188 for c in cipher.clone()
2189 { write!(txt, "{:02X} ", c); }
2190 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
2191 println!();
2192
2193 // Expanded case for 0 rounds which means that key is meaningless
2194 let key1 = 0x_1234567890ABCDEF_u64;
2195 let key2 = 0_u64;
2196 println!("K1 =\t{:#016X}", key1);
2197 println!("K2 =\t{:#016X}", key2);
2198 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2199 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2200
2201 let message = "In the beginning God created the heavens and the earth.";
2202 println!("M =\t{}", message);
2203 let message = unsafe { message.to_string().as_mut_vec().clone() };
2204 let iv = 0x_FEDCBA0987654321_u64;
2205 println!("IV = {}", iv);
2206 let mut cipher1 = [0_u8; 55];
2207 let mut cipher2 = [0_u8; 55];
2208 c_des.encrypt_vec_into_array(iv, &message, &mut cipher1);
2209 d_des.encrypt_vec_into_array(iv, &message, &mut cipher2);
2210 print!("C (0 rounds) =\t");
2211 for c in cipher1.clone()
2212 { print!("{:02X} ", c); }
2213 println!();
2214 let mut txt = String::new();
2215 for c in cipher1.clone()
2216 { write!(txt, "{:02X} ", c); }
2217 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2218 print!("D (0 rounds) =\t");
2219 for c in cipher2.clone()
2220 { print!("{:02X} ", c); }
2221 println!();
2222 let mut txt = String::new();
2223 for c in cipher2.clone()
2224 { write!(txt, "{:02X} ", c); }
2225 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2226 println!();
2227
2228 // Normal case for the message of 0 bytes
2229 let key = 0x_1234567890ABCDEF_u64;
2230 println!("K =\t{:#016X}", key);
2231 let mut a_des = DES::new_with_key_u64(key);
2232
2233 let message = "";
2234 println!("M =\t{}", message);
2235 let message = unsafe { message.to_string().as_mut_vec().clone() };
2236 let iv = 0x_FEDCBA0987654321_u64;
2237 println!("IV = {}", iv);
2238 let mut cipher = [0_u8; 0];
2239 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2240 print!("C =\t");
2241 for c in cipher.clone()
2242 { print!("{:02X} ", c); }
2243 println!();
2244 let mut txt = String::new();
2245 for c in cipher.clone()
2246 { write!(txt, "{:02X} ", c); }
2247 assert_eq!(txt, "");
2248 println!();
2249
2250 // Normal case for the message shorter than 8 bytes
2251 let key = 0x_1234567890ABCDEF_u64;
2252 println!("K =\t{:#016X}", key);
2253 let mut a_des = DES::new_with_key_u64(key);
2254
2255 let message = "7 bytes";
2256 println!("M =\t{}", message);
2257 let message = unsafe { message.to_string().as_mut_vec().clone() };
2258 let iv = 0x_FEDCBA0987654321_u64;
2259 println!("IV = {}", iv);
2260 let mut cipher = [0_u8; 7];
2261 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2262 print!("C =\t");
2263 for c in cipher.clone()
2264 { print!("{:02X} ", c); }
2265 println!();
2266 let mut txt = String::new();
2267 for c in cipher.clone()
2268 { write!(txt, "{:02X} ", c); }
2269 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2270 println!();
2271
2272 // Normal case for the message of 8 bytes
2273 let key = 0x_1234567890ABCDEF_u64;
2274 println!("K =\t{:#016X}", key);
2275 let mut a_des = DES::new_with_key_u64(key);
2276
2277 let message = "I am OK.";
2278 println!("M =\t{}", message);
2279 let message = unsafe { message.to_string().as_mut_vec().clone() };
2280 let iv = 0x_FEDCBA0987654321_u64;
2281 println!("IV = {}", iv);
2282 let mut cipher = [0_u8; 8];
2283 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2284 print!("C =\t");
2285 for c in cipher.clone()
2286 { print!("{:02X} ", c); }
2287 println!();
2288 let mut txt = String::new();
2289 for c in cipher.clone()
2290 { write!(txt, "{:02X} ", c); }
2291 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2292 println!();
2293
2294 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2295 let key = 0x_1234567890ABCDEF_u64;
2296 println!("K =\t{:#016X}", key);
2297 let mut a_des = DES::new_with_key_u64(key);
2298
2299 let message = "PARK Youngho";
2300 println!("M =\t{}", message);
2301 let message = unsafe { message.to_string().as_mut_vec().clone() };
2302 let iv = 0x_FEDCBA0987654321_u64;
2303 println!("IV = {}", iv);
2304 let mut cipher = [0_u8; 12];
2305 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2306 print!("C =\t");
2307 for c in cipher.clone()
2308 { print!("{:02X} ", c); }
2309 println!();
2310 let mut txt = String::new();
2311 for c in cipher.clone()
2312 { write!(txt, "{:02X} ", c); }
2313 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
2314 println!();
2315
2316 // Normal case for the message of 16 bytes
2317 let key = 0x_1234567890ABCDEF_u64;
2318 println!("K =\t{:#016X}", key);
2319 let mut a_des = DES::new_with_key_u64(key);
2320
2321 let message = "고맙습니다.";
2322 println!("M =\t{}", message);
2323 let message = unsafe { message.to_string().as_mut_vec().clone() };
2324 let iv = 0x_FEDCBA0987654321_u64;
2325 println!("IV = {}", iv);
2326 let mut cipher = [0_u8; 16];
2327 a_des.encrypt_vec_into_array(iv, &message, &mut cipher);
2328 print!("C =\t");
2329 for c in cipher.clone()
2330 { print!("{:02X} ", c); }
2331 println!();
2332 let mut txt = String::new();
2333 for c in cipher.clone()
2334 { write!(txt, "{:02X} ", c); }
2335 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
2336 println!("-------------------------------");
2337}
2338
2339fn des_encrypt_array_ofb()
2340{
2341 println!("des_encrypt_array_ofb()");
2342 use std::io::Write;
2343 use std::fmt::Write as _;
2344 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
2345
2346 // Normal case
2347 let key = 0x_1234567890ABCDEF_u64;
2348 println!("K =\t{:#016X}", key);
2349 let mut a_des = DES::new_with_key_u64(key);
2350
2351 let mes = "In the beginning God created the heavens and the earth.";
2352 println!("M =\t{}", mes);
2353 let mut message = [0_u8; 55];
2354 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2355 let iv = 0x_FEDCBA0987654321_u64;
2356 println!("IV = {}", iv);
2357 let mut cipher = [0_u8; 55];
2358 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2359 print!("C (16 rounds) =\t");
2360 for c in cipher.clone()
2361 { print!("{:02X} ", c); }
2362 println!();
2363 let mut txt = String::new();
2364 for c in cipher.clone()
2365 { write!(txt, "{:02X} ", c); }
2366 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
2367 println!();
2368
2369 // Expanded case for 128 rounds
2370 let key = 0x_1234567890ABCDEF_u64;
2371 println!("K =\t{:#016X}", key);
2372 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2373
2374 let mes = "In the beginning God created the heavens and the earth.";
2375 println!("M =\t{}", mes);
2376 let mut message = [0_u8; 55];
2377 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2378 let iv = 0x_FEDCBA0987654321_u64;
2379 println!("IV = {}", iv);
2380 let mut cipher = [0_u8; 55];
2381 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2382 print!("C (128 rounds) =\t");
2383 for c in cipher.clone()
2384 { print!("{:02X} ", c); }
2385 println!();
2386 let mut txt = String::new();
2387 for c in cipher.clone()
2388 { write!(txt, "{:02X} ", c); }
2389 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
2390 println!();
2391
2392 // Expanded case for 0 rounds which means that key is meaningless
2393 let key1 = 0x_1234567890ABCDEF_u64;
2394 let key2 = 0_u64;
2395 println!("K1 =\t{:#016X}", key1);
2396 println!("K2 =\t{:#016X}", key2);
2397 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2398 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2399
2400 let mes = "In the beginning God created the heavens and the earth.";
2401 println!("M =\t{}", mes);
2402 let mut message = [0_u8; 55];
2403 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2404 let iv = 0x_FEDCBA0987654321_u64;
2405 println!("IV = {}", iv);
2406 let mut cipher1 = [0_u8; 55];
2407 let mut cipher2 = [0_u8; 55];
2408 c_des.encrypt_array(iv, &message, cipher1.as_mut_ptr());
2409 d_des.encrypt_array(iv, &message, cipher2.as_mut_ptr());
2410 print!("C (0 rounds) =\t");
2411 for c in cipher1.clone()
2412 { print!("{:02X} ", c); }
2413 println!();
2414 let mut txt = String::new();
2415 for c in cipher1.clone()
2416 { write!(txt, "{:02X} ", c); }
2417 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2418 print!("D (0 rounds) =\t");
2419 for c in cipher2.clone()
2420 { print!("{:02X} ", c); }
2421 println!();
2422 let mut txt = String::new();
2423 for c in cipher2.clone()
2424 { write!(txt, "{:02X} ", c); }
2425 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2426 println!();
2427
2428 // Normal case for the message of 0 bytes
2429 let key = 0x_1234567890ABCDEF_u64;
2430 println!("K =\t{:#016X}", key);
2431 let mut a_des = DES::new_with_key_u64(key);
2432
2433 let mes = "";
2434 println!("M =\t{}", mes);
2435 let mut message = [0_u8; 0];
2436 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2437 let iv = 0x_FEDCBA0987654321_u64;
2438 println!("IV = {}", iv);
2439 let mut cipher = [0_u8; 0];
2440 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2441 print!("C =\t");
2442 for c in cipher.clone()
2443 { print!("{:02X} ", c); }
2444 println!();
2445 let mut txt = String::new();
2446 for c in cipher.clone()
2447 { write!(txt, "{:02X} ", c); }
2448 assert_eq!(txt, "");
2449 println!();
2450
2451 // Normal case for the message shorter than 8 bytes
2452 let key = 0x_1234567890ABCDEF_u64;
2453 println!("K =\t{:#016X}", key);
2454 let mut a_des = DES::new_with_key_u64(key);
2455
2456 let mes = "7 bytes";
2457 println!("M =\t{}", mes);
2458 let mut message = [0_u8; 7];
2459 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460 let iv = 0x_FEDCBA0987654321_u64;
2461 println!("IV = {}", iv);
2462 let mut cipher = [0_u8; 7];
2463 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2464 print!("C =\t");
2465 for c in cipher.clone()
2466 { print!("{:02X} ", c); }
2467 println!();
2468 let mut txt = String::new();
2469 for c in cipher.clone()
2470 { write!(txt, "{:02X} ", c); }
2471 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2472 println!();
2473
2474 // Normal case for the message of 8 bytes
2475 let key = 0x_1234567890ABCDEF_u64;
2476 println!("K =\t{:#016X}", key);
2477 let mut a_des = DES::new_with_key_u64(key);
2478
2479 let mes = "I am OK.";
2480 println!("M =\t{}", mes);
2481 let mut message = [0_u8; 8];
2482 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2483 let iv = 0x_FEDCBA0987654321_u64;
2484 println!("IV = {}", iv);
2485 let mut cipher = [0_u8; 8];
2486 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2487 print!("C =\t");
2488 for c in cipher.clone()
2489 { print!("{:02X} ", c); }
2490 println!();
2491 let mut txt = String::new();
2492 for c in cipher.clone()
2493 { write!(txt, "{:02X} ", c); }
2494 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2495 println!();
2496
2497 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2498 let key = 0x_1234567890ABCDEF_u64;
2499 println!("K =\t{:#016X}", key);
2500 let mut a_des = DES::new_with_key_u64(key);
2501
2502 let mes = "PARK Youngho";
2503 println!("M =\t{}", mes);
2504 let mut message = [0_u8; 12];
2505 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2506 let iv = 0x_FEDCBA0987654321_u64;
2507 println!("IV = {}", iv);
2508 let mut cipher = [0_u8; 12];
2509 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2510 print!("C =\t");
2511 for c in cipher.clone()
2512 { print!("{:02X} ", c); }
2513 println!();
2514 let mut txt = String::new();
2515 for c in cipher.clone()
2516 { write!(txt, "{:02X} ", c); }
2517 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
2518 println!();
2519
2520 // Normal case for the message of 16 bytes
2521 let key = 0x_1234567890ABCDEF_u64;
2522 println!("K =\t{:#016X}", key);
2523 let mut a_des = DES::new_with_key_u64(key);
2524
2525 let mes = "고맙습니다.";
2526 println!("M =\t{}", mes);
2527 let mut message = [0_u8; 16];
2528 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2529 let iv = 0x_FEDCBA0987654321_u64;
2530 println!("IV = {}", iv);
2531 let mut cipher = [0_u8; 16];
2532 a_des.encrypt_array(iv, &message, cipher.as_mut_ptr());
2533 print!("C =\t");
2534 for c in cipher.clone()
2535 { print!("{:02X} ", c); }
2536 println!();
2537 let mut txt = String::new();
2538 for c in cipher.clone()
2539 { write!(txt, "{:02X} ", c); }
2540 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
2541 println!("-------------------------------");
2542}
2543
2544fn des_encrypt_array_ofb_into_vec()
2545{
2546 println!("des_encrypt_array_ofb_into_vec()");
2547 use std::io::Write;
2548 use std::fmt::Write as _;
2549 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
2550
2551 // Normal case
2552 let key = 0x_1234567890ABCDEF_u64;
2553 println!("K =\t{:#016X}", key);
2554 let mut a_des = DES::new_with_key_u64(key);
2555
2556 let mes = "In the beginning God created the heavens and the earth.";
2557 println!("M =\t{}", mes);
2558 let mut message = [0_u8; 55];
2559 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2560 let iv = 0x_FEDCBA0987654321_u64;
2561 println!("IV = {}", iv);
2562 let mut cipher = Vec::<u8>::new();
2563 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2564 print!("C (16 rounds) =\t");
2565 for c in cipher.clone()
2566 { print!("{:02X} ", c); }
2567 println!();
2568 let mut txt = String::new();
2569 for c in cipher.clone()
2570 { write!(txt, "{:02X} ", c); }
2571 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
2572 println!();
2573
2574 // Expanded case for 128 rounds
2575 let key = 0x_1234567890ABCDEF_u64;
2576 println!("K =\t{:#016X}", key);
2577 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2578
2579 let mes = "In the beginning God created the heavens and the earth.";
2580 println!("M =\t{}", mes);
2581 let mut message = [0_u8; 55];
2582 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2583 let iv = 0x_FEDCBA0987654321_u64;
2584 println!("IV = {}", iv);
2585 let mut cipher = Vec::<u8>::new();
2586 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2587 print!("C (128 rounds) =\t");
2588 for c in cipher.clone()
2589 { print!("{:02X} ", c); }
2590 println!();
2591 let mut txt = String::new();
2592 for c in cipher.clone()
2593 { write!(txt, "{:02X} ", c); }
2594 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
2595 println!();
2596
2597 // Expanded case for 0 rounds which means that key is meaningless
2598 let key1 = 0x_1234567890ABCDEF_u64;
2599 let key2 = 0_u64;
2600 println!("K1 =\t{:#016X}", key1);
2601 println!("K2 =\t{:#016X}", key2);
2602 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2603 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2604
2605 let mes = "In the beginning God created the heavens and the earth.";
2606 println!("M =\t{}", mes);
2607 let mut message = [0_u8; 55];
2608 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2609
2610 let iv = 0x_FEDCBA0987654321_u64;
2611 println!("IV = {}", iv);
2612 let mut cipher1 = Vec::<u8>::new();
2613 let mut cipher2 = Vec::<u8>::new();
2614 c_des.encrypt_array_into_vec(iv, &message, &mut cipher1);
2615 d_des.encrypt_array_into_vec(iv, &message, &mut cipher2);
2616 print!("C (0 rounds) =\t");
2617 for c in cipher1.clone()
2618 { print!("{:02X} ", c); }
2619 println!();
2620 let mut txt = String::new();
2621 for c in cipher1.clone()
2622 { write!(txt, "{:02X} ", c); }
2623 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2624 print!("D (0 rounds) =\t");
2625 for c in cipher2.clone()
2626 { print!("{:02X} ", c); }
2627 println!();
2628 let mut txt = String::new();
2629 for c in cipher2.clone()
2630 { write!(txt, "{:02X} ", c); }
2631 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2632 println!();
2633
2634 // Normal case for the message of 0 bytes
2635 let key = 0x_1234567890ABCDEF_u64;
2636 println!("K =\t{:#016X}", key);
2637 let mut a_des = DES::new_with_key_u64(key);
2638
2639 let mes = "";
2640 println!("M =\t{}", mes);
2641 let mut message = [0_u8; 0];
2642 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2643 let iv = 0x_FEDCBA0987654321_u64;
2644 println!("IV = {}", iv);
2645 let mut cipher = Vec::<u8>::new();
2646 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2647 print!("C =\t");
2648 for c in cipher.clone()
2649 { print!("{:02X} ", c); }
2650 println!();
2651 let mut txt = String::new();
2652 for c in cipher.clone()
2653 { write!(txt, "{:02X} ", c); }
2654 assert_eq!(txt, "");
2655 println!();
2656
2657 // Normal case for the message shorter than 8 bytes
2658 let key = 0x_1234567890ABCDEF_u64;
2659 println!("K =\t{:#016X}", key);
2660 let mut a_des = DES::new_with_key_u64(key);
2661
2662 let mes = "7 bytes";
2663 println!("M =\t{}", mes);
2664 let mut message = [0_u8; 7];
2665 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2666 let iv = 0x_FEDCBA0987654321_u64;
2667 println!("IV = {}", iv);
2668 let mut cipher = Vec::<u8>::new();
2669 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2670 print!("C =\t");
2671 for c in cipher.clone()
2672 { print!("{:02X} ", c); }
2673 println!();
2674 let mut txt = String::new();
2675 for c in cipher.clone()
2676 { write!(txt, "{:02X} ", c); }
2677 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2678 println!();
2679
2680 // Normal case for the message of 8 bytes
2681 let key = 0x_1234567890ABCDEF_u64;
2682 println!("K =\t{:#016X}", key);
2683 let mut a_des = DES::new_with_key_u64(key);
2684
2685 let mes = "I am OK.";
2686 println!("M =\t{}", mes);
2687 let mut message = [0_u8; 8];
2688 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2689 let iv = 0x_FEDCBA0987654321_u64;
2690 println!("IV = {}", iv);
2691 let mut cipher = Vec::<u8>::new();
2692 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2693 print!("C =\t");
2694 for c in cipher.clone()
2695 { print!("{:02X} ", c); }
2696 println!();
2697 let mut txt = String::new();
2698 for c in cipher.clone()
2699 { write!(txt, "{:02X} ", c); }
2700 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2701 println!();
2702
2703 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2704 let key = 0x_1234567890ABCDEF_u64;
2705 println!("K =\t{:#016X}", key);
2706 let mut a_des = DES::new_with_key_u64(key);
2707
2708 let mes = "PARK Youngho";
2709 println!("M =\t{}", mes);
2710 let mut message = [0_u8; 12];
2711 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2712 let iv = 0x_FEDCBA0987654321_u64;
2713 println!("IV = {}", iv);
2714 let mut cipher = Vec::<u8>::new();
2715 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2716 print!("C =\t");
2717 for c in cipher.clone()
2718 { print!("{:02X} ", c); }
2719 println!();
2720 let mut txt = String::new();
2721 for c in cipher.clone()
2722 { write!(txt, "{:02X} ", c); }
2723 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
2724 println!();
2725
2726 // Normal case for the message of 16 bytes
2727 let key = 0x_1234567890ABCDEF_u64;
2728 println!("K =\t{:#016X}", key);
2729 let mut a_des = DES::new_with_key_u64(key);
2730
2731 let mes = "고맙습니다.";
2732 println!("M =\t{}", mes);
2733 let mut message = [0_u8; 16];
2734 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2735 let iv = 0x_FEDCBA0987654321_u64;
2736 println!("IV = {}", iv);
2737 let mut cipher = Vec::<u8>::new();
2738 a_des.encrypt_array_into_vec(iv, &message, &mut cipher);
2739 print!("C =\t");
2740 for c in cipher.clone()
2741 { print!("{:02X} ", c); }
2742 println!();
2743 let mut txt = String::new();
2744 for c in cipher.clone()
2745 { write!(txt, "{:02X} ", c); }
2746 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
2747 println!("-------------------------------");
2748}
2749
2750fn des_encrypt_array_ofb_into_array()
2751{
2752 println!("des_encrypt_array_ofb_into_array()");
2753 use std::io::Write;
2754 use std::fmt::Write as _;
2755 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
2756
2757 // Normal case
2758 let key = 0x_1234567890ABCDEF_u64;
2759 println!("K =\t{:#016X}", key);
2760 let mut a_des = DES::new_with_key_u64(key);
2761
2762 let mes = "In the beginning God created the heavens and the earth.";
2763 println!("M =\t{}", mes);
2764 let mut message = [0_u8; 55];
2765 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2766 let iv = 0x_FEDCBA0987654321_u64;
2767 println!("IV = {}", iv);
2768 let mut cipher = [0_u8; 55];
2769 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2770 for c in cipher.clone()
2771 { print!("{:02X} ", c); }
2772 println!();
2773 let mut txt = String::new();
2774 for c in cipher.clone()
2775 { write!(txt, "{:02X} ", c); }
2776 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
2777 println!();
2778
2779 // Expanded case for 128 rounds
2780 let key = 0x_1234567890ABCDEF_u64;
2781 println!("K =\t{:#016X}", key);
2782 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2783
2784 let mes = "In the beginning God created the heavens and the earth.";
2785 println!("M =\t{}", mes);
2786 let mut message = [0_u8; 55];
2787 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2788 let iv = 0x_FEDCBA0987654321_u64;
2789 println!("IV = {}", iv);
2790 let mut cipher = [0_u8; 55];
2791 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2792 print!("C (128 rounds) =\t");
2793 for c in cipher.clone()
2794 { print!("{:02X} ", c); }
2795 println!();
2796 let mut txt = String::new();
2797 for c in cipher.clone()
2798 { write!(txt, "{:02X} ", c); }
2799 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
2800 println!();
2801
2802 // Expanded case for 0 rounds which means that key is meaningless
2803 let key1 = 0x_1234567890ABCDEF_u64;
2804 let key2 = 0_u64;
2805 println!("K1 =\t{:#016X}", key1);
2806 println!("K2 =\t{:#016X}", key2);
2807 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2808 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2809
2810 let mes = "In the beginning God created the heavens and the earth.";
2811 println!("M =\t{}", mes);
2812 let mut message = [0_u8; 55];
2813 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2814 let iv = 0x_FEDCBA0987654321_u64;
2815 println!("IV = {}", iv);
2816 let mut cipher1 = [0_u8; 55];
2817 let mut cipher2 = [0_u8; 55];
2818 c_des.encrypt_array_into_array(iv, &message, &mut cipher1);
2819 d_des.encrypt_array_into_array(iv, &message, &mut cipher2);
2820 print!("C (0 rounds) =\t");
2821 for c in cipher1.clone()
2822 { print!("{:02X} ", c); }
2823 println!();
2824 let mut txt = String::new();
2825 for c in cipher1.clone()
2826 { write!(txt, "{:02X} ", c); }
2827 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2828 print!("D (0 rounds) =\t");
2829 for c in cipher2.clone()
2830 { print!("{:02X} ", c); }
2831 println!();
2832 let mut txt = String::new();
2833 for c in cipher2.clone()
2834 { write!(txt, "{:02X} ", c); }
2835 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
2836 println!();
2837
2838 // Normal case for the message of 0 bytes
2839 let key = 0x_1234567890ABCDEF_u64;
2840 println!("K =\t{:#016X}", key);
2841 let mut a_des = DES::new_with_key_u64(key);
2842
2843 let mes = "";
2844 println!("M =\t{}", mes);
2845 let mut message = [0_u8; 0];
2846 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2847 let iv = 0x_FEDCBA0987654321_u64;
2848 println!("IV = {}", iv);
2849 let mut cipher = [0_u8; 0];
2850 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2851 print!("C =\t");
2852 for c in cipher.clone()
2853 { print!("{:02X} ", c); }
2854 println!();
2855 let mut txt = String::new();
2856 for c in cipher.clone()
2857 { write!(txt, "{:02X} ", c); }
2858 assert_eq!(txt, "");
2859 println!();
2860
2861 // Normal case for the message shorter than 8 bytes
2862 let key = 0x_1234567890ABCDEF_u64;
2863 println!("K =\t{:#016X}", key);
2864 let mut a_des = DES::new_with_key_u64(key);
2865
2866 let mes = "7 bytes";
2867 println!("M =\t{}", mes);
2868 let mut message = [0_u8; 7];
2869 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2870 let iv = 0x_FEDCBA0987654321_u64;
2871 println!("IV = {}", iv);
2872 let mut cipher = [0_u8; 7];
2873 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2874 print!("C =\t");
2875 for c in cipher.clone()
2876 { print!("{:02X} ", c); }
2877 println!();
2878 let mut txt = String::new();
2879 for c in cipher.clone()
2880 { write!(txt, "{:02X} ", c); }
2881 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
2882 println!();
2883
2884 // Normal case for the message of 8 bytes
2885 let key = 0x_1234567890ABCDEF_u64;
2886 println!("K =\t{:#016X}", key);
2887 let mut a_des = DES::new_with_key_u64(key);
2888
2889 let mes = "I am OK.";
2890 println!("M =\t{}", mes);
2891 let mut message = [0_u8; 8];
2892 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2893 let iv = 0x_FEDCBA0987654321_u64;
2894 println!("IV = {}", iv);
2895 let mut cipher = [0_u8; 8];
2896 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2897 print!("C =\t");
2898 for c in cipher.clone()
2899 { print!("{:02X} ", c); }
2900 println!();
2901 let mut txt = String::new();
2902 for c in cipher.clone()
2903 { write!(txt, "{:02X} ", c); }
2904 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
2905 println!();
2906
2907 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2908 let key = 0x_1234567890ABCDEF_u64;
2909 println!("K =\t{:#016X}", key);
2910 let mut a_des = DES::new_with_key_u64(key);
2911
2912 let mes = "PARK Youngho";
2913 println!("M =\t{}", mes);
2914 let mut message = [0_u8; 12];
2915 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2916 let iv = 0x_FEDCBA0987654321_u64;
2917 println!("IV = {}", iv);
2918 let mut cipher = [0_u8; 12];
2919 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2920 print!("C =\t");
2921 for c in cipher.clone()
2922 { print!("{:02X} ", c); }
2923 println!();
2924 let mut txt = String::new();
2925 for c in cipher.clone()
2926 { write!(txt, "{:02X} ", c); }
2927 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
2928 println!();
2929
2930 // Normal case for the message of 16 bytes
2931 let key = 0x_1234567890ABCDEF_u64;
2932 println!("K =\t{:#016X}", key);
2933 let mut a_des = DES::new_with_key_u64(key);
2934
2935 let mes = "고맙습니다.";
2936 println!("M =\t{}", mes);
2937 let mut message = [0_u8; 16];
2938 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2939 let iv = 0x_FEDCBA0987654321_u64;
2940 println!("IV = {}", iv);
2941 let mut cipher = [0_u8; 16];
2942 a_des.encrypt_array_into_array(iv, &message, &mut cipher);
2943 print!("C =\t");
2944 for c in cipher.clone()
2945 { print!("{:02X} ", c); }
2946 println!();
2947 let mut txt = String::new();
2948 for c in cipher.clone()
2949 { write!(txt, "{:02X} ", c); }
2950 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
2951 println!("-------------------------------");
2952}
2953
2954fn des_decrypt_ofb()
2955{
2956 println!("des_decrypt_ofb()");
2957 use std::io::Write;
2958 use std::fmt::Write as _;
2959 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
2960
2961 // Normal case
2962 let key = 0x_1234567890ABCDEF_u64;
2963 println!("K =\t{:#016X}", key);
2964 let mut a_des = DES::new_with_key_u64(key);
2965
2966 let message = "In the beginning God created the heavens and the earth.";
2967 println!("M =\t{}", message);
2968 let iv = 0x_FEDCBA0987654321_u64;
2969 println!("IV = {}", iv);
2970 let mut cipher = Vec::<u8>::new();
2971 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
2972 print!("C (16 rounds) =\t");
2973 for c in cipher.clone()
2974 { print!("{:02X} ", c); }
2975 println!();
2976 let mut txt = String::new();
2977 for c in cipher.clone()
2978 { write!(txt, "{:02X} ", c); }
2979 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
2980
2981 let mut recovered = vec![0; 55];
2982 a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2983 print!("Ba (16 rounds) =\t");
2984 for b in recovered.clone()
2985 { print!("{:02X} ", b); }
2986 println!();
2987 let mut txt = String::new();
2988 for c in recovered.clone()
2989 { write!(txt, "{:02X} ", c); }
2990 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2991
2992 let mut converted = String::new();
2993 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2994
2995 println!("Bb (16 rounds) =\t{}", converted);
2996 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2997 assert_eq!(converted, message);
2998 println!();
2999
3000 // Expanded case for 128 rounds
3001 let key = 0x_1234567890ABCDEF_u64;
3002 println!("K =\t{:#016X}", key);
3003 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3004
3005 let message = "In the beginning God created the heavens and the earth.";
3006 println!("M =\t{}", message);
3007 let iv = 0x_FEDCBA0987654321_u64;
3008 println!("IV = {}", iv);
3009 let mut cipher = Vec::<u8>::new();
3010 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3011 print!("C (128 rounds) =\t");
3012 for c in cipher.clone()
3013 { print!("{:02X} ", c); }
3014 println!();
3015 let mut txt = String::new();
3016 for c in cipher.clone()
3017 { write!(txt, "{:02X} ", c); }
3018 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
3019
3020 let mut recovered = vec![0; 55];
3021 a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3022 print!("Ba (128 rounds) =\t");
3023 for b in recovered.clone()
3024 { print!("{:02X} ", b); }
3025 println!();
3026 let mut txt = String::new();
3027 for c in recovered.clone()
3028 { write!(txt, "{:02X} ", c); }
3029 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3030
3031 let mut converted = String::new();
3032 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3033
3034 println!("Bb (128 rounds) =\t{}", converted);
3035 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3036 assert_eq!(converted, message);
3037 println!();
3038
3039 // Expanded case for 0 rounds which means that key is meaningless
3040 let key1 = 0x_1234567890ABCDEF_u64;
3041 let key2 = 0_u64;
3042 println!("K =\t{:#016X}", key);
3043 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3044 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3045
3046 let message = "In the beginning God created the heavens and the earth.";
3047 println!("M =\t{}", message);
3048 let iv = 0x_FEDCBA0987654321_u64;
3049 println!("IV = {}", iv);
3050 let mut cipher1 = Vec::<u8>::new();
3051 let mut cipher2 = Vec::<u8>::new();
3052 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
3053 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
3054 print!("C (0 rounds) =\t");
3055 for c in cipher1.clone()
3056 { print!("{:02X} ", c); }
3057 println!();
3058 let mut txt = String::new();
3059 for c in cipher1.clone()
3060 { write!(txt, "{:02X} ", c); }
3061 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
3062 print!("D (0 rounds) =\t");
3063 for c in cipher2.clone()
3064 { print!("{:02X} ", c); }
3065 println!();
3066 let mut txt = String::new();
3067 for c in cipher2.clone()
3068 { write!(txt, "{:02X} ", c); }
3069 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
3070
3071 let mut recovered1 = vec![0; 55];
3072 let mut recovered2 = vec![0; 55];
3073 c_des.decrypt(iv, cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
3074 d_des.decrypt(iv, cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
3075 print!("B1a (0 rounds) =\t");
3076 for b in recovered1.clone()
3077 { print!("{:02X} ", b); }
3078 println!();
3079 let mut txt = String::new();
3080 for c in recovered1.clone()
3081 { write!(txt, "{:02X} ", c); }
3082 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3083 print!("B2a (0 rounds) =\t");
3084 for b in recovered2.clone()
3085 { print!("{:02X} ", b); }
3086 println!();
3087 let mut txt = String::new();
3088 for c in recovered2.clone()
3089 { write!(txt, "{:02X} ", c); }
3090 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3091
3092 let mut converted1 = String::new();
3093 let mut converted2 = String::new();
3094 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3095 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3096
3097 println!("B1b (0 rounds) =\t{}", converted1);
3098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3099 assert_eq!(converted1, message);
3100 println!("B2b (0 rounds) =\t{}", converted2);
3101 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3102 assert_eq!(converted2, message);
3103 assert_eq!(converted1, converted1);
3104 println!();
3105
3106 // Normal case for the message of 0 bytes
3107 let key = 0x_1234567890ABCDEF_u64;
3108 println!("K =\t{:#016X}", key);
3109 let mut a_des = DES::new_with_key_u64(key);
3110
3111 let message = "";
3112 println!("M =\t{}", message);
3113 let iv = 0x_FEDCBA0987654321_u64;
3114 println!("IV = {}", iv);
3115 let mut cipher = Vec::<u8>::new();
3116 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3117 print!("C =\t");
3118 for c in cipher.clone()
3119 { print!("{:02X} ", c); }
3120 println!();
3121 let mut txt = String::new();
3122 for c in cipher.clone()
3123 { write!(txt, "{:02X} ", c); }
3124 assert_eq!(txt, "");
3125
3126 let mut recovered = vec![0; 8];
3127 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3128 print!("Ba =\t");
3129 for b in recovered.clone()
3130 { print!("{:02X} ", b); }
3131 println!();
3132 let mut txt = String::new();
3133 for c in recovered.clone()
3134 { write!(txt, "{:02X} ", c); }
3135 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3136
3137 let mut converted = String::new();
3138 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139 converted.truncate(len as usize);
3140
3141 println!("Bb =\t{}", converted);
3142 assert_eq!(converted, "");
3143 assert_eq!(converted, message);
3144 println!();
3145
3146 // Normal case for the message shorter than 8 bytes
3147 let key = 0x_1234567890ABCDEF_u64;
3148 println!("K =\t{:#016X}", key);
3149 let mut a_des = DES::new_with_key_u64(key);
3150
3151 let message = "7 bytes";
3152 println!("M =\t{}", message);
3153 let iv = 0x_FEDCBA0987654321_u64;
3154 println!("IV = {}", iv);
3155 let mut cipher = Vec::<u8>::new();
3156 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3157 print!("C =\t");
3158 for c in cipher.clone()
3159 { print!("{:02X} ", c); }
3160 println!();
3161 let mut txt = String::new();
3162 for c in cipher.clone()
3163 { write!(txt, "{:02X} ", c); }
3164 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
3165
3166 let mut recovered = vec![0; 8];
3167 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3168 print!("Ba =\t");
3169 for b in recovered.clone()
3170 { print!("{:02X} ", b); }
3171 println!();
3172 let mut txt = String::new();
3173 for c in recovered.clone()
3174 { write!(txt, "{:02X} ", c); }
3175 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3176
3177 let mut converted = String::new();
3178 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3179 converted.truncate(len as usize);
3180
3181 println!("Bb =\t{}", converted);
3182 assert_eq!(converted, "7 bytes");
3183 assert_eq!(converted, message);
3184 println!();
3185
3186 // Normal case for the message of 8 bytes
3187 let key = 0x_1234567890ABCDEF_u64;
3188 println!("K =\t{:#016X}", key);
3189 let mut a_des = DES::new_with_key_u64(key);
3190
3191 let message = "I am OK.";
3192 println!("M =\t{}", message);
3193 let iv = 0x_FEDCBA0987654321_u64;
3194 println!("IV = {}", iv);
3195 let mut cipher = Vec::<u8>::new();
3196 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3197 print!("C =\t");
3198 for c in cipher.clone()
3199 { print!("{:02X} ", c); }
3200 println!();
3201 let mut txt = String::new();
3202 for c in cipher.clone()
3203 { write!(txt, "{:02X} ", c); }
3204 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
3205
3206 let mut recovered = vec![0; 16];
3207 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3208 print!("Ba =\t");
3209 for b in recovered.clone()
3210 { print!("{:02X} ", b); }
3211 println!();
3212 let mut txt = String::new();
3213 for c in recovered.clone()
3214 { write!(txt, "{:02X} ", c); }
3215 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3216
3217 let mut converted = String::new();
3218 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3219 converted.truncate(len as usize);
3220
3221 println!("Bb =\t{}", converted);
3222 assert_eq!(converted, "I am OK.");
3223 assert_eq!(converted, message);
3224 println!();
3225
3226 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3227 let key = 0x_1234567890ABCDEF_u64;
3228 println!("K =\t{:#016X}", key);
3229 let mut a_des = DES::new_with_key_u64(key);
3230
3231 let message = "PARK Youngho";
3232 println!("M =\t{}", message);
3233 let iv = 0x_FEDCBA0987654321_u64;
3234 println!("IV = {}", iv);
3235 let mut cipher = Vec::<u8>::new();
3236 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3237 print!("C =\t");
3238 for c in cipher.clone()
3239 { print!("{:02X} ", c); }
3240 println!();
3241 let mut txt = String::new();
3242 for c in cipher.clone()
3243 { write!(txt, "{:02X} ", c); }
3244 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
3245
3246 let mut recovered = vec![0; 16];
3247 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3248 print!("Ba =\t");
3249 for b in recovered.clone()
3250 { print!("{:02X} ", b); }
3251 println!();
3252 let mut txt = String::new();
3253 for c in recovered.clone()
3254 { write!(txt, "{:02X} ", c); }
3255 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3256
3257 let mut converted = String::new();
3258 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3259 converted.truncate(len as usize);
3260
3261 println!("Bb =\t{}", converted);
3262 assert_eq!(converted, "PARK Youngho");
3263 assert_eq!(converted, message);
3264 println!();
3265
3266 // Normal case for the message of 16 bytes
3267 let key = 0x_1234567890ABCDEF_u64;
3268 println!("K =\t{:#016X}", key);
3269 let mut a_des = DES::new_with_key_u64(key);
3270
3271 let message = "고맙습니다.";
3272 println!("M =\t{}", message);
3273 let iv = 0x_FEDCBA0987654321_u64;
3274 println!("IV = {}", iv);
3275 let mut cipher = Vec::<u8>::new();
3276 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3277 print!("C =\t");
3278 for c in cipher.clone()
3279 { print!("{:02X} ", c); }
3280 println!();
3281 let mut txt = String::new();
3282 for c in cipher.clone()
3283 { write!(txt, "{:02X} ", c); }
3284 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
3285
3286 let mut recovered = vec![0; 24];
3287 let len = a_des.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3288 print!("Ba =\t");
3289 for b in recovered.clone()
3290 { print!("{:02X} ", b); }
3291 println!();
3292 let mut txt = String::new();
3293 for c in recovered.clone()
3294 { write!(txt, "{:02X} ", c); }
3295 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3296
3297 let mut converted = String::new();
3298 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3299 converted.truncate(len as usize);
3300
3301 println!("Bb =\t{}", converted);
3302 assert_eq!(converted, "고맙습니다.");
3303 assert_eq!(converted, message);
3304 println!("-------------------------------");
3305}
3306
3307fn des_decrypt_ofb_into_vec()
3308{
3309 println!("des_decrypt_ofb_into_vec()");
3310 use std::io::Write;
3311 use std::fmt::Write as _;
3312 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
3313
3314 // Normal case
3315 let key = 0x_1234567890ABCDEF_u64;
3316 println!("K =\t{:#016X}", key);
3317 let mut a_des = DES::new_with_key_u64(key);
3318
3319 let message = "In the beginning God created the heavens and the earth.";
3320 println!("M =\t{}", message);
3321 let iv = 0x_FEDCBA0987654321_u64;
3322 println!("IV = {}", iv);
3323 let mut cipher = Vec::<u8>::new();
3324 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3325 print!("C (16 rounds) =\t");
3326 for c in cipher.clone()
3327 { print!("{:02X} ", c); }
3328 println!();
3329 let mut txt = String::new();
3330 for c in cipher.clone()
3331 { write!(txt, "{:02X} ", c); }
3332 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
3333
3334 let mut recovered = Vec::<u8>::new();
3335 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3336 print!("Ba (16 rounds) =\t");
3337 for b in recovered.clone()
3338 { print!("{:02X} ", b); }
3339 println!();
3340 let mut txt = String::new();
3341 for c in recovered.clone()
3342 { write!(txt, "{:02X} ", c); }
3343 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3344
3345 let mut converted = String::new();
3346 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3347
3348 println!("Bb (16 rounds) =\t{}", converted);
3349 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3350 assert_eq!(converted, message);
3351 println!();
3352
3353 // Expanded case for 128 rounds
3354 let key = 0x_1234567890ABCDEF_u64;
3355 println!("K =\t{:#016X}", key);
3356 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3357
3358 let message = "In the beginning God created the heavens and the earth.";
3359 println!("M =\t{}", message);
3360 let iv = 0x_FEDCBA0987654321_u64;
3361 println!("IV = {}", iv);
3362 let mut cipher = Vec::<u8>::new();
3363 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3364 print!("C (128 rounds) =\t");
3365 for c in cipher.clone()
3366 { print!("{:02X} ", c); }
3367 println!();
3368 let mut txt = String::new();
3369 for c in cipher.clone()
3370 { write!(txt, "{:02X} ", c); }
3371 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
3372
3373 let mut recovered = Vec::<u8>::new();
3374 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3375 print!("Ba (128 rounds) =\t");
3376 for b in recovered.clone()
3377 { print!("{:02X} ", b); }
3378 println!();
3379 let mut txt = String::new();
3380 for c in recovered.clone()
3381 { write!(txt, "{:02X} ", c); }
3382 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3383
3384 let mut converted = String::new();
3385 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3386
3387 println!("Bb (128 rounds) =\t{}", converted);
3388 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3389 assert_eq!(converted, message);
3390 println!();
3391
3392 // Expanded case for 0 rounds which means that key is meaningless
3393 let key1 = 0x_1234567890ABCDEF_u64;
3394 let key2 = 0_u64;
3395 println!("K =\t{:#016X}", key);
3396 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3397 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3398
3399 let message = "In the beginning God created the heavens and the earth.";
3400 println!("M =\t{}", message);
3401 let iv = 0x_FEDCBA0987654321_u64;
3402 println!("IV = {}", iv);
3403 let mut cipher1 = Vec::<u8>::new();
3404 let mut cipher2 = Vec::<u8>::new();
3405 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
3406 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
3407 print!("C (0 rounds) =\t");
3408 for c in cipher1.clone()
3409 { print!("{:02X} ", c); }
3410 println!();
3411 let mut txt = String::new();
3412 for c in cipher1.clone()
3413 { write!(txt, "{:02X} ", c); }
3414 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
3415 print!("D (0 rounds) =\t");
3416 for c in cipher2.clone()
3417 { print!("{:02X} ", c); }
3418 println!();
3419 let mut txt = String::new();
3420 for c in cipher2.clone()
3421 { write!(txt, "{:02X} ", c); }
3422 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
3423
3424 let mut recovered1 = Vec::<u8>::new();
3425 let mut recovered2 = Vec::<u8>::new();
3426 c_des.decrypt_into_vec(iv, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3427 d_des.decrypt_into_vec(iv, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3428 print!("B1a (0 rounds) =\t");
3429 for b in recovered1.clone()
3430 { print!("{:02X} ", b); }
3431 println!();
3432 let mut txt = String::new();
3433 for c in recovered1.clone()
3434 { write!(txt, "{:02X} ", c); }
3435 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3436 print!("B2a (0 rounds) =\t");
3437 for b in recovered2.clone()
3438 { print!("{:02X} ", b); }
3439 println!();
3440 let mut txt = String::new();
3441 for c in recovered2.clone()
3442 { write!(txt, "{:02X} ", c); }
3443 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3444
3445 let mut converted1 = String::new();
3446 let mut converted2 = String::new();
3447 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3448 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3449
3450 println!("B1b (0 rounds) =\t{}", converted1);
3451 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3452 assert_eq!(converted1, message);
3453 println!("B2b (0 rounds) =\t{}", converted2);
3454 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3455 assert_eq!(converted2, message);
3456 assert_eq!(converted1, converted1);
3457 println!();
3458
3459 // Normal case for the message of 0 bytes
3460 let key = 0x_1234567890ABCDEF_u64;
3461 println!("K =\t{:#016X}", key);
3462 let mut a_des = DES::new_with_key_u64(key);
3463
3464 let message = "";
3465 println!("M =\t{}", message);
3466 let iv = 0x_FEDCBA0987654321_u64;
3467 println!("IV = {}", iv);
3468 let mut cipher = Vec::<u8>::new();
3469 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3470 print!("C =\t");
3471 for c in cipher.clone()
3472 { print!("{:02X} ", c); }
3473 println!();
3474 let mut txt = String::new();
3475 for c in cipher.clone()
3476 { write!(txt, "{:02X} ", c); }
3477 assert_eq!(txt, "");
3478
3479 let mut recovered = Vec::<u8>::new();
3480 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3481 print!("Ba =\t");
3482 for b in recovered.clone()
3483 { print!("{:02X} ", b); }
3484 println!();
3485 let mut txt = String::new();
3486 for c in recovered.clone()
3487 { write!(txt, "{:02X} ", c); }
3488 assert_eq!(txt, "");
3489
3490 let mut converted = String::new();
3491 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3492
3493 println!("Bb =\t{}", converted);
3494 assert_eq!(converted, "");
3495 assert_eq!(converted, message);
3496 println!();
3497
3498 // Normal case for the message shorter than 8 bytes
3499 let key = 0x_1234567890ABCDEF_u64;
3500 println!("K =\t{:#016X}", key);
3501 let mut a_des = DES::new_with_key_u64(key);
3502
3503 let message = "7 bytes";
3504 println!("M =\t{}", message);
3505 let iv = 0x_FEDCBA0987654321_u64;
3506 println!("IV = {}", iv);
3507 let mut cipher = Vec::<u8>::new();
3508 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3509 print!("C =\t");
3510 for c in cipher.clone()
3511 { print!("{:02X} ", c); }
3512 println!();
3513 let mut txt = String::new();
3514 for c in cipher.clone()
3515 { write!(txt, "{:02X} ", c); }
3516 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
3517
3518 let mut recovered = Vec::<u8>::new();
3519 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3520 print!("Ba =\t");
3521 for b in recovered.clone()
3522 { print!("{:02X} ", b); }
3523 println!();
3524 let mut txt = String::new();
3525 for c in recovered.clone()
3526 { write!(txt, "{:02X} ", c); }
3527 assert_eq!(txt, "37 20 62 79 74 65 73 ");
3528
3529 let mut converted = String::new();
3530 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3531
3532 println!("Bb =\t{}", converted);
3533 assert_eq!(converted, "7 bytes");
3534 assert_eq!(converted, message);
3535 println!();
3536
3537 // Normal case for the message of 8 bytes
3538 let key = 0x_1234567890ABCDEF_u64;
3539 println!("K =\t{:#016X}", key);
3540 let mut a_des = DES::new_with_key_u64(key);
3541
3542 let message = "I am OK.";
3543 println!("M =\t{}", message);
3544 let iv = 0x_FEDCBA0987654321_u64;
3545 println!("IV = {}", iv);
3546 let mut cipher = Vec::<u8>::new();
3547 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3548 print!("C =\t");
3549 for c in cipher.clone()
3550 { print!("{:02X} ", c); }
3551 println!();
3552 let mut txt = String::new();
3553 for c in cipher.clone()
3554 { write!(txt, "{:02X} ", c); }
3555 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
3556
3557 let mut recovered = Vec::<u8>::new();
3558 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3559 print!("Ba =\t");
3560 for b in recovered.clone()
3561 { print!("{:02X} ", b); }
3562 println!();
3563 let mut txt = String::new();
3564 for c in recovered.clone()
3565 { write!(txt, "{:02X} ", c); }
3566 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3567
3568 let mut converted = String::new();
3569 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3570
3571 println!("Bb =\t{}", converted);
3572 assert_eq!(converted, "I am OK.");
3573 assert_eq!(converted, message);
3574 println!();
3575
3576 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3577 let key = 0x_1234567890ABCDEF_u64;
3578 println!("K =\t{:#016X}", key);
3579 let mut a_des = DES::new_with_key_u64(key);
3580
3581 let message = "PARK Youngho";
3582 println!("M =\t{}", message);
3583 let iv = 0x_FEDCBA0987654321_u64;
3584 println!("IV = {}", iv);
3585 let mut cipher = Vec::<u8>::new();
3586 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3587 print!("C =\t");
3588 for c in cipher.clone()
3589 { print!("{:02X} ", c); }
3590 println!();
3591 let mut txt = String::new();
3592 for c in cipher.clone()
3593 { write!(txt, "{:02X} ", c); }
3594 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
3595
3596 let mut recovered = Vec::<u8>::new();
3597 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3598 print!("Ba =\t");
3599 for b in recovered.clone()
3600 { print!("{:02X} ", b); }
3601 println!();
3602 let mut txt = String::new();
3603 for c in recovered.clone()
3604 { write!(txt, "{:02X} ", c); }
3605 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3606
3607 let mut converted = String::new();
3608 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3609
3610 println!("Bb =\t{}", converted);
3611 assert_eq!(converted, "PARK Youngho");
3612 assert_eq!(converted, message);
3613 println!();
3614
3615 // Normal case for the message of 16 bytes
3616 let key = 0x_1234567890ABCDEF_u64;
3617 println!("K =\t{:#016X}", key);
3618 let mut a_des = DES::new_with_key_u64(key);
3619
3620 let message = "고맙습니다.";
3621 println!("M =\t{}", message);
3622 let iv = 0x_FEDCBA0987654321_u64;
3623 println!("IV = {}", iv);
3624 let mut cipher = Vec::<u8>::new();
3625 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3626 print!("C =\t");
3627 for c in cipher.clone()
3628 { print!("{:02X} ", c); }
3629 println!();
3630 let mut txt = String::new();
3631 for c in cipher.clone()
3632 { write!(txt, "{:02X} ", c); }
3633 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
3634
3635 let mut recovered = Vec::<u8>::new();
3636 a_des.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3637 print!("Ba =\t");
3638 for b in recovered.clone()
3639 { print!("{:02X} ", b); }
3640 println!();
3641 let mut txt = String::new();
3642 for c in recovered.clone()
3643 { write!(txt, "{:02X} ", c); }
3644 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3645
3646 let mut converted = String::new();
3647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3648
3649 println!("Bb =\t{}", converted);
3650 assert_eq!(converted, "고맙습니다.");
3651 assert_eq!(converted, message);
3652 println!("-------------------------------");
3653}
3654
3655fn des_decrypt_ofb_into_array()
3656{
3657 println!("des_decrypt_ofb_into_array()");
3658 use std::io::Write;
3659 use std::fmt::Write as _;
3660 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
3661
3662 // Normal case
3663 let key = 0x_1234567890ABCDEF_u64;
3664 println!("K =\t{:#016X}", key);
3665 let mut a_des = DES::new_with_key_u64(key);
3666
3667 let message = "In the beginning God created the heavens and the earth.";
3668 println!("M =\t{}", message);
3669 let iv = 0x_FEDCBA0987654321_u64;
3670 println!("IV = {}", iv);
3671 let mut cipher = Vec::<u8>::new();
3672 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3673 print!("C (16 rounds) =\t");
3674 for c in cipher.clone()
3675 { print!("{:02X} ", c); }
3676 println!();
3677 let mut txt = String::new();
3678 for c in cipher.clone()
3679 { write!(txt, "{:02X} ", c); }
3680 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
3681
3682 let mut recovered = [0u8; 56];
3683 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3684 print!("Ba (16 rounds) =\t");
3685 for b in recovered.clone()
3686 { print!("{:02X} ", b); }
3687 println!();
3688 let mut txt = String::new();
3689 for c in recovered.clone()
3690 { write!(txt, "{:02X} ", c); }
3691 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3692
3693 let mut converted = String::new();
3694 unsafe { converted.as_mut_vec() }.write(&recovered);
3695 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3696 println!("Bb (16 rounds) =\t{}", converted);
3697 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3698 assert_eq!(converted, message);
3699 println!();
3700
3701 // Expanded case for 128 rounds
3702 let key = 0x_1234567890ABCDEF_u64;
3703 println!("K =\t{:#016X}", key);
3704 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3705
3706 let message = "In the beginning God created the heavens and the earth.";
3707 println!("M =\t{}", message);
3708 let iv = 0x_FEDCBA0987654321_u64;
3709 println!("IV = {}", iv);
3710 let mut cipher = Vec::<u8>::new();
3711 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3712 print!("C (128 rounds) =\t");
3713 for c in cipher.clone()
3714 { print!("{:02X} ", c); }
3715 println!();
3716 let mut txt = String::new();
3717 for c in cipher.clone()
3718 { write!(txt, "{:02X} ", c); }
3719 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
3720
3721 let mut recovered = [0u8; 56];
3722 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3723 print!("Ba (16 rounds) =\t");
3724 for b in recovered.clone()
3725 { print!("{:02X} ", b); }
3726 println!();
3727 let mut txt = String::new();
3728 for c in recovered.clone()
3729 { write!(txt, "{:02X} ", c); }
3730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3731
3732 let mut converted = String::new();
3733 unsafe { converted.as_mut_vec() }.write(&recovered);
3734 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3735 println!("Bb (16 rounds) =\t{}", converted);
3736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3737 assert_eq!(converted, message);
3738 println!();
3739
3740 // Expanded case for 0 rounds which means that key is meaningless
3741 let key1 = 0x_1234567890ABCDEF_u64;
3742 let key2 = 0_u64;
3743 println!("K =\t{:#016X}", key);
3744 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3745 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3746
3747 let message = "In the beginning God created the heavens and the earth.";
3748 println!("M =\t{}", message);
3749 let iv = 0x_FEDCBA0987654321_u64;
3750 println!("IV = {}", iv);
3751 let mut cipher1 = Vec::<u8>::new();
3752 let mut cipher2 = Vec::<u8>::new();
3753 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
3754 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
3755 print!("C (0 rounds) =\t");
3756 for c in cipher1.clone()
3757 { print!("{:02X} ", c); }
3758 println!();
3759 let mut txt = String::new();
3760 for c in cipher1.clone()
3761 { write!(txt, "{:02X} ", c); }
3762 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
3763 print!("D (0 rounds) =\t");
3764 for c in cipher2.clone()
3765 { print!("{:02X} ", c); }
3766 println!();
3767 let mut txt = String::new();
3768 for c in cipher2.clone()
3769 { write!(txt, "{:02X} ", c); }
3770 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
3771
3772 let mut recovered1 = [0u8; 56];
3773 let mut recovered2 = [0u8; 56];
3774 let len1 = c_des.decrypt_into_array(iv, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3775 let len2 = d_des.decrypt_into_array(iv, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3776 print!("B1a (0 rounds) =\t");
3777 for b in recovered1.clone()
3778 { print!("{:02X} ", b); }
3779 println!();
3780 let mut txt = String::new();
3781 for c in recovered1.clone()
3782 { write!(txt, "{:02X} ", c); }
3783 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3784 print!("B2a (0 rounds) =\t");
3785 for b in recovered2.clone()
3786 { print!("{:02X} ", b); }
3787 println!();
3788 let mut txt = String::new();
3789 for c in recovered.clone()
3790 { write!(txt, "{:02X} ", c); }
3791 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3792
3793 let mut converted1 = String::new();
3794 let mut converted2 = String::new();
3795 unsafe { converted1.as_mut_vec() }.write(&recovered1);
3796 unsafe { converted2.as_mut_vec() }.write(&recovered2);
3797 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3798 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3799 println!("B1b (0 rounds) =\t{}", converted1);
3800 println!("B2b (0 rounds) =\t{}", converted2);
3801 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3802 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3803 assert_eq!(converted1, message);
3804 assert_eq!(converted2, message);
3805 assert_eq!(converted1, converted2);
3806 println!();
3807
3808 // Normal case for the message of 0 bytes
3809 let key = 0x_1234567890ABCDEF_u64;
3810 println!("K =\t{:#016X}", key);
3811 let mut a_des = DES::new_with_key_u64(key);
3812
3813 let message = "";
3814 println!("M =\t{}", message);
3815 let iv = 0x_FEDCBA0987654321_u64;
3816 println!("IV = {}", iv);
3817 let mut cipher = Vec::<u8>::new();
3818 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3819 print!("C =\t");
3820 for c in cipher.clone()
3821 { print!("{:02X} ", c); }
3822 println!();
3823 let mut txt = String::new();
3824 for c in cipher.clone()
3825 { write!(txt, "{:02X} ", c); }
3826 assert_eq!(txt, "");
3827
3828 let mut recovered = [0u8; 8];
3829 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3830
3831 print!("Ba =\t");
3832 for b in recovered.clone()
3833 { print!("{:02X} ", b); }
3834 println!();
3835 let mut txt = String::new();
3836 for c in recovered.clone()
3837 { write!(txt, "{:02X} ", c); }
3838 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3839
3840 let mut converted = String::new();
3841 unsafe { converted.as_mut_vec() }.write(&recovered);
3842 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3843 println!("Bb =\t{}", converted);
3844 assert_eq!(converted, "");
3845 assert_eq!(converted, message);
3846 println!();
3847
3848 // Normal case for the message shorter than 8 bytes
3849 let key = 0x_1234567890ABCDEF_u64;
3850 println!("K =\t{:#016X}", key);
3851 let mut a_des = DES::new_with_key_u64(key);
3852
3853 let message = "7 bytes";
3854 println!("M =\t{}", message);
3855 let iv = 0x_FEDCBA0987654321_u64;
3856 println!("IV = {}", iv);
3857 let mut cipher = Vec::<u8>::new();
3858 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3859 print!("C =\t");
3860 for c in cipher.clone()
3861 { print!("{:02X} ", c); }
3862 println!();
3863 let mut txt = String::new();
3864 for c in cipher.clone()
3865 { write!(txt, "{:02X} ", c); }
3866 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
3867
3868 let mut recovered = [0u8; 8];
3869 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3870
3871 print!("Ba =\t");
3872 for b in recovered.clone()
3873 { print!("{:02X} ", b); }
3874 println!();
3875 let mut txt = String::new();
3876 for c in recovered.clone()
3877 { write!(txt, "{:02X} ", c); }
3878 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3879
3880 let mut converted = String::new();
3881 unsafe { converted.as_mut_vec() }.write(&recovered);
3882 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3883 println!("Bb =\t{}", converted);
3884 assert_eq!(converted, "7 bytes");
3885 assert_eq!(converted, message);
3886 println!();
3887
3888 // Normal case for the message of 8 bytes
3889 let key = 0x_1234567890ABCDEF_u64;
3890 println!("K =\t{:#016X}", key);
3891 let mut a_des = DES::new_with_key_u64(key);
3892
3893 let message = "I am OK.";
3894 println!("M =\t{}", message);
3895 let iv = 0x_FEDCBA0987654321_u64;
3896 println!("IV = {}", iv);
3897 let mut cipher = Vec::<u8>::new();
3898 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3899 print!("C =\t");
3900 for c in cipher.clone()
3901 { print!("{:02X} ", c); }
3902 println!();
3903 let mut txt = String::new();
3904 for c in cipher.clone()
3905 { write!(txt, "{:02X} ", c); }
3906 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
3907
3908 let mut recovered = [0u8; 16];
3909 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3910
3911 print!("Ba =\t");
3912 for b in recovered.clone()
3913 { print!("{:02X} ", b); }
3914 println!();
3915 let mut txt = String::new();
3916 for c in recovered.clone()
3917 { write!(txt, "{:02X} ", c); }
3918 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3919
3920 let mut converted = String::new();
3921 unsafe { converted.as_mut_vec() }.write(&recovered);
3922 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3923 println!("Bb =\t{}", converted);
3924 assert_eq!(converted, "I am OK.");
3925 assert_eq!(converted, message);
3926 println!();
3927
3928 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3929 let key = 0x_1234567890ABCDEF_u64;
3930 println!("K =\t{:#016X}", key);
3931 let mut a_des = DES::new_with_key_u64(key);
3932
3933 let message = "PARK Youngho";
3934 println!("M =\t{}", message);
3935 let iv = 0x_FEDCBA0987654321_u64;
3936 println!("IV = {}", iv);
3937 let mut cipher = Vec::<u8>::new();
3938 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3939 print!("C =\t");
3940 for c in cipher.clone()
3941 { print!("{:02X} ", c); }
3942 println!();
3943 let mut txt = String::new();
3944 for c in cipher.clone()
3945 { write!(txt, "{:02X} ", c); }
3946 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
3947
3948 let mut recovered = [0u8; 16];
3949 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3950
3951 print!("Ba =\t");
3952 for b in recovered.clone()
3953 { print!("{:02X} ", b); }
3954 println!();
3955 let mut txt = String::new();
3956 for c in recovered.clone()
3957 { write!(txt, "{:02X} ", c); }
3958 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3959
3960 let mut converted = String::new();
3961 unsafe { converted.as_mut_vec() }.write(&recovered);
3962 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3963 println!("Bb =\t{}", converted);
3964 assert_eq!(converted, "PARK Youngho");
3965 assert_eq!(converted, message);
3966 println!();
3967
3968 // Normal case for the message of 16 bytes
3969 let key = 0x_1234567890ABCDEF_u64;
3970 println!("K =\t{:#016X}", key);
3971 let mut a_des = DES::new_with_key_u64(key);
3972
3973 let message = "고맙습니다.";
3974 println!("M =\t{}", message);
3975 let iv = 0x_FEDCBA0987654321_u64;
3976 println!("IV = {}", iv);
3977 let mut cipher = Vec::<u8>::new();
3978 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
3979 print!("C =\t");
3980 for c in cipher.clone()
3981 { print!("{:02X} ", c); }
3982 println!();
3983 let mut txt = String::new();
3984 for c in cipher.clone()
3985 { write!(txt, "{:02X} ", c); }
3986 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
3987
3988 let mut recovered = [0u8; 24];
3989 let len = a_des.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3990
3991 print!("Ba =\t");
3992 for b in recovered.clone()
3993 { print!("{:02X} ", b); }
3994 println!();
3995 let mut txt = String::new();
3996 for c in recovered.clone()
3997 { write!(txt, "{:02X} ", c); }
3998 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3999
4000 let mut converted = String::new();
4001 unsafe { converted.as_mut_vec() }.write(&recovered);
4002 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4003 println!("Bb =\t{}", converted);
4004 assert_eq!(converted, "고맙습니다.");
4005 assert_eq!(converted, message);
4006 println!("-------------------------------");
4007}
4008
4009fn des_decrypt_ofb_into_string()
4010{
4011 println!("des_decrypt_ofb_into_string()");
4012 use std::io::Write;
4013 use std::fmt::Write as _;
4014 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
4015
4016 // Normal case
4017 let key = 0x_1234567890ABCDEF_u64;
4018 println!("K =\t{:#016X}", key);
4019 let mut a_des = DES::new_with_key_u64(key);
4020
4021 let message = "In the beginning God created the heavens and the earth.";
4022 println!("M =\t{}", message);
4023 let iv = 0x_FEDCBA0987654321_u64;
4024 println!("IV = {}", iv);
4025 let mut cipher = Vec::<u8>::new();
4026 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4027 print!("C (16 rounds) =\t");
4028 for c in cipher.clone()
4029 { print!("{:02X} ", c); }
4030 println!();
4031 let mut txt = String::new();
4032 for c in cipher.clone()
4033 { write!(txt, "{:02X} ", c); }
4034 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
4035
4036 let mut recovered = String::new();
4037 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4038 println!("B (16 rounds) =\t{}", recovered);
4039 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4040 assert_eq!(recovered, message);
4041 println!();
4042
4043 // Expanded case for 128 rounds
4044 let key = 0x_1234567890ABCDEF_u64;
4045 println!("K =\t{:#016X}", key);
4046 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4047
4048 let message = "In the beginning God created the heavens and the earth.";
4049 println!("M =\t{}", message);
4050 let iv = 0x_FEDCBA0987654321_u64;
4051 println!("IV = {}", iv);
4052 let mut cipher = Vec::<u8>::new();
4053 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4054 print!("C (128 rounds) =\t");
4055 for c in cipher.clone()
4056 { print!("{:02X} ", c); }
4057 println!();
4058 let mut txt = String::new();
4059 for c in cipher.clone()
4060 { write!(txt, "{:02X} ", c); }
4061 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
4062
4063 let mut recovered = String::new();
4064 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4065 println!("B (128 rounds) =\t{}", recovered);
4066 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4067 assert_eq!(recovered, message);
4068 println!();
4069
4070 // Expanded case for 0 rounds which means that key is meaningless
4071 let key1 = 0x_1234567890ABCDEF_u64;
4072 let key2 = 0_u64;
4073 println!("K =\t{:#016X}", key);
4074 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4075 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4076
4077 let message = "In the beginning God created the heavens and the earth.";
4078 println!("M =\t{}", message);
4079 let iv = 0x_FEDCBA0987654321_u64;
4080 println!("IV = {}", iv);
4081 let mut cipher1 = Vec::<u8>::new();
4082 let mut cipher2 = Vec::<u8>::new();
4083 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
4084 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
4085 print!("C (0 rounds) =\t");
4086 for c in cipher1.clone()
4087 { print!("{:02X} ", c); }
4088 println!();
4089 let mut txt = String::new();
4090 for c in cipher1.clone()
4091 { write!(txt, "{:02X} ", c); }
4092 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
4093 print!("D (0 rounds) =\t");
4094 for c in cipher2.clone()
4095 { print!("{:02X} ", c); }
4096 println!();
4097 let mut txt = String::new();
4098 for c in cipher2.clone()
4099 { write!(txt, "{:02X} ", c); }
4100 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
4101
4102 let mut recovered1 = String::new();
4103 let mut recovered2 = String::new();
4104 c_des.decrypt_into_string(iv, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
4105 d_des.decrypt_into_string(iv, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
4106 println!("B1 (0 rounds) =\t{}", recovered1);
4107 println!("B2 (0 rounds) =\t{}", recovered2);
4108 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
4109 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
4110 assert_eq!(recovered1, message);
4111 assert_eq!(recovered2, message);
4112 assert_eq!(recovered1, recovered2);
4113 println!();
4114
4115 // Normal case for the message of 0 bytes
4116 let key = 0x_1234567890ABCDEF_u64;
4117 println!("K =\t{:#016X}", key);
4118 let mut a_des = DES::new_with_key_u64(key);
4119
4120 let message = "";
4121 println!("M =\t{}", message);
4122 let iv = 0x_FEDCBA0987654321_u64;
4123 println!("IV = {}", iv);
4124 let mut cipher = Vec::<u8>::new();
4125 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4126 print!("C =\t");
4127 for c in cipher.clone()
4128 { print!("{:02X} ", c); }
4129 println!();
4130 let mut txt = String::new();
4131 for c in cipher.clone()
4132 { write!(txt, "{:02X} ", c); }
4133 assert_eq!(txt, "");
4134
4135 let mut recovered = String::new();
4136 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4137 println!("B =\t{}", recovered);
4138 assert_eq!(recovered, "");
4139 assert_eq!(recovered, message);
4140 println!();
4141
4142 // Normal case for the message shorter than 8 bytes
4143 let key = 0x_1234567890ABCDEF_u64;
4144 println!("K =\t{:#016X}", key);
4145 let mut a_des = DES::new_with_key_u64(key);
4146
4147 let message = "7 bytes";
4148 println!("M =\t{}", message);
4149 let iv = 0x_FEDCBA0987654321_u64;
4150 println!("IV = {}", iv);
4151 let mut cipher = Vec::<u8>::new();
4152 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4153 print!("C =\t");
4154 for c in cipher.clone()
4155 { print!("{:02X} ", c); }
4156 println!();
4157 let mut txt = String::new();
4158 for c in cipher.clone()
4159 { write!(txt, "{:02X} ", c); }
4160 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
4161
4162 let mut recovered = String::new();
4163 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4164 println!("B =\t{}", recovered);
4165 assert_eq!(recovered, "7 bytes");
4166 assert_eq!(recovered, message);
4167 println!();
4168
4169 // Normal case for the message of 8 bytes
4170 let key = 0x_1234567890ABCDEF_u64;
4171 println!("K =\t{:#016X}", key);
4172 let mut a_des = DES::new_with_key_u64(key);
4173
4174 let message = "I am OK.";
4175 println!("M =\t{}", message);
4176 let iv = 0x_FEDCBA0987654321_u64;
4177 println!("IV = {}", iv);
4178 let mut cipher = Vec::<u8>::new();
4179 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4180 print!("C =\t");
4181 for c in cipher.clone()
4182 { print!("{:02X} ", c); }
4183 println!();
4184 let mut txt = String::new();
4185 for c in cipher.clone()
4186 { write!(txt, "{:02X} ", c); }
4187 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
4188
4189 let mut recovered = String::new();
4190 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4191 println!("B =\t{}", recovered);
4192 assert_eq!(recovered, "I am OK.");
4193 assert_eq!(recovered, message);
4194 println!();
4195
4196 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4197 let key = 0x_1234567890ABCDEF_u64;
4198 println!("K =\t{:#016X}", key);
4199 let mut a_des = DES::new_with_key_u64(key);
4200
4201 let message = "PARK Youngho";
4202 println!("M =\t{}", message);
4203 let iv = 0x_FEDCBA0987654321_u64;
4204 println!("IV = {}", iv);
4205 let mut cipher = Vec::<u8>::new();
4206 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4207 print!("C =\t");
4208 for c in cipher.clone()
4209 { print!("{:02X} ", c); }
4210 println!();
4211 let mut txt = String::new();
4212 for c in cipher.clone()
4213 { write!(txt, "{:02X} ", c); }
4214 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
4215
4216 let mut recovered = String::new();
4217 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4218 println!("B =\t{}", recovered);
4219 assert_eq!(recovered, "PARK Youngho");
4220 assert_eq!(recovered, message);
4221 println!();
4222
4223 // Normal case for the message of 16 bytes
4224 let key = 0x_1234567890ABCDEF_u64;
4225 println!("K =\t{:#016X}", key);
4226 let mut a_des = DES::new_with_key_u64(key);
4227
4228 let message = "고맙습니다.";
4229 println!("M =\t{}", message);
4230 let iv = 0x_FEDCBA0987654321_u64;
4231 println!("IV = {}", iv);
4232 let mut cipher = Vec::<u8>::new();
4233 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4234 print!("C =\t");
4235 for c in cipher.clone()
4236 { print!("{:02X} ", c); }
4237 println!();
4238 let mut txt = String::new();
4239 for c in cipher.clone()
4240 { write!(txt, "{:02X} ", c); }
4241 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
4242
4243 let mut recovered = String::new();
4244 a_des.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4245 println!("B =\t{}", recovered);
4246 assert_eq!(recovered, "고맙습니다.");
4247 assert_eq!(recovered, message);
4248 println!("-------------------------------");
4249}
4250
4251fn des_decrypt_vec_ofb()
4252{
4253 println!("des_decrypt_vec_ofb()");
4254 use std::io::Write;
4255 use std::fmt::Write as _;
4256 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
4257
4258 // Normal case
4259 let key = 0x_1234567890ABCDEF_u64;
4260 println!("K =\t{:#016X}", key);
4261 let mut a_des = DES::new_with_key_u64(key);
4262
4263 let message = "In the beginning God created the heavens and the earth.";
4264 println!("M =\t{}", message);
4265 let iv = 0x_FEDCBA0987654321_u64;
4266 println!("IV = {}", iv);
4267 let mut cipher = Vec::<u8>::new();
4268 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4269 print!("C (16 rounds) =\t");
4270 for c in cipher.clone()
4271 { print!("{:02X} ", c); }
4272 println!();
4273 let mut txt = String::new();
4274 for c in cipher.clone()
4275 { write!(txt, "{:02X} ", c); }
4276 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
4277
4278 let mut recovered = vec![0; 55];
4279 a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4280 print!("Ba (16 rounds) =\t");
4281 for b in recovered.clone()
4282 { print!("{:02X} ", b); }
4283 println!();
4284 let mut txt = String::new();
4285 for c in recovered.clone()
4286 { write!(txt, "{:02X} ", c); }
4287 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4288
4289 let mut converted = String::new();
4290 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4291
4292 println!("Bb (16 rounds) =\t{}", converted);
4293 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4294 assert_eq!(converted, message);
4295 println!();
4296
4297 // Expanded case for 128 rounds
4298 let key = 0x_1234567890ABCDEF_u64;
4299 println!("K =\t{:#016X}", key);
4300 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4301
4302 let message = "In the beginning God created the heavens and the earth.";
4303 println!("M =\t{}", message);
4304 let iv = 0x_FEDCBA0987654321_u64;
4305 println!("IV = {}", iv);
4306 let mut cipher = Vec::<u8>::new();
4307 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4308 print!("C (128 rounds) =\t");
4309 for c in cipher.clone()
4310 { print!("{:02X} ", c); }
4311 println!();
4312 let mut txt = String::new();
4313 for c in cipher.clone()
4314 { write!(txt, "{:02X} ", c); }
4315 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
4316
4317 let mut recovered = vec![0; 55];
4318 a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4319 print!("Ba (128 rounds) =\t");
4320 for b in recovered.clone()
4321 { print!("{:02X} ", b); }
4322 println!();
4323 let mut txt = String::new();
4324 for c in recovered.clone()
4325 { write!(txt, "{:02X} ", c); }
4326 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4327
4328 let mut converted = String::new();
4329 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4330
4331 println!("Bb (128 rounds) =\t{}", converted);
4332 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4333 assert_eq!(converted, message);
4334 println!();
4335
4336 // Expanded case for 0 rounds which means that key is meaningless
4337 let key1 = 0x_1234567890ABCDEF_u64;
4338 let key2 = 0_u64;
4339 println!("K =\t{:#016X}", key);
4340 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4341 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4342
4343 let message = "In the beginning God created the heavens and the earth.";
4344 println!("M =\t{}", message);
4345 let iv = 0x_FEDCBA0987654321_u64;
4346 println!("IV = {}", iv);
4347 let mut cipher1 = Vec::<u8>::new();
4348 let mut cipher2 = Vec::<u8>::new();
4349 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
4350 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
4351 print!("C (0 rounds) =\t");
4352 for c in cipher1.clone()
4353 { print!("{:02X} ", c); }
4354 println!();
4355 let mut txt = String::new();
4356 for c in cipher1.clone()
4357 { write!(txt, "{:02X} ", c); }
4358 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
4359 print!("D (0 rounds) =\t");
4360 for c in cipher2.clone()
4361 { print!("{:02X} ", c); }
4362 println!();
4363 let mut txt = String::new();
4364 for c in cipher2.clone()
4365 { write!(txt, "{:02X} ", c); }
4366 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
4367
4368 let mut recovered1 = vec![0; 55];
4369 let mut recovered2 = vec![0; 55];
4370 c_des.decrypt_vec(iv, &cipher1, recovered1.as_mut_ptr());
4371 d_des.decrypt_vec(iv, &cipher2, recovered2.as_mut_ptr());
4372 print!("B1a (0 rounds) =\t");
4373 for b in recovered1.clone()
4374 { print!("{:02X} ", b); }
4375 println!();
4376 let mut txt = String::new();
4377 for c in recovered1.clone()
4378 { write!(txt, "{:02X} ", c); }
4379 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4380 print!("B2a (0 rounds) =\t");
4381 for b in recovered2.clone()
4382 { print!("{:02X} ", b); }
4383 println!();
4384 let mut txt = String::new();
4385 for c in recovered2.clone()
4386 { write!(txt, "{:02X} ", c); }
4387 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4388
4389 let mut converted1 = String::new();
4390 let mut converted2 = String::new();
4391 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4392 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4393
4394 println!("B1b (0 rounds) =\t{}", converted1);
4395 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4396 assert_eq!(converted1, message);
4397 println!("B2b (0 rounds) =\t{}", converted2);
4398 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4399 assert_eq!(converted2, message);
4400 assert_eq!(converted1, converted1);
4401 println!();
4402
4403 // Normal case for the message of 0 bytes
4404 let key = 0x_1234567890ABCDEF_u64;
4405 println!("K =\t{:#016X}", key);
4406 let mut a_des = DES::new_with_key_u64(key);
4407
4408 let message = "";
4409 println!("M =\t{}", message);
4410 let iv = 0x_FEDCBA0987654321_u64;
4411 println!("IV = {}", iv);
4412 let mut cipher = Vec::<u8>::new();
4413 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4414 print!("C =\t");
4415 for c in cipher.clone()
4416 { print!("{:02X} ", c); }
4417 println!();
4418 let mut txt = String::new();
4419 for c in cipher.clone()
4420 { write!(txt, "{:02X} ", c); }
4421 assert_eq!(txt, "");
4422
4423 let mut recovered = vec![0; 8];
4424 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4425 print!("Ba =\t");
4426 for b in recovered.clone()
4427 { print!("{:02X} ", b); }
4428 println!();
4429 let mut txt = String::new();
4430 for c in recovered.clone()
4431 { write!(txt, "{:02X} ", c); }
4432 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4433
4434 let mut converted = String::new();
4435 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4436 converted.truncate(len as usize);
4437
4438 println!("Bb =\t{}", converted);
4439 assert_eq!(converted, "");
4440 assert_eq!(converted, message);
4441 println!();
4442
4443 // Normal case for the message shorter than 8 bytes
4444 let key = 0x_1234567890ABCDEF_u64;
4445 println!("K =\t{:#016X}", key);
4446 let mut a_des = DES::new_with_key_u64(key);
4447
4448 let message = "7 bytes";
4449 println!("M =\t{}", message);
4450 let iv = 0x_FEDCBA0987654321_u64;
4451 println!("IV = {}", iv);
4452 let mut cipher = Vec::<u8>::new();
4453 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4454 print!("C =\t");
4455 for c in cipher.clone()
4456 { print!("{:02X} ", c); }
4457 println!();
4458 let mut txt = String::new();
4459 for c in cipher.clone()
4460 { write!(txt, "{:02X} ", c); }
4461 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
4462
4463 let mut recovered = vec![0; 8];
4464 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4465 print!("Ba =\t");
4466 for b in recovered.clone()
4467 { print!("{:02X} ", b); }
4468 println!();
4469 let mut txt = String::new();
4470 for c in recovered.clone()
4471 { write!(txt, "{:02X} ", c); }
4472 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4473
4474 let mut converted = String::new();
4475 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4476 converted.truncate(len as usize);
4477
4478 println!("Bb =\t{}", converted);
4479 assert_eq!(converted, "7 bytes");
4480 assert_eq!(converted, message);
4481 println!();
4482
4483 // Normal case for the message of 8 bytes
4484 let key = 0x_1234567890ABCDEF_u64;
4485 println!("K =\t{:#016X}", key);
4486 let mut a_des = DES::new_with_key_u64(key);
4487
4488 let message = "I am OK.";
4489 println!("M =\t{}", message);
4490 let iv = 0x_FEDCBA0987654321_u64;
4491 println!("IV = {}", iv);
4492 let mut cipher = Vec::<u8>::new();
4493 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4494 print!("C =\t");
4495 for c in cipher.clone()
4496 { print!("{:02X} ", c); }
4497 println!();
4498 let mut txt = String::new();
4499 for c in cipher.clone()
4500 { write!(txt, "{:02X} ", c); }
4501 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
4502
4503 let mut recovered = vec![0; 16];
4504 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4505 print!("Ba =\t");
4506 for b in recovered.clone()
4507 { print!("{:02X} ", b); }
4508 println!();
4509 let mut txt = String::new();
4510 for c in recovered.clone()
4511 { write!(txt, "{:02X} ", c); }
4512 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4513
4514 let mut converted = String::new();
4515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4516 converted.truncate(len as usize);
4517
4518 println!("Bb =\t{}", converted);
4519 assert_eq!(converted, "I am OK.");
4520 assert_eq!(converted, message);
4521 println!();
4522
4523 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4524 let key = 0x_1234567890ABCDEF_u64;
4525 println!("K =\t{:#016X}", key);
4526 let mut a_des = DES::new_with_key_u64(key);
4527
4528 let message = "PARK Youngho";
4529 println!("M =\t{}", message);
4530 let iv = 0x_FEDCBA0987654321_u64;
4531 println!("IV = {}", iv);
4532 let mut cipher = Vec::<u8>::new();
4533 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4534 print!("C =\t");
4535 for c in cipher.clone()
4536 { print!("{:02X} ", c); }
4537 println!();
4538 let mut txt = String::new();
4539 for c in cipher.clone()
4540 { write!(txt, "{:02X} ", c); }
4541 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
4542
4543 let mut recovered = vec![0; 16];
4544 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4545 print!("Ba =\t");
4546 for b in recovered.clone()
4547 { print!("{:02X} ", b); }
4548 println!();
4549 let mut txt = String::new();
4550 for c in recovered.clone()
4551 { write!(txt, "{:02X} ", c); }
4552 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4553
4554 let mut converted = String::new();
4555 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4556 converted.truncate(len as usize);
4557
4558 println!("Bb =\t{}", converted);
4559 assert_eq!(converted, "PARK Youngho");
4560 assert_eq!(converted, message);
4561 println!();
4562
4563 // Normal case for the message of 16 bytes
4564 let key = 0x_1234567890ABCDEF_u64;
4565 println!("K =\t{:#016X}", key);
4566 let mut a_des = DES::new_with_key_u64(key);
4567
4568 let message = "고맙습니다.";
4569 println!("M =\t{}", message);
4570 let iv = 0x_FEDCBA0987654321_u64;
4571 println!("IV = {}", iv);
4572 let mut cipher = Vec::<u8>::new();
4573 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4574 print!("C =\t");
4575 for c in cipher.clone()
4576 { print!("{:02X} ", c); }
4577 println!();
4578 let mut txt = String::new();
4579 for c in cipher.clone()
4580 { write!(txt, "{:02X} ", c); }
4581 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
4582
4583 let mut recovered = vec![0; 24];
4584 let len = a_des.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
4585 print!("Ba =\t");
4586 for b in recovered.clone()
4587 { print!("{:02X} ", b); }
4588 println!();
4589 let mut txt = String::new();
4590 for c in recovered.clone()
4591 { write!(txt, "{:02X} ", c); }
4592 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4593
4594 let mut converted = String::new();
4595 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4596 converted.truncate(len as usize);
4597
4598 println!("Bb =\t{}", converted);
4599 assert_eq!(converted, "고맙습니다.");
4600 assert_eq!(converted, message);
4601 println!("-------------------------------");
4602}
4603
4604fn des_decrypt_vec_ofb_into_vec()
4605{
4606 println!("des_decrypt_vec_ofb_into_vec()");
4607 use std::io::Write;
4608 use std::fmt::Write as _;
4609 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
4610
4611 // Normal case
4612 let key = 0x_1234567890ABCDEF_u64;
4613 println!("K =\t{:#016X}", key);
4614 let mut a_des = DES::new_with_key_u64(key);
4615
4616 let message = "In the beginning God created the heavens and the earth.";
4617 println!("M =\t{}", message);
4618 let iv = 0x_FEDCBA0987654321_u64;
4619 println!("IV = {}", iv);
4620 let mut cipher = Vec::<u8>::new();
4621 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4622 print!("C (16 rounds) =\t");
4623 for c in cipher.clone()
4624 { print!("{:02X} ", c); }
4625 println!();
4626 let mut txt = String::new();
4627 for c in cipher.clone()
4628 { write!(txt, "{:02X} ", c); }
4629 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
4630
4631 let mut recovered = Vec::<u8>::new();
4632 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4633 print!("Ba (16 rounds) =\t");
4634 for b in recovered.clone()
4635 { print!("{:02X} ", b); }
4636 println!();
4637 let mut txt = String::new();
4638 for c in recovered.clone()
4639 { write!(txt, "{:02X} ", c); }
4640 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4641
4642 let mut converted = String::new();
4643 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4644
4645 println!("Bb (16 rounds) =\t{}", converted);
4646 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4647 assert_eq!(converted, message);
4648 println!();
4649
4650 // Expanded case for 128 rounds
4651 let key = 0x_1234567890ABCDEF_u64;
4652 println!("K =\t{:#016X}", key);
4653 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4654
4655 let message = "In the beginning God created the heavens and the earth.";
4656 println!("M =\t{}", message);
4657 let iv = 0x_FEDCBA0987654321_u64;
4658 println!("IV = {}", iv);
4659 let mut cipher = Vec::<u8>::new();
4660 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4661 print!("C (128 rounds) =\t");
4662 for c in cipher.clone()
4663 { print!("{:02X} ", c); }
4664 println!();
4665 let mut txt = String::new();
4666 for c in cipher.clone()
4667 { write!(txt, "{:02X} ", c); }
4668 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
4669
4670 let mut recovered = Vec::<u8>::new();
4671 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4672 print!("Ba (128 rounds) =\t");
4673 for b in recovered.clone()
4674 { print!("{:02X} ", b); }
4675 println!();
4676 let mut txt = String::new();
4677 for c in recovered.clone()
4678 { write!(txt, "{:02X} ", c); }
4679 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4680
4681 let mut converted = String::new();
4682 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4683
4684 println!("Bb (128 rounds) =\t{}", converted);
4685 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4686 assert_eq!(converted, message);
4687 println!();
4688
4689 // Expanded case for 0 rounds which means that key is meaningless
4690 let key1 = 0x_1234567890ABCDEF_u64;
4691 let key2 = 0_u64;
4692 println!("K =\t{:#016X}", key);
4693 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4694 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4695
4696 let message = "In the beginning God created the heavens and the earth.";
4697 println!("M =\t{}", message);
4698 let iv = 0x_FEDCBA0987654321_u64;
4699 println!("IV = {}", iv);
4700 let mut cipher1 = Vec::<u8>::new();
4701 let mut cipher2 = Vec::<u8>::new();
4702 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
4703 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
4704 print!("C (0 rounds) =\t");
4705 for c in cipher1.clone()
4706 { print!("{:02X} ", c); }
4707 println!();
4708 let mut txt = String::new();
4709 for c in cipher1.clone()
4710 { write!(txt, "{:02X} ", c); }
4711 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
4712 print!("D (0 rounds) =\t");
4713 for c in cipher2.clone()
4714 { print!("{:02X} ", c); }
4715 println!();
4716 let mut txt = String::new();
4717 for c in cipher2.clone()
4718 { write!(txt, "{:02X} ", c); }
4719 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
4720
4721 let mut recovered1 = Vec::<u8>::new();
4722 let mut recovered2 = Vec::<u8>::new();
4723 c_des.decrypt_vec_into_vec(iv, &cipher1, &mut recovered1);
4724 d_des.decrypt_vec_into_vec(iv, &cipher2, &mut recovered2);
4725 print!("B1a (0 rounds) =\t");
4726 for b in recovered1.clone()
4727 { print!("{:02X} ", b); }
4728 println!();
4729 let mut txt = String::new();
4730 for c in recovered1.clone()
4731 { write!(txt, "{:02X} ", c); }
4732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4733 print!("B2a (0 rounds) =\t");
4734 for b in recovered2.clone()
4735 { print!("{:02X} ", b); }
4736 println!();
4737 let mut txt = String::new();
4738 for c in recovered2.clone()
4739 { write!(txt, "{:02X} ", c); }
4740 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4741
4742 let mut converted1 = String::new();
4743 let mut converted2 = String::new();
4744 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4745 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4746
4747 println!("B1b (0 rounds) =\t{}", converted1);
4748 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4749 assert_eq!(converted1, message);
4750 println!("B2b (0 rounds) =\t{}", converted2);
4751 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4752 assert_eq!(converted2, message);
4753 assert_eq!(converted1, converted1);
4754 println!();
4755
4756 // Normal case for the message of 0 bytes
4757 let key = 0x_1234567890ABCDEF_u64;
4758 println!("K =\t{:#016X}", key);
4759 let mut a_des = DES::new_with_key_u64(key);
4760
4761 let message = "";
4762 println!("M =\t{}", message);
4763 let iv = 0x_FEDCBA0987654321_u64;
4764 println!("IV = {}", iv);
4765 let mut cipher = Vec::<u8>::new();
4766 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4767 print!("C =\t");
4768 for c in cipher.clone()
4769 { print!("{:02X} ", c); }
4770 println!();
4771 let mut txt = String::new();
4772 for c in cipher.clone()
4773 { write!(txt, "{:02X} ", c); }
4774 assert_eq!(txt, "");
4775
4776 let mut recovered = Vec::<u8>::new();
4777 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4778 print!("Ba =\t");
4779 for b in recovered.clone()
4780 { print!("{:02X} ", b); }
4781 println!();
4782 let mut txt = String::new();
4783 for c in recovered.clone()
4784 { write!(txt, "{:02X} ", c); }
4785 assert_eq!(txt, "");
4786
4787 let mut converted = String::new();
4788 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4789
4790 println!("Bb =\t{}", converted);
4791 assert_eq!(converted, "");
4792 assert_eq!(converted, message);
4793 println!();
4794
4795 // Normal case for the message shorter than 8 bytes
4796 let key = 0x_1234567890ABCDEF_u64;
4797 println!("K =\t{:#016X}", key);
4798 let mut a_des = DES::new_with_key_u64(key);
4799
4800 let message = "7 bytes";
4801 println!("M =\t{}", message);
4802 let iv = 0x_FEDCBA0987654321_u64;
4803 println!("IV = {}", iv);
4804 let mut cipher = Vec::<u8>::new();
4805 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4806 print!("C =\t");
4807 for c in cipher.clone()
4808 { print!("{:02X} ", c); }
4809 println!();
4810 let mut txt = String::new();
4811 for c in cipher.clone()
4812 { write!(txt, "{:02X} ", c); }
4813 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
4814
4815 let mut recovered = Vec::<u8>::new();
4816 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4817 print!("Ba =\t");
4818 for b in recovered.clone()
4819 { print!("{:02X} ", b); }
4820 println!();
4821 let mut txt = String::new();
4822 for c in recovered.clone()
4823 { write!(txt, "{:02X} ", c); }
4824 assert_eq!(txt, "37 20 62 79 74 65 73 ");
4825
4826 let mut converted = String::new();
4827 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4828
4829 println!("Bb =\t{}", converted);
4830 assert_eq!(converted, "7 bytes");
4831 assert_eq!(converted, message);
4832 println!();
4833
4834 // Normal case for the message of 8 bytes
4835 let key = 0x_1234567890ABCDEF_u64;
4836 println!("K =\t{:#016X}", key);
4837 let mut a_des = DES::new_with_key_u64(key);
4838
4839 let message = "I am OK.";
4840 println!("M =\t{}", message);
4841 let iv = 0x_FEDCBA0987654321_u64;
4842 println!("IV = {}", iv);
4843 let mut cipher = Vec::<u8>::new();
4844 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4845 print!("C =\t");
4846 for c in cipher.clone()
4847 { print!("{:02X} ", c); }
4848 println!();
4849 let mut txt = String::new();
4850 for c in cipher.clone()
4851 { write!(txt, "{:02X} ", c); }
4852 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
4853
4854 let mut recovered = Vec::<u8>::new();
4855 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4856 print!("Ba =\t");
4857 for b in recovered.clone()
4858 { print!("{:02X} ", b); }
4859 println!();
4860 let mut txt = String::new();
4861 for c in recovered.clone()
4862 { write!(txt, "{:02X} ", c); }
4863 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4864
4865 let mut converted = String::new();
4866 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4867
4868 println!("Bb =\t{}", converted);
4869 assert_eq!(converted, "I am OK.");
4870 assert_eq!(converted, message);
4871 println!();
4872
4873 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4874 let key = 0x_1234567890ABCDEF_u64;
4875 println!("K =\t{:#016X}", key);
4876 let mut a_des = DES::new_with_key_u64(key);
4877
4878 let message = "PARK Youngho";
4879 println!("M =\t{}", message);
4880 let iv = 0x_FEDCBA0987654321_u64;
4881 println!("IV = {}", iv);
4882 let mut cipher = Vec::<u8>::new();
4883 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4884 print!("C =\t");
4885 for c in cipher.clone()
4886 { print!("{:02X} ", c); }
4887 println!();
4888 let mut txt = String::new();
4889 for c in cipher.clone()
4890 { write!(txt, "{:02X} ", c); }
4891 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
4892
4893 let mut recovered = Vec::<u8>::new();
4894 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4895 print!("Ba =\t");
4896 for b in recovered.clone()
4897 { print!("{:02X} ", b); }
4898 println!();
4899 let mut txt = String::new();
4900 for c in recovered.clone()
4901 { write!(txt, "{:02X} ", c); }
4902 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4903
4904 let mut converted = String::new();
4905 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4906
4907 println!("Bb =\t{}", converted);
4908 assert_eq!(converted, "PARK Youngho");
4909 assert_eq!(converted, message);
4910 println!();
4911
4912 // Normal case for the message of 16 bytes
4913 let key = 0x_1234567890ABCDEF_u64;
4914 println!("K =\t{:#016X}", key);
4915 let mut a_des = DES::new_with_key_u64(key);
4916
4917 let message = "고맙습니다.";
4918 println!("M =\t{}", message);
4919 let iv = 0x_FEDCBA0987654321_u64;
4920 println!("IV = {}", iv);
4921 let mut cipher = Vec::<u8>::new();
4922 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4923 print!("C =\t");
4924 for c in cipher.clone()
4925 { print!("{:02X} ", c); }
4926 println!();
4927 let mut txt = String::new();
4928 for c in cipher.clone()
4929 { write!(txt, "{:02X} ", c); }
4930 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
4931
4932 let mut recovered = Vec::<u8>::new();
4933 a_des.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
4934 print!("Ba =\t");
4935 for b in recovered.clone()
4936 { print!("{:02X} ", b); }
4937 println!();
4938 let mut txt = String::new();
4939 for c in recovered.clone()
4940 { write!(txt, "{:02X} ", c); }
4941 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4942
4943 let mut converted = String::new();
4944 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4945
4946 println!("Bb =\t{}", converted);
4947 assert_eq!(converted, "고맙습니다.");
4948 assert_eq!(converted, message);
4949 println!("-------------------------------");
4950}
4951
4952fn des_decrypt_vec_ofb_into_array()
4953{
4954 println!("des_decrypt_vec_ofb_into_array()");
4955 use std::io::Write;
4956 use std::fmt::Write as _;
4957 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
4958
4959 // Normal case
4960 let key = 0x_1234567890ABCDEF_u64;
4961 println!("K =\t{:#016X}", key);
4962 let mut a_des = DES::new_with_key_u64(key);
4963
4964 let message = "In the beginning God created the heavens and the earth.";
4965 println!("M =\t{}", message);
4966 let iv = 0x_FEDCBA0987654321_u64;
4967 println!("IV = {}", iv);
4968 let mut cipher = Vec::<u8>::new();
4969 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
4970 print!("C (16 rounds) =\t");
4971 for c in cipher.clone()
4972 { print!("{:02X} ", c); }
4973 println!();
4974 let mut txt = String::new();
4975 for c in cipher.clone()
4976 { write!(txt, "{:02X} ", c); }
4977 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
4978
4979 let mut recovered = [0u8; 56];
4980 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
4981 print!("Ba (16 rounds) =\t");
4982 for b in recovered.clone()
4983 { print!("{:02X} ", b); }
4984 println!();
4985 let mut txt = String::new();
4986 for c in recovered.clone()
4987 { write!(txt, "{:02X} ", c); }
4988 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4989
4990 let mut converted = String::new();
4991 unsafe { converted.as_mut_vec() }.write(&recovered);
4992 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4993 println!("Bb (16 rounds) =\t{}", converted);
4994 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4995 assert_eq!(converted, message);
4996 println!();
4997
4998 // Expanded case for 128 rounds
4999 let key = 0x_1234567890ABCDEF_u64;
5000 println!("K =\t{:#016X}", key);
5001 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5002
5003 let message = "In the beginning God created the heavens and the earth.";
5004 println!("M =\t{}", message);
5005 let iv = 0x_FEDCBA0987654321_u64;
5006 println!("IV = {}", iv);
5007 let mut cipher = Vec::<u8>::new();
5008 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5009 print!("C (128 rounds) =\t");
5010 for c in cipher.clone()
5011 { print!("{:02X} ", c); }
5012 println!();
5013 let mut txt = String::new();
5014 for c in cipher.clone()
5015 { write!(txt, "{:02X} ", c); }
5016 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
5017
5018 let mut recovered = [0u8; 56];
5019 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5020 print!("Ba (16 rounds) =\t");
5021 for b in recovered.clone()
5022 { print!("{:02X} ", b); }
5023 println!();
5024 let mut txt = String::new();
5025 for c in recovered.clone()
5026 { write!(txt, "{:02X} ", c); }
5027 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5028
5029 let mut converted = String::new();
5030 unsafe { converted.as_mut_vec() }.write(&recovered);
5031 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5032 println!("Bb (16 rounds) =\t{}", converted);
5033 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5034 assert_eq!(converted, message);
5035 println!();
5036
5037 // Expanded case for 0 rounds which means that key is meaningless
5038 let key1 = 0x_1234567890ABCDEF_u64;
5039 let key2 = 0_u64;
5040 println!("K =\t{:#016X}", key);
5041 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5042 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5043
5044 let message = "In the beginning God created the heavens and the earth.";
5045 println!("M =\t{}", message);
5046 let iv = 0x_FEDCBA0987654321_u64;
5047 println!("IV = {}", iv);
5048 let mut cipher1 = Vec::<u8>::new();
5049 let mut cipher2 = Vec::<u8>::new();
5050 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
5051 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
5052 print!("C (0 rounds) =\t");
5053 for c in cipher1.clone()
5054 { print!("{:02X} ", c); }
5055 println!();
5056 let mut txt = String::new();
5057 for c in cipher1.clone()
5058 { write!(txt, "{:02X} ", c); }
5059 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
5060 print!("D (0 rounds) =\t");
5061 for c in cipher2.clone()
5062 { print!("{:02X} ", c); }
5063 println!();
5064 let mut txt = String::new();
5065 for c in cipher2.clone()
5066 { write!(txt, "{:02X} ", c); }
5067 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
5068
5069 let mut recovered1 = [0u8; 56];
5070 let mut recovered2 = [0u8; 56];
5071 let len1 = c_des.decrypt_vec_into_array(iv, &cipher1, &mut recovered1);
5072 let len2 = d_des.decrypt_vec_into_array(iv, &cipher2, &mut recovered2);
5073 print!("B1a (0 rounds) =\t");
5074 for b in recovered1.clone()
5075 { print!("{:02X} ", b); }
5076 println!();
5077 let mut txt = String::new();
5078 for c in recovered1.clone()
5079 { write!(txt, "{:02X} ", c); }
5080 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5081 print!("B2a (0 rounds) =\t");
5082 for b in recovered2.clone()
5083 { print!("{:02X} ", b); }
5084 println!();
5085 let mut txt = String::new();
5086 for c in recovered.clone()
5087 { write!(txt, "{:02X} ", c); }
5088 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5089
5090 let mut converted1 = String::new();
5091 let mut converted2 = String::new();
5092 unsafe { converted1.as_mut_vec() }.write(&recovered1);
5093 unsafe { converted2.as_mut_vec() }.write(&recovered2);
5094 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
5095 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
5096 println!("B1b (0 rounds) =\t{}", converted1);
5097 println!("B2b (0 rounds) =\t{}", converted2);
5098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5099 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5100 assert_eq!(converted1, message);
5101 assert_eq!(converted2, message);
5102 assert_eq!(converted1, converted2);
5103 println!();
5104
5105 // Normal case for the message of 0 bytes
5106 let key = 0x_1234567890ABCDEF_u64;
5107 println!("K =\t{:#016X}", key);
5108 let mut a_des = DES::new_with_key_u64(key);
5109
5110 let message = "";
5111 println!("M =\t{}", message);
5112 let iv = 0x_FEDCBA0987654321_u64;
5113 println!("IV = {}", iv);
5114 let mut cipher = Vec::<u8>::new();
5115 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5116 print!("C =\t");
5117 for c in cipher.clone()
5118 { print!("{:02X} ", c); }
5119 println!();
5120 let mut txt = String::new();
5121 for c in cipher.clone()
5122 { write!(txt, "{:02X} ", c); }
5123 assert_eq!(txt, "");
5124
5125 let mut recovered = [0u8; 8];
5126 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5127
5128 print!("Ba =\t");
5129 for b in recovered.clone()
5130 { print!("{:02X} ", b); }
5131 println!();
5132 let mut txt = String::new();
5133 for c in recovered.clone()
5134 { write!(txt, "{:02X} ", c); }
5135 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
5136
5137 let mut converted = String::new();
5138 unsafe { converted.as_mut_vec() }.write(&recovered);
5139 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5140 println!("Bb =\t{}", converted);
5141 assert_eq!(converted, "");
5142 assert_eq!(converted, message);
5143 println!();
5144
5145 // Normal case for the message shorter than 8 bytes
5146 let key = 0x_1234567890ABCDEF_u64;
5147 println!("K =\t{:#016X}", key);
5148 let mut a_des = DES::new_with_key_u64(key);
5149
5150 let message = "7 bytes";
5151 println!("M =\t{}", message);
5152 let iv = 0x_FEDCBA0987654321_u64;
5153 println!("IV = {}", iv);
5154 let mut cipher = Vec::<u8>::new();
5155 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5156 print!("C =\t");
5157 for c in cipher.clone()
5158 { print!("{:02X} ", c); }
5159 println!();
5160 let mut txt = String::new();
5161 for c in cipher.clone()
5162 { write!(txt, "{:02X} ", c); }
5163 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
5164
5165 let mut recovered = [0u8; 8];
5166 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5167
5168 print!("Ba =\t");
5169 for b in recovered.clone()
5170 { print!("{:02X} ", b); }
5171 println!();
5172 let mut txt = String::new();
5173 for c in recovered.clone()
5174 { write!(txt, "{:02X} ", c); }
5175 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
5176
5177 let mut converted = String::new();
5178 unsafe { converted.as_mut_vec() }.write(&recovered);
5179 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5180 println!("Bb =\t{}", converted);
5181 assert_eq!(converted, "7 bytes");
5182 assert_eq!(converted, message);
5183 println!();
5184
5185 // Normal case for the message of 8 bytes
5186 let key = 0x_1234567890ABCDEF_u64;
5187 println!("K =\t{:#016X}", key);
5188 let mut a_des = DES::new_with_key_u64(key);
5189
5190 let message = "I am OK.";
5191 println!("M =\t{}", message);
5192 let iv = 0x_FEDCBA0987654321_u64;
5193 println!("IV = {}", iv);
5194 let mut cipher = Vec::<u8>::new();
5195 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5196 print!("C =\t");
5197 for c in cipher.clone()
5198 { print!("{:02X} ", c); }
5199 println!();
5200 let mut txt = String::new();
5201 for c in cipher.clone()
5202 { write!(txt, "{:02X} ", c); }
5203 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
5204
5205 let mut recovered = [0u8; 16];
5206 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5207
5208 print!("Ba =\t");
5209 for b in recovered.clone()
5210 { print!("{:02X} ", b); }
5211 println!();
5212 let mut txt = String::new();
5213 for c in recovered.clone()
5214 { write!(txt, "{:02X} ", c); }
5215 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
5216
5217 let mut converted = String::new();
5218 unsafe { converted.as_mut_vec() }.write(&recovered);
5219 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5220 println!("Bb =\t{}", converted);
5221 assert_eq!(converted, "I am OK.");
5222 assert_eq!(converted, message);
5223 println!();
5224
5225 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5226 let key = 0x_1234567890ABCDEF_u64;
5227 println!("K =\t{:#016X}", key);
5228 let mut a_des = DES::new_with_key_u64(key);
5229
5230 let message = "PARK Youngho";
5231 println!("M =\t{}", message);
5232 let iv = 0x_FEDCBA0987654321_u64;
5233 println!("IV = {}", iv);
5234 let mut cipher = Vec::<u8>::new();
5235 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5236 print!("C =\t");
5237 for c in cipher.clone()
5238 { print!("{:02X} ", c); }
5239 println!();
5240 let mut txt = String::new();
5241 for c in cipher.clone()
5242 { write!(txt, "{:02X} ", c); }
5243 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
5244
5245 let mut recovered = [0u8; 16];
5246 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5247
5248 print!("Ba =\t");
5249 for b in recovered.clone()
5250 { print!("{:02X} ", b); }
5251 println!();
5252 let mut txt = String::new();
5253 for c in recovered.clone()
5254 { write!(txt, "{:02X} ", c); }
5255 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
5256
5257 let mut converted = String::new();
5258 unsafe { converted.as_mut_vec() }.write(&recovered);
5259 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5260 println!("Bb =\t{}", converted);
5261 assert_eq!(converted, "PARK Youngho");
5262 assert_eq!(converted, message);
5263 println!();
5264
5265 // Normal case for the message of 16 bytes
5266 let key = 0x_1234567890ABCDEF_u64;
5267 println!("K =\t{:#016X}", key);
5268 let mut a_des = DES::new_with_key_u64(key);
5269
5270 let message = "고맙습니다.";
5271 println!("M =\t{}", message);
5272 let iv = 0x_FEDCBA0987654321_u64;
5273 println!("IV = {}", iv);
5274 let mut cipher = Vec::<u8>::new();
5275 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5276 print!("C =\t");
5277 for c in cipher.clone()
5278 { print!("{:02X} ", c); }
5279 println!();
5280 let mut txt = String::new();
5281 for c in cipher.clone()
5282 { write!(txt, "{:02X} ", c); }
5283 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
5284
5285 let mut recovered = [0u8; 24];
5286 let len = a_des.decrypt_vec_into_array(iv, &cipher, &mut recovered);
5287
5288 print!("Ba =\t");
5289 for b in recovered.clone()
5290 { print!("{:02X} ", b); }
5291 println!();
5292 let mut txt = String::new();
5293 for c in recovered.clone()
5294 { write!(txt, "{:02X} ", c); }
5295 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
5296
5297 let mut converted = String::new();
5298 unsafe { converted.as_mut_vec() }.write(&recovered);
5299 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5300 println!("Bb =\t{}", converted);
5301 assert_eq!(converted, "고맙습니다.");
5302 assert_eq!(converted, message);
5303 println!("-------------------------------");
5304}
5305
5306fn des_decrypt_vec_ofb_into_string()
5307{
5308 println!("des_decrypt_vec_ofb_into_string()");
5309 use std::io::Write;
5310 use std::fmt::Write as _;
5311 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
5312
5313 // Normal case
5314 let key = 0x_1234567890ABCDEF_u64;
5315 println!("K =\t{:#016X}", key);
5316 let mut a_des = DES::new_with_key_u64(key);
5317
5318 let message = "In the beginning God created the heavens and the earth.";
5319 println!("M =\t{}", message);
5320 let iv = 0x_FEDCBA0987654321_u64;
5321 println!("IV = {}", iv);
5322 let mut cipher = Vec::<u8>::new();
5323 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5324 print!("C (16 rounds) =\t");
5325 for c in cipher.clone()
5326 { print!("{:02X} ", c); }
5327 println!();
5328 let mut txt = String::new();
5329 for c in cipher.clone()
5330 { write!(txt, "{:02X} ", c); }
5331 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
5332
5333 let mut recovered = String::new();
5334 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5335 println!("B (16 rounds) =\t{}", recovered);
5336 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5337 assert_eq!(recovered, message);
5338 println!();
5339
5340 // Expanded case for 128 rounds
5341 let key = 0x_1234567890ABCDEF_u64;
5342 println!("K =\t{:#016X}", key);
5343 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5344
5345 let message = "In the beginning God created the heavens and the earth.";
5346 println!("M =\t{}", message);
5347 let iv = 0x_FEDCBA0987654321_u64;
5348 println!("IV = {}", iv);
5349 let mut cipher = Vec::<u8>::new();
5350 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5351 print!("C (128 rounds) =\t");
5352 for c in cipher.clone()
5353 { print!("{:02X} ", c); }
5354 println!();
5355 let mut txt = String::new();
5356 for c in cipher.clone()
5357 { write!(txt, "{:02X} ", c); }
5358 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
5359
5360 let mut recovered = String::new();
5361 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5362 println!("B (128 rounds) =\t{}", recovered);
5363 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5364 assert_eq!(recovered, message);
5365 println!();
5366
5367 // Expanded case for 0 rounds which means that key is meaningless
5368 let key1 = 0x_1234567890ABCDEF_u64;
5369 let key2 = 0_u64;
5370 println!("K =\t{:#016X}", key);
5371 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5372 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5373
5374 let message = "In the beginning God created the heavens and the earth.";
5375 println!("M =\t{}", message);
5376 let iv = 0x_FEDCBA0987654321_u64;
5377 println!("IV = {}", iv);
5378 let mut cipher1 = Vec::<u8>::new();
5379 let mut cipher2 = Vec::<u8>::new();
5380 c_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
5381 d_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
5382 print!("C (0 rounds) =\t");
5383 for c in cipher1.clone()
5384 { print!("{:02X} ", c); }
5385 println!();
5386 let mut txt = String::new();
5387 for c in cipher1.clone()
5388 { write!(txt, "{:02X} ", c); }
5389 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
5390 print!("D (0 rounds) =\t");
5391 for c in cipher2.clone()
5392 { print!("{:02X} ", c); }
5393 println!();
5394 let mut txt = String::new();
5395 for c in cipher2.clone()
5396 { write!(txt, "{:02X} ", c); }
5397 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
5398
5399 let mut recovered1 = String::new();
5400 let mut recovered2 = String::new();
5401 c_des.decrypt_vec_into_string(iv, &cipher1, &mut recovered1);
5402 d_des.decrypt_vec_into_string(iv, &cipher2, &mut recovered2);
5403 println!("B1 (0 rounds) =\t{}", recovered1);
5404 println!("B2 (0 rounds) =\t{}", recovered2);
5405 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5406 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5407 assert_eq!(recovered1, message);
5408 assert_eq!(recovered2, message);
5409 assert_eq!(recovered1, recovered2);
5410 println!();
5411
5412 // Normal case for the message of 0 bytes
5413 let key = 0x_1234567890ABCDEF_u64;
5414 println!("K =\t{:#016X}", key);
5415 let mut a_des = DES::new_with_key_u64(key);
5416
5417 let message = "";
5418 println!("M =\t{}", message);
5419 let iv = 0x_FEDCBA0987654321_u64;
5420 println!("IV = {}", iv);
5421 let mut cipher = Vec::<u8>::new();
5422 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5423 print!("C =\t");
5424 for c in cipher.clone()
5425 { print!("{:02X} ", c); }
5426 println!();
5427 let mut txt = String::new();
5428 for c in cipher.clone()
5429 { write!(txt, "{:02X} ", c); }
5430 assert_eq!(txt, "");
5431
5432 let mut recovered = String::new();
5433 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5434 println!("B =\t{}", recovered);
5435 assert_eq!(recovered, "");
5436 assert_eq!(recovered, message);
5437 println!();
5438
5439 // Normal case for the message shorter than 8 bytes
5440 let key = 0x_1234567890ABCDEF_u64;
5441 println!("K =\t{:#016X}", key);
5442 let mut a_des = DES::new_with_key_u64(key);
5443
5444 let message = "7 bytes";
5445 println!("M =\t{}", message);
5446 let iv = 0x_FEDCBA0987654321_u64;
5447 println!("IV = {}", iv);
5448 let mut cipher = Vec::<u8>::new();
5449 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5450 print!("C =\t");
5451 for c in cipher.clone()
5452 { print!("{:02X} ", c); }
5453 println!();
5454 let mut txt = String::new();
5455 for c in cipher.clone()
5456 { write!(txt, "{:02X} ", c); }
5457 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
5458
5459 let mut recovered = String::new();
5460 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5461 println!("B =\t{}", recovered);
5462 assert_eq!(recovered, "7 bytes");
5463 assert_eq!(recovered, message);
5464 println!();
5465
5466 // Normal case for the message of 8 bytes
5467 let key = 0x_1234567890ABCDEF_u64;
5468 println!("K =\t{:#016X}", key);
5469 let mut a_des = DES::new_with_key_u64(key);
5470
5471 let message = "I am OK.";
5472 println!("M =\t{}", message);
5473 let iv = 0x_FEDCBA0987654321_u64;
5474 println!("IV = {}", iv);
5475 let mut cipher = Vec::<u8>::new();
5476 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5477 print!("C =\t");
5478 for c in cipher.clone()
5479 { print!("{:02X} ", c); }
5480 println!();
5481 let mut txt = String::new();
5482 for c in cipher.clone()
5483 { write!(txt, "{:02X} ", c); }
5484 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
5485
5486 let mut recovered = String::new();
5487 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5488 println!("B =\t{}", recovered);
5489 assert_eq!(recovered, "I am OK.");
5490 assert_eq!(recovered, message);
5491 println!();
5492
5493 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5494 let key = 0x_1234567890ABCDEF_u64;
5495 println!("K =\t{:#016X}", key);
5496 let mut a_des = DES::new_with_key_u64(key);
5497
5498 let message = "PARK Youngho";
5499 println!("M =\t{}", message);
5500 let iv = 0x_FEDCBA0987654321_u64;
5501 println!("IV = {}", iv);
5502 let mut cipher = Vec::<u8>::new();
5503 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5504 print!("C =\t");
5505 for c in cipher.clone()
5506 { print!("{:02X} ", c); }
5507 println!();
5508 let mut txt = String::new();
5509 for c in cipher.clone()
5510 { write!(txt, "{:02X} ", c); }
5511 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
5512
5513 let mut recovered = String::new();
5514 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5515 println!("B =\t{}", recovered);
5516 assert_eq!(recovered, "PARK Youngho");
5517 assert_eq!(recovered, message);
5518 println!();
5519
5520 // Normal case for the message of 16 bytes
5521 let key = 0x_1234567890ABCDEF_u64;
5522 println!("K =\t{:#016X}", key);
5523 let mut a_des = DES::new_with_key_u64(key);
5524
5525 let message = "고맙습니다.";
5526 println!("M =\t{}", message);
5527 let iv = 0x_FEDCBA0987654321_u64;
5528 println!("IV = {}", iv);
5529 let mut cipher = Vec::<u8>::new();
5530 a_des.encrypt_str_into_vec(iv, &message, &mut cipher);
5531 print!("C =\t");
5532 for c in cipher.clone()
5533 { print!("{:02X} ", c); }
5534 println!();
5535 let mut txt = String::new();
5536 for c in cipher.clone()
5537 { write!(txt, "{:02X} ", c); }
5538 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
5539
5540 let mut recovered = String::new();
5541 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
5542 println!("B =\t{}", recovered);
5543 assert_eq!(recovered, "고맙습니다.");
5544 assert_eq!(recovered, message);
5545 println!("-------------------------------");
5546}
5547
5548fn des_decrypt_array_ofb()
5549{
5550 println!("des_decrypt_array_ofb()");
5551 use std::io::Write;
5552 use std::fmt::Write as _;
5553 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
5554
5555 // Normal case
5556 let key = 0x_1234567890ABCDEF_u64;
5557 println!("K =\t{:#016X}", key);
5558 let mut a_des = DES::new_with_key_u64(key);
5559
5560 let message = "In the beginning God created the heavens and the earth.";
5561 println!("M =\t{}", message);
5562 let iv = 0x_FEDCBA0987654321_u64;
5563 println!("IV = {}", iv);
5564 let mut cipher = [0_u8; 55];
5565 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5566 print!("C (16 rounds) =\t");
5567 for c in cipher.clone()
5568 { print!("{:02X} ", c); }
5569 println!();
5570 let mut txt = String::new();
5571 for c in cipher.clone()
5572 { write!(txt, "{:02X} ", c); }
5573 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
5574
5575 let mut recovered = vec![0; 55];
5576 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5577 recovered.truncate(len as usize);
5578 print!("Ba (16 rounds) =\t");
5579 for b in recovered.clone()
5580 { print!("{:02X} ", b); }
5581 println!();
5582 let mut txt = String::new();
5583 for c in recovered.clone()
5584 { write!(txt, "{:02X} ", c); }
5585 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5586
5587 let mut converted = String::new();
5588 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5589
5590 println!("Bb (16 rounds) =\t{}", converted);
5591 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5592 assert_eq!(converted, message);
5593 println!();
5594
5595 // Expanded case for 128 rounds
5596 let key = 0x_1234567890ABCDEF_u64;
5597 println!("K =\t{:#016X}", key);
5598 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5599
5600 let message = "In the beginning God created the heavens and the earth.";
5601 println!("M =\t{}", message);
5602 let iv = 0x_FEDCBA0987654321_u64;
5603 println!("IV = {}", iv);
5604 let mut cipher = [0_u8; 55];
5605 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5606 print!("C (128 rounds) =\t");
5607 for c in cipher.clone()
5608 { print!("{:02X} ", c); }
5609 println!();
5610 let mut txt = String::new();
5611 for c in cipher.clone()
5612 { write!(txt, "{:02X} ", c); }
5613 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
5614
5615 let mut recovered = vec![0; 55];
5616 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5617 recovered.truncate(len as usize);
5618 print!("Ba (128 rounds) =\t");
5619 for b in recovered.clone()
5620 { print!("{:02X} ", b); }
5621 println!();
5622 let mut txt = String::new();
5623 for c in recovered.clone()
5624 { write!(txt, "{:02X} ", c); }
5625 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5626
5627 let mut converted = String::new();
5628 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5629
5630 println!("Bb (128 rounds) =\t{}", converted);
5631 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5632 assert_eq!(converted, message);
5633 println!();
5634
5635 // Expanded case for 0 rounds which means that key is meaningless
5636 let key1 = 0x_1234567890ABCDEF_u64;
5637 let key2 = 0_u64;
5638 println!("K =\t{:#016X}", key);
5639 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5640 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5641
5642 let message = "In the beginning God created the heavens and the earth.";
5643 println!("M =\t{}", message);
5644 let iv = 0x_FEDCBA0987654321_u64;
5645 println!("IV = {}", iv);
5646 let mut cipher1 = [0_u8; 55];
5647 let mut cipher2 = [0_u8; 55];
5648 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
5649 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
5650 print!("C (0 rounds) =\t");
5651 for c in cipher1.clone()
5652 { print!("{:02X} ", c); }
5653 println!();
5654 let mut txt = String::new();
5655 for c in cipher1.clone()
5656 { write!(txt, "{:02X} ", c); }
5657 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
5658 print!("D (0 rounds) =\t");
5659 for c in cipher2.clone()
5660 { print!("{:02X} ", c); }
5661 println!();
5662 let mut txt = String::new();
5663 for c in cipher2.clone()
5664 { write!(txt, "{:02X} ", c); }
5665 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
5666
5667 let mut recovered1 = vec![0; 55];
5668 let mut recovered2 = vec![0; 55];
5669 let len1 = c_des.decrypt_array(iv, &cipher1, recovered1.as_mut_ptr());
5670 let len2 = d_des.decrypt_array(iv, &cipher2, recovered2.as_mut_ptr());
5671 recovered1.truncate(len1 as usize);
5672 recovered2.truncate(len2 as usize);
5673
5674 print!("B1a (0 rounds) =\t");
5675 for b in recovered1.clone()
5676 { print!("{:02X} ", b); }
5677 println!();
5678 let mut txt = String::new();
5679 for c in recovered1.clone()
5680 { write!(txt, "{:02X} ", c); }
5681 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5682 print!("B2a (0 rounds) =\t");
5683 for b in recovered2.clone()
5684 { print!("{:02X} ", b); }
5685 println!();
5686 let mut txt = String::new();
5687 for c in recovered2.clone()
5688 { write!(txt, "{:02X} ", c); }
5689 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5690
5691 let mut converted1 = String::new();
5692 let mut converted2 = String::new();
5693 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5694 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5695
5696 println!("B1b (0 rounds) =\t{}", converted1);
5697 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5698 assert_eq!(converted1, message);
5699 println!("B2b (0 rounds) =\t{}", converted2);
5700 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5701 assert_eq!(converted2, message);
5702 assert_eq!(converted1, converted1);
5703 println!();
5704
5705 // Normal case for the message of 0 bytes
5706 let key = 0x_1234567890ABCDEF_u64;
5707 println!("K =\t{:#016X}", key);
5708 let mut a_des = DES::new_with_key_u64(key);
5709
5710 let message = "";
5711 println!("M =\t{}", message);
5712 let iv = 0x_FEDCBA0987654321_u64;
5713 println!("IV = {}", iv);
5714 let mut cipher = [0_u8; 0];
5715 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5716 print!("C =\t");
5717 for c in cipher.clone()
5718 { print!("{:02X} ", c); }
5719 println!();
5720 let mut txt = String::new();
5721 for c in cipher.clone()
5722 { write!(txt, "{:02X} ", c); }
5723 assert_eq!(txt, "");
5724
5725 let mut recovered = vec![0; 8];
5726 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5727 recovered.truncate(len as usize);
5728
5729 print!("Ba =\t");
5730 for b in recovered.clone()
5731 { print!("{:02X} ", b); }
5732 println!();
5733 let mut txt = String::new();
5734 for c in recovered.clone()
5735 { write!(txt, "{:02X} ", c); }
5736 assert_eq!(txt, "");
5737
5738 let mut converted = String::new();
5739 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5740
5741 println!("Bb =\t{}", converted);
5742 assert_eq!(converted, "");
5743 assert_eq!(converted, message);
5744 println!();
5745
5746 // Normal case for the message shorter than 8 bytes
5747 let key = 0x_1234567890ABCDEF_u64;
5748 println!("K =\t{:#016X}", key);
5749 let mut a_des = DES::new_with_key_u64(key);
5750
5751 let message = "7 bytes";
5752 println!("M =\t{}", message);
5753 let iv = 0x_FEDCBA0987654321_u64;
5754 println!("IV = {}", iv);
5755 let mut cipher = [0_u8; 7];
5756 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5757 print!("C =\t");
5758 for c in cipher.clone()
5759 { print!("{:02X} ", c); }
5760 println!();
5761 let mut txt = String::new();
5762 for c in cipher.clone()
5763 { write!(txt, "{:02X} ", c); }
5764 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
5765
5766 let mut recovered = vec![0; 8];
5767 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5768 recovered.truncate(len as usize);
5769
5770 print!("Ba =\t");
5771 for b in recovered.clone()
5772 { print!("{:02X} ", b); }
5773 println!();
5774 let mut txt = String::new();
5775 for c in recovered.clone()
5776 { write!(txt, "{:02X} ", c); }
5777 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5778
5779 let mut converted = String::new();
5780 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5781
5782 println!("Bb =\t{}", converted);
5783 assert_eq!(converted, "7 bytes");
5784 assert_eq!(converted, message);
5785 println!();
5786
5787 // Normal case for the message of 8 bytes
5788 let key = 0x_1234567890ABCDEF_u64;
5789 println!("K =\t{:#016X}", key);
5790 let mut a_des = DES::new_with_key_u64(key);
5791
5792 let message = "I am OK.";
5793 println!("M =\t{}", message);
5794 let iv = 0x_FEDCBA0987654321_u64;
5795 println!("IV = {}", iv);
5796 let mut cipher = [0_u8; 8];
5797 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5798 print!("C =\t");
5799 for c in cipher.clone()
5800 { print!("{:02X} ", c); }
5801 println!();
5802 let mut txt = String::new();
5803 for c in cipher.clone()
5804 { write!(txt, "{:02X} ", c); }
5805 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
5806
5807 let mut recovered = vec![0; 16];
5808 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5809 recovered.truncate(len as usize);
5810
5811 print!("Ba =\t");
5812 for b in recovered.clone()
5813 { print!("{:02X} ", b); }
5814 println!();
5815 let mut txt = String::new();
5816 for c in recovered.clone()
5817 { write!(txt, "{:02X} ", c); }
5818 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5819
5820 let mut converted = String::new();
5821 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5822
5823 println!("Bb =\t{}", converted);
5824 assert_eq!(converted, "I am OK.");
5825 assert_eq!(converted, message);
5826 println!();
5827
5828 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5829 let key = 0x_1234567890ABCDEF_u64;
5830 println!("K =\t{:#016X}", key);
5831 let mut a_des = DES::new_with_key_u64(key);
5832
5833 let message = "PARK Youngho";
5834 println!("M =\t{}", message);
5835 let iv = 0x_FEDCBA0987654321_u64;
5836 println!("IV = {}", iv);
5837 let mut cipher = [0_u8; 12];
5838 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5839 print!("C =\t");
5840 for c in cipher.clone()
5841 { print!("{:02X} ", c); }
5842 println!();
5843 let mut txt = String::new();
5844 for c in cipher.clone()
5845 { write!(txt, "{:02X} ", c); }
5846 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
5847
5848 let mut recovered = vec![0; 16];
5849 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5850 recovered.truncate(len as usize);
5851 print!("Ba =\t");
5852 for b in recovered.clone()
5853 { print!("{:02X} ", b); }
5854 println!();
5855 let mut txt = String::new();
5856 for c in recovered.clone()
5857 { write!(txt, "{:02X} ", c); }
5858 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5859
5860 let mut converted = String::new();
5861 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5862
5863 println!("Bb =\t{}", converted);
5864 assert_eq!(converted, "PARK Youngho");
5865 assert_eq!(converted, message);
5866 println!();
5867
5868 // Normal case for the message of 16 bytes
5869 let key = 0x_1234567890ABCDEF_u64;
5870 println!("K =\t{:#016X}", key);
5871 let mut a_des = DES::new_with_key_u64(key);
5872
5873 let message = "고맙습니다.";
5874 println!("M =\t{}", message);
5875 let iv = 0x_FEDCBA0987654321_u64;
5876 println!("IV = {}", iv);
5877 let mut cipher = [0_u8; 16];
5878 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5879 print!("C =\t");
5880 for c in cipher.clone()
5881 { print!("{:02X} ", c); }
5882 println!();
5883 let mut txt = String::new();
5884 for c in cipher.clone()
5885 { write!(txt, "{:02X} ", c); }
5886 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
5887
5888 let mut recovered = vec![0; 24];
5889 let len = a_des.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
5890 recovered.truncate(len as usize);
5891
5892 print!("Ba =\t");
5893 for b in recovered.clone()
5894 { print!("{:02X} ", b); }
5895 println!();
5896 let mut txt = String::new();
5897 for c in recovered.clone()
5898 { write!(txt, "{:02X} ", c); }
5899 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5900
5901 let mut converted = String::new();
5902 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5903
5904 println!("Bb =\t{}", converted);
5905 assert_eq!(converted, "고맙습니다.");
5906 assert_eq!(converted, message);
5907 println!("-------------------------------");
5908}
5909
5910fn des_decrypt_array_ofb_into_vec()
5911{
5912 println!("des_decrypt_array_ofb_into_vec()");
5913 use std::io::Write;
5914 use std::fmt::Write as _;
5915 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
5916
5917 // Normal case
5918 let key = 0x_1234567890ABCDEF_u64;
5919 println!("K =\t{:#016X}", key);
5920 let mut a_des = DES::new_with_key_u64(key);
5921
5922 let message = "In the beginning God created the heavens and the earth.";
5923 println!("M =\t{}", message);
5924 let iv = 0x_FEDCBA0987654321_u64;
5925 println!("IV = {}", iv);
5926 let mut cipher = [0_u8; 55];
5927 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5928 print!("C (16 rounds) =\t");
5929 for c in cipher.clone()
5930 { print!("{:02X} ", c); }
5931 println!();
5932 let mut txt = String::new();
5933 for c in cipher.clone()
5934 { write!(txt, "{:02X} ", c); }
5935 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
5936
5937 let mut recovered = Vec::<u8>::new();
5938 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
5939 print!("Ba (16 rounds) =\t");
5940 for b in recovered.clone()
5941 { print!("{:02X} ", b); }
5942 println!();
5943 let mut txt = String::new();
5944 for c in recovered.clone()
5945 { write!(txt, "{:02X} ", c); }
5946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5947
5948 let mut converted = String::new();
5949 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5950
5951 println!("Bb (16 rounds) =\t{}", converted);
5952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5953 assert_eq!(converted, message);
5954 println!();
5955
5956 // Expanded case for 128 rounds
5957 let key = 0x_1234567890ABCDEF_u64;
5958 println!("K =\t{:#016X}", key);
5959 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5960
5961 let message = "In the beginning God created the heavens and the earth.";
5962 println!("M =\t{}", message);
5963 let iv = 0x_FEDCBA0987654321_u64;
5964 println!("IV = {}", iv);
5965 let mut cipher = [0_u8; 55];
5966 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
5967 print!("C (128 rounds) =\t");
5968 for c in cipher.clone()
5969 { print!("{:02X} ", c); }
5970 println!();
5971 let mut txt = String::new();
5972 for c in cipher.clone()
5973 { write!(txt, "{:02X} ", c); }
5974 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
5975
5976 let mut recovered = Vec::<u8>::new();
5977 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
5978 print!("Ba (128 rounds) =\t");
5979 for b in recovered.clone()
5980 { print!("{:02X} ", b); }
5981 println!();
5982 let mut txt = String::new();
5983 for c in recovered.clone()
5984 { write!(txt, "{:02X} ", c); }
5985 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5986
5987 let mut converted = String::new();
5988 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5989
5990 println!("Bb (128 rounds) =\t{}", converted);
5991 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5992 assert_eq!(converted, message);
5993 println!();
5994
5995 // Expanded case for 0 rounds which means that key is meaningless
5996 let key1 = 0x_1234567890ABCDEF_u64;
5997 let key2 = 0_u64;
5998 println!("K =\t{:#016X}", key);
5999 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6000 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6001
6002 let message = "In the beginning God created the heavens and the earth.";
6003 println!("M =\t{}", message);
6004 let iv = 0x_FEDCBA0987654321_u64;
6005 println!("IV = {}", iv);
6006 let mut cipher1 = [0_u8; 55];
6007 let mut cipher2 = [0_u8; 55];
6008 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
6009 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
6010 print!("C (0 rounds) =\t");
6011 for c in cipher1.clone()
6012 { print!("{:02X} ", c); }
6013 println!();
6014 let mut txt = String::new();
6015 for c in cipher1.clone()
6016 { write!(txt, "{:02X} ", c); }
6017 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
6018 print!("D (0 rounds) =\t");
6019 for c in cipher2.clone()
6020 { print!("{:02X} ", c); }
6021 println!();
6022 let mut txt = String::new();
6023 for c in cipher2.clone()
6024 { write!(txt, "{:02X} ", c); }
6025 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
6026
6027 let mut recovered1 = Vec::<u8>::new();
6028 let mut recovered2 = Vec::<u8>::new();
6029 c_des.decrypt_array_into_vec(iv, &cipher1, &mut recovered1);
6030 d_des.decrypt_array_into_vec(iv, &cipher2, &mut recovered2);
6031 print!("B1a (0 rounds) =\t");
6032 for b in recovered1.clone()
6033 { print!("{:02X} ", b); }
6034 println!();
6035 let mut txt = String::new();
6036 for c in recovered1.clone()
6037 { write!(txt, "{:02X} ", c); }
6038 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
6039 print!("B2a (0 rounds) =\t");
6040 for b in recovered2.clone()
6041 { print!("{:02X} ", b); }
6042 println!();
6043 let mut txt = String::new();
6044 for c in recovered2.clone()
6045 { write!(txt, "{:02X} ", c); }
6046 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
6047
6048 let mut converted1 = String::new();
6049 let mut converted2 = String::new();
6050 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
6051 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
6052
6053 println!("B1b (0 rounds) =\t{}", converted1);
6054 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6055 assert_eq!(converted1, message);
6056 println!("B2b (0 rounds) =\t{}", converted2);
6057 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6058 assert_eq!(converted2, message);
6059 assert_eq!(converted1, converted1);
6060 println!();
6061
6062 // Normal case for the message of 0 bytes
6063 let key = 0x_1234567890ABCDEF_u64;
6064 println!("K =\t{:#016X}", key);
6065 let mut a_des = DES::new_with_key_u64(key);
6066
6067 let message = "";
6068 println!("M =\t{}", message);
6069 let iv = 0x_FEDCBA0987654321_u64;
6070 println!("IV = {}", iv);
6071 let mut cipher = [0_u8; 0];
6072 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6073 print!("C =\t");
6074 for c in cipher.clone()
6075 { print!("{:02X} ", c); }
6076 println!();
6077 let mut txt = String::new();
6078 for c in cipher.clone()
6079 { write!(txt, "{:02X} ", c); }
6080 assert_eq!(txt, "");
6081
6082 let mut recovered = Vec::<u8>::new();
6083 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6084 print!("Ba =\t");
6085 for b in recovered.clone()
6086 { print!("{:02X} ", b); }
6087 println!();
6088 let mut txt = String::new();
6089 for c in recovered.clone()
6090 { write!(txt, "{:02X} ", c); }
6091 assert_eq!(txt, "");
6092
6093 let mut converted = String::new();
6094 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6095
6096 println!("Bb =\t{}", converted);
6097 assert_eq!(converted, "");
6098 assert_eq!(converted, message);
6099 println!();
6100
6101 // Normal case for the message shorter than 8 bytes
6102 let key = 0x_1234567890ABCDEF_u64;
6103 println!("K =\t{:#016X}", key);
6104 let mut a_des = DES::new_with_key_u64(key);
6105
6106 let message = "7 bytes";
6107 println!("M =\t{}", message);
6108 let iv = 0x_FEDCBA0987654321_u64;
6109 println!("IV = {}", iv);
6110 let mut cipher = [0_u8; 7];
6111 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6112 print!("C =\t");
6113 for c in cipher.clone()
6114 { print!("{:02X} ", c); }
6115 println!();
6116 let mut txt = String::new();
6117 for c in cipher.clone()
6118 { write!(txt, "{:02X} ", c); }
6119 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
6120
6121 let mut recovered = Vec::<u8>::new();
6122 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6123 print!("Ba =\t");
6124 for b in recovered.clone()
6125 { print!("{:02X} ", b); }
6126 println!();
6127 let mut txt = String::new();
6128 for c in recovered.clone()
6129 { write!(txt, "{:02X} ", c); }
6130 assert_eq!(txt, "37 20 62 79 74 65 73 ");
6131
6132 let mut converted = String::new();
6133 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6134
6135 println!("Bb =\t{}", converted);
6136 assert_eq!(converted, "7 bytes");
6137 assert_eq!(converted, message);
6138 println!();
6139
6140 // Normal case for the message of 8 bytes
6141 let key = 0x_1234567890ABCDEF_u64;
6142 println!("K =\t{:#016X}", key);
6143 let mut a_des = DES::new_with_key_u64(key);
6144
6145 let message = "I am OK.";
6146 println!("M =\t{}", message);
6147 let iv = 0x_FEDCBA0987654321_u64;
6148 println!("IV = {}", iv);
6149 let mut cipher = [0_u8; 8];
6150 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6151 print!("C =\t");
6152 for c in cipher.clone()
6153 { print!("{:02X} ", c); }
6154 println!();
6155 let mut txt = String::new();
6156 for c in cipher.clone()
6157 { write!(txt, "{:02X} ", c); }
6158 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
6159
6160 let mut recovered = Vec::<u8>::new();
6161 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6162 print!("Ba =\t");
6163 for b in recovered.clone()
6164 { print!("{:02X} ", b); }
6165 println!();
6166 let mut txt = String::new();
6167 for c in recovered.clone()
6168 { write!(txt, "{:02X} ", c); }
6169 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
6170
6171 let mut converted = String::new();
6172 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6173
6174 println!("Bb =\t{}", converted);
6175 assert_eq!(converted, "I am OK.");
6176 assert_eq!(converted, message);
6177 println!();
6178
6179 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6180 let key = 0x_1234567890ABCDEF_u64;
6181 println!("K =\t{:#016X}", key);
6182 let mut a_des = DES::new_with_key_u64(key);
6183
6184 let message = "PARK Youngho";
6185 println!("M =\t{}", message);
6186 let iv = 0x_FEDCBA0987654321_u64;
6187 println!("IV = {}", iv);
6188 let mut cipher = [0_u8; 12];
6189 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6190 print!("C =\t");
6191 for c in cipher.clone()
6192 { print!("{:02X} ", c); }
6193 println!();
6194 let mut txt = String::new();
6195 for c in cipher.clone()
6196 { write!(txt, "{:02X} ", c); }
6197 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
6198
6199 let mut recovered = Vec::<u8>::new();
6200 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6201 print!("Ba =\t");
6202 for b in recovered.clone()
6203 { print!("{:02X} ", b); }
6204 println!();
6205 let mut txt = String::new();
6206 for c in recovered.clone()
6207 { write!(txt, "{:02X} ", c); }
6208 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
6209
6210 let mut converted = String::new();
6211 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6212
6213 println!("Bb =\t{}", converted);
6214 assert_eq!(converted, "PARK Youngho");
6215 assert_eq!(converted, message);
6216 println!();
6217
6218 // Normal case for the message of 16 bytes
6219 let key = 0x_1234567890ABCDEF_u64;
6220 println!("K =\t{:#016X}", key);
6221 let mut a_des = DES::new_with_key_u64(key);
6222
6223 let message = "고맙습니다.";
6224 println!("M =\t{}", message);
6225 let iv = 0x_FEDCBA0987654321_u64;
6226 println!("IV = {}", iv);
6227 let mut cipher = [0_u8; 16];
6228 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6229 print!("C =\t");
6230 for c in cipher.clone()
6231 { print!("{:02X} ", c); }
6232 println!();
6233 let mut txt = String::new();
6234 for c in cipher.clone()
6235 { write!(txt, "{:02X} ", c); }
6236 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
6237
6238 let mut recovered = Vec::<u8>::new();
6239 a_des.decrypt_array_into_vec(iv, &cipher, &mut recovered);
6240 print!("Ba =\t");
6241 for b in recovered.clone()
6242 { print!("{:02X} ", b); }
6243 println!();
6244 let mut txt = String::new();
6245 for c in recovered.clone()
6246 { write!(txt, "{:02X} ", c); }
6247 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
6248
6249 let mut converted = String::new();
6250 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6251
6252 println!("Bb =\t{}", converted);
6253 assert_eq!(converted, "고맙습니다.");
6254 assert_eq!(converted, message);
6255 println!("-------------------------------");
6256}
6257
6258fn des_decrypt_array_ofb_into_array()
6259{
6260 println!("des_decrypt_array_ofb_into_array()");
6261 use std::io::Write;
6262 use std::fmt::Write as _;
6263 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
6264
6265 // Normal case
6266 let key = 0x_1234567890ABCDEF_u64;
6267 println!("K =\t{:#016X}", key);
6268 let mut a_des = DES::new_with_key_u64(key);
6269
6270 let message = "In the beginning God created the heavens and the earth.";
6271 println!("M =\t{}", message);
6272 let iv = 0x_FEDCBA0987654321_u64;
6273 println!("IV = {}", iv);
6274 let mut cipher = [0_u8; 55];
6275 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6276 print!("C (16 rounds) =\t");
6277 for c in cipher.clone()
6278 { print!("{:02X} ", c); }
6279 println!();
6280 let mut txt = String::new();
6281 for c in cipher.clone()
6282 { write!(txt, "{:02X} ", c); }
6283 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
6284
6285 let mut recovered = [0u8; 56];
6286 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6287 print!("Ba (16 rounds) =\t");
6288 for b in recovered.clone()
6289 { print!("{:02X} ", b); }
6290 println!();
6291 let mut txt = String::new();
6292 for c in recovered.clone()
6293 { write!(txt, "{:02X} ", c); }
6294 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6295
6296 let mut converted = String::new();
6297 unsafe { converted.as_mut_vec() }.write(&recovered);
6298 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6299 println!("Bb (16 rounds) =\t{}", converted);
6300 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
6301 assert_eq!(converted, message);
6302 println!();
6303
6304 // Expanded case for 128 rounds
6305 let key = 0x_1234567890ABCDEF_u64;
6306 println!("K =\t{:#016X}", key);
6307 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6308
6309 let message = "In the beginning God created the heavens and the earth.";
6310 println!("M =\t{}", message);
6311 let iv = 0x_FEDCBA0987654321_u64;
6312 println!("IV = {}", iv);
6313 let mut cipher = [0_u8; 55];
6314 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6315 print!("C (128 rounds) =\t");
6316 for c in cipher.clone()
6317 { print!("{:02X} ", c); }
6318 println!();
6319 let mut txt = String::new();
6320 for c in cipher.clone()
6321 { write!(txt, "{:02X} ", c); }
6322 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
6323
6324 let mut recovered = [0u8; 56];
6325 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6326 print!("Ba (16 rounds) =\t");
6327 for b in recovered.clone()
6328 { print!("{:02X} ", b); }
6329 println!();
6330 let mut txt = String::new();
6331 for c in recovered.clone()
6332 { write!(txt, "{:02X} ", c); }
6333 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6334
6335 let mut converted = String::new();
6336 unsafe { converted.as_mut_vec() }.write(&recovered);
6337 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6338 println!("Bb (16 rounds) =\t{}", converted);
6339 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
6340 assert_eq!(converted, message);
6341 println!();
6342
6343 // Expanded case for 0 rounds which means that key is meaningless
6344 let key1 = 0x_1234567890ABCDEF_u64;
6345 let key2 = 0_u64;
6346 println!("K =\t{:#016X}", key);
6347 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6348 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6349
6350 let message = "In the beginning God created the heavens and the earth.";
6351 println!("M =\t{}", message);
6352 let iv = 0x_FEDCBA0987654321_u64;
6353 println!("IV = {}", iv);
6354 let mut cipher1 = [0_u8; 55];
6355 let mut cipher2 = [0_u8; 55];
6356 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
6357 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
6358 print!("C (0 rounds) =\t");
6359 for c in cipher1.clone()
6360 { print!("{:02X} ", c); }
6361 println!();
6362 let mut txt = String::new();
6363 for c in cipher1.clone()
6364 { write!(txt, "{:02X} ", c); }
6365 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
6366 print!("D (0 rounds) =\t");
6367 for c in cipher2.clone()
6368 { print!("{:02X} ", c); }
6369 println!();
6370 let mut txt = String::new();
6371 for c in cipher2.clone()
6372 { write!(txt, "{:02X} ", c); }
6373 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
6374
6375 let mut recovered1 = [0u8; 56];
6376 let mut recovered2 = [0u8; 56];
6377 let len1 = c_des.decrypt_array_into_array(iv, &cipher1, &mut recovered1);
6378 let len2 = d_des.decrypt_array_into_array(iv, &cipher2, &mut recovered2);
6379 print!("B1a (0 rounds) =\t");
6380 for b in recovered1.clone()
6381 { print!("{:02X} ", b); }
6382 println!();
6383 let mut txt = String::new();
6384 for c in recovered1.clone()
6385 { write!(txt, "{:02X} ", c); }
6386 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6387 print!("B2a (0 rounds) =\t");
6388 for b in recovered2.clone()
6389 { print!("{:02X} ", b); }
6390 println!();
6391 let mut txt = String::new();
6392 for c in recovered.clone()
6393 { write!(txt, "{:02X} ", c); }
6394 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6395
6396 let mut converted1 = String::new();
6397 let mut converted2 = String::new();
6398 unsafe { converted1.as_mut_vec() }.write(&recovered1);
6399 unsafe { converted2.as_mut_vec() }.write(&recovered2);
6400 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6401 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6402 println!("B1b (0 rounds) =\t{}", converted1);
6403 println!("B2b (0 rounds) =\t{}", converted2);
6404 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6405 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6406 assert_eq!(converted1, message);
6407 assert_eq!(converted2, message);
6408 assert_eq!(converted1, converted2);
6409 println!();
6410
6411 // Normal case for the message of 0 bytes
6412 let key = 0x_1234567890ABCDEF_u64;
6413 println!("K =\t{:#016X}", key);
6414 let mut a_des = DES::new_with_key_u64(key);
6415
6416 let message = "";
6417 println!("M =\t{}", message);
6418 let iv = 0x_FEDCBA0987654321_u64;
6419 println!("IV = {}", iv);
6420 let mut cipher = [0_u8; 0];
6421 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6422 print!("C =\t");
6423 for c in cipher.clone()
6424 { print!("{:02X} ", c); }
6425 println!();
6426 let mut txt = String::new();
6427 for c in cipher.clone()
6428 { write!(txt, "{:02X} ", c); }
6429 assert_eq!(txt, "");
6430
6431 let mut recovered = [0u8; 8];
6432 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6433
6434 print!("Ba =\t");
6435 for b in recovered.clone()
6436 { print!("{:02X} ", b); }
6437 println!();
6438 let mut txt = String::new();
6439 for c in recovered.clone()
6440 { write!(txt, "{:02X} ", c); }
6441 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6442
6443 let mut converted = String::new();
6444 unsafe { converted.as_mut_vec() }.write(&recovered);
6445 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6446 println!("Bb =\t{}", converted);
6447 assert_eq!(converted, "");
6448 assert_eq!(converted, message);
6449 println!();
6450
6451 // Normal case for the message shorter than 8 bytes
6452 let key = 0x_1234567890ABCDEF_u64;
6453 println!("K =\t{:#016X}", key);
6454 let mut a_des = DES::new_with_key_u64(key);
6455
6456 let message = "7 bytes";
6457 println!("M =\t{}", message);
6458 let iv = 0x_FEDCBA0987654321_u64;
6459 println!("IV = {}", iv);
6460 let mut cipher = [0_u8; 7];
6461 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6462 print!("C =\t");
6463 for c in cipher.clone()
6464 { print!("{:02X} ", c); }
6465 println!();
6466 let mut txt = String::new();
6467 for c in cipher.clone()
6468 { write!(txt, "{:02X} ", c); }
6469 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
6470
6471 let mut recovered = [0u8; 8];
6472 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6473
6474 print!("Ba =\t");
6475 for b in recovered.clone()
6476 { print!("{:02X} ", b); }
6477 println!();
6478 let mut txt = String::new();
6479 for c in recovered.clone()
6480 { write!(txt, "{:02X} ", c); }
6481 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6482
6483 let mut converted = String::new();
6484 unsafe { converted.as_mut_vec() }.write(&recovered);
6485 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6486 println!("Bb =\t{}", converted);
6487 assert_eq!(converted, "7 bytes");
6488 assert_eq!(converted, message);
6489 println!();
6490
6491 // Normal case for the message of 8 bytes
6492 let key = 0x_1234567890ABCDEF_u64;
6493 println!("K =\t{:#016X}", key);
6494 let mut a_des = DES::new_with_key_u64(key);
6495
6496 let message = "I am OK.";
6497 println!("M =\t{}", message);
6498 let iv = 0x_FEDCBA0987654321_u64;
6499 println!("IV = {}", iv);
6500 let mut cipher = [0_u8; 8];
6501 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6502 print!("C =\t");
6503 for c in cipher.clone()
6504 { print!("{:02X} ", c); }
6505 println!();
6506 let mut txt = String::new();
6507 for c in cipher.clone()
6508 { write!(txt, "{:02X} ", c); }
6509 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
6510
6511 let mut recovered = [0u8; 16];
6512 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6513
6514 print!("Ba =\t");
6515 for b in recovered.clone()
6516 { print!("{:02X} ", b); }
6517 println!();
6518 let mut txt = String::new();
6519 for c in recovered.clone()
6520 { write!(txt, "{:02X} ", c); }
6521 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6522
6523 let mut converted = String::new();
6524 unsafe { converted.as_mut_vec() }.write(&recovered);
6525 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6526 println!("Bb =\t{}", converted);
6527 assert_eq!(converted, "I am OK.");
6528 assert_eq!(converted, message);
6529 println!();
6530
6531 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6532 let key = 0x_1234567890ABCDEF_u64;
6533 println!("K =\t{:#016X}", key);
6534 let mut a_des = DES::new_with_key_u64(key);
6535
6536 let message = "PARK Youngho";
6537 println!("M =\t{}", message);
6538 let iv = 0x_FEDCBA0987654321_u64;
6539 println!("IV = {}", iv);
6540 let mut cipher = [0_u8; 12];
6541 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6542 print!("C =\t");
6543 for c in cipher.clone()
6544 { print!("{:02X} ", c); }
6545 println!();
6546 let mut txt = String::new();
6547 for c in cipher.clone()
6548 { write!(txt, "{:02X} ", c); }
6549 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
6550
6551 let mut recovered = [0u8; 16];
6552 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6553
6554 print!("Ba =\t");
6555 for b in recovered.clone()
6556 { print!("{:02X} ", b); }
6557 println!();
6558 let mut txt = String::new();
6559 for c in recovered.clone()
6560 { write!(txt, "{:02X} ", c); }
6561 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6562
6563 let mut converted = String::new();
6564 unsafe { converted.as_mut_vec() }.write(&recovered);
6565 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6566 println!("Bb =\t{}", converted);
6567 assert_eq!(converted, "PARK Youngho");
6568 assert_eq!(converted, message);
6569 println!();
6570
6571 // Normal case for the message of 16 bytes
6572 let key = 0x_1234567890ABCDEF_u64;
6573 println!("K =\t{:#016X}", key);
6574 let mut a_des = DES::new_with_key_u64(key);
6575
6576 let message = "고맙습니다.";
6577 println!("M =\t{}", message);
6578 let iv = 0x_FEDCBA0987654321_u64;
6579 println!("IV = {}", iv);
6580 let mut cipher = [0_u8; 16];
6581 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6582 print!("C =\t");
6583 for c in cipher.clone()
6584 { print!("{:02X} ", c); }
6585 println!();
6586 let mut txt = String::new();
6587 for c in cipher.clone()
6588 { write!(txt, "{:02X} ", c); }
6589 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
6590
6591 let mut recovered = [0u8; 24];
6592 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
6593
6594 print!("Ba =\t");
6595 for b in recovered.clone()
6596 { print!("{:02X} ", b); }
6597 println!();
6598 let mut txt = String::new();
6599 for c in recovered.clone()
6600 { write!(txt, "{:02X} ", c); }
6601 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6602
6603 let mut converted = String::new();
6604 unsafe { converted.as_mut_vec() }.write(&recovered);
6605 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6606 println!("Bb =\t{}", converted);
6607 assert_eq!(converted, "고맙습니다.");
6608 assert_eq!(converted, message);
6609 println!("-------------------------------");
6610}
6611
6612fn des_decrypt_array_ofb_into_string()
6613{
6614 println!("des_decrypt_array_ofb_into_string()");
6615 use std::io::Write;
6616 use std::fmt::Write as _;
6617 use cryptocol::symmetric::{ DES, DES_Expanded, OFB };
6618
6619 // Normal case
6620 let key = 0x_1234567890ABCDEF_u64;
6621 println!("K =\t{:#016X}", key);
6622 let mut a_des = DES::new_with_key_u64(key);
6623
6624 let message = "In the beginning God created the heavens and the earth.";
6625 println!("M =\t{}", message);
6626 let iv = 0x_FEDCBA0987654321_u64;
6627 println!("IV = {}", iv);
6628 let mut cipher = [0_u8; 55];
6629 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6630 print!("C (16 rounds) =\t");
6631 for c in cipher.clone()
6632 { print!("{:02X} ", c); }
6633 println!();
6634 let mut txt = String::new();
6635 for c in cipher.clone()
6636 { write!(txt, "{:02X} ", c); }
6637 assert_eq!(txt, "2E 1E E1 51 FD B3 B0 4B 2A EF BC 49 21 FA C0 27 FB 9F DD BB 17 8D 21 3B 49 66 A2 94 AB 4D 08 8E B9 8D D6 7F 9F 8B 8D 0E E3 E7 5D F4 57 BB 96 2D 63 C3 2F 9E 71 8C 72 ");
6638
6639 let mut recovered = String::new();
6640 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6641 println!("B (16 rounds) =\t{}", recovered);
6642 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6643 assert_eq!(recovered, message);
6644 println!();
6645
6646 // Expanded case for 128 rounds
6647 let key = 0x_1234567890ABCDEF_u64;
6648 println!("K =\t{:#016X}", key);
6649 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6650
6651 let message = "In the beginning God created the heavens and the earth.";
6652 println!("M =\t{}", message);
6653 let iv = 0x_FEDCBA0987654321_u64;
6654 println!("IV = {}", iv);
6655 let mut cipher = [0_u8; 55];
6656 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6657 print!("C (128 rounds) =\t");
6658 for c in cipher.clone()
6659 { print!("{:02X} ", c); }
6660 println!();
6661 let mut txt = String::new();
6662 for c in cipher.clone()
6663 { write!(txt, "{:02X} ", c); }
6664 assert_eq!(txt, "19 B0 8F 23 01 31 B3 95 5F 0F 7C D5 96 55 DB 98 76 6C C7 23 49 6D 35 9B FD DE B7 1A 6B B2 8A EF B6 63 DB A5 50 F6 07 30 8C 75 28 32 25 32 33 77 B0 46 FE 96 1C F7 6B ");
6665
6666 let mut recovered = String::new();
6667 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6668 println!("B (128 rounds) =\t{}", recovered);
6669 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6670 assert_eq!(recovered, message);
6671 println!();
6672
6673 // Expanded case for 0 rounds which means that key is meaningless
6674 let key1 = 0x_1234567890ABCDEF_u64;
6675 let key2 = 0_u64;
6676 println!("K =\t{:#016X}", key);
6677 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6678 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6679
6680 let message = "In the beginning God created the heavens and the earth.";
6681 println!("M =\t{}", message);
6682 let iv = 0x_FEDCBA0987654321_u64;
6683 println!("IV = {}", iv);
6684 let mut cipher1 = [0_u8; 55];
6685 let mut cipher2 = [0_u8; 55];
6686 c_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher1);
6687 d_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher2);
6688 print!("C (0 rounds) =\t");
6689 for c in cipher1.clone()
6690 { print!("{:02X} ", c); }
6691 println!();
6692 let mut txt = String::new();
6693 for c in cipher1.clone()
6694 { write!(txt, "{:02X} ", c); }
6695 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
6696 print!("D (0 rounds) =\t");
6697 for c in cipher2.clone()
6698 { print!("{:02X} ", c); }
6699 println!();
6700 let mut txt = String::new();
6701 for c in cipher2.clone()
6702 { write!(txt, "{:02X} ", c); }
6703 assert_eq!(txt, "5B ED BA 3F 6E 10 CC 9F 44 24 0C E9 67 D3 B2 99 32 C4 F5 2F 26 16 9E 98 40 37 00 E3 29 CE B4 9B 32 EB FF 2A 70 10 82 8E 01 22 0B E3 29 CE B4 9B 32 E6 FB 39 72 1D C2 ");
6704
6705 let mut recovered1 = String::new();
6706 let mut recovered2 = String::new();
6707 c_des.decrypt_array_into_string(iv, &cipher1, &mut recovered1);
6708 d_des.decrypt_array_into_string(iv, &cipher2, &mut recovered2);
6709 println!("B1 (0 rounds) =\t{}", recovered1);
6710 println!("B2 (0 rounds) =\t{}", recovered2);
6711 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6712 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6713 assert_eq!(recovered1, message);
6714 assert_eq!(recovered2, message);
6715 assert_eq!(recovered1, recovered2);
6716 println!();
6717
6718 // Normal case for the message of 0 bytes
6719 let key = 0x_1234567890ABCDEF_u64;
6720 println!("K =\t{:#016X}", key);
6721 let mut a_des = DES::new_with_key_u64(key);
6722
6723 let message = "";
6724 println!("M =\t{}", message);
6725 let iv = 0x_FEDCBA0987654321_u64;
6726 println!("IV = {}", iv);
6727 let mut cipher = [0_u8; 0];
6728 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6729 print!("C =\t");
6730 for c in cipher.clone()
6731 { print!("{:02X} ", c); }
6732 println!();
6733 let mut txt = String::new();
6734 for c in cipher.clone()
6735 { write!(txt, "{:02X} ", c); }
6736 assert_eq!(txt, "");
6737
6738 let mut recovered = String::new();
6739 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6740 println!("B =\t{}", recovered);
6741 assert_eq!(recovered, "");
6742 assert_eq!(recovered, message);
6743 println!();
6744
6745 // Normal case for the message shorter than 8 bytes
6746 let key = 0x_1234567890ABCDEF_u64;
6747 println!("K =\t{:#016X}", key);
6748 let mut a_des = DES::new_with_key_u64(key);
6749
6750 let message = "7 bytes";
6751 println!("M =\t{}", message);
6752 let iv = 0x_FEDCBA0987654321_u64;
6753 println!("IV = {}", iv);
6754 let mut cipher = [0_u8; 7];
6755 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6756 print!("C =\t");
6757 for c in cipher.clone()
6758 { print!("{:02X} ", c); }
6759 println!();
6760 let mut txt = String::new();
6761 for c in cipher.clone()
6762 { write!(txt, "{:02X} ", c); }
6763 assert_eq!(txt, "50 50 A3 5C E1 B3 E3 ");
6764
6765 let mut recovered = String::new();
6766 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6767 println!("B =\t{}", recovered);
6768 assert_eq!(recovered, "7 bytes");
6769 assert_eq!(recovered, message);
6770 println!();
6771
6772 // Normal case for the message of 8 bytes
6773 let key = 0x_1234567890ABCDEF_u64;
6774 println!("K =\t{:#016X}", key);
6775 let mut a_des = DES::new_with_key_u64(key);
6776
6777 let message = "I am OK.";
6778 println!("M =\t{}", message);
6779 let iv = 0x_FEDCBA0987654321_u64;
6780 println!("IV = {}", iv);
6781 let mut cipher = [0_u8; 8];
6782 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6783 print!("C =\t");
6784 for c in cipher.clone()
6785 { print!("{:02X} ", c); }
6786 println!();
6787 let mut txt = String::new();
6788 for c in cipher.clone()
6789 { write!(txt, "{:02X} ", c); }
6790 assert_eq!(txt, "2E 50 A0 48 B5 99 DB 07 ");
6791
6792 let mut recovered = String::new();
6793 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6794 println!("B =\t{}", recovered);
6795 assert_eq!(recovered, "I am OK.");
6796 assert_eq!(recovered, message);
6797 println!();
6798
6799 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6800 let key = 0x_1234567890ABCDEF_u64;
6801 println!("K =\t{:#016X}", key);
6802 let mut a_des = DES::new_with_key_u64(key);
6803
6804 let message = "PARK Youngho";
6805 println!("M =\t{}", message);
6806 let iv = 0x_FEDCBA0987654321_u64;
6807 println!("IV = {}", iv);
6808 let mut cipher = [0_u8; 12];
6809 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6810 print!("C =\t");
6811 for c in cipher.clone()
6812 { print!("{:02X} ", c); }
6813 println!();
6814 let mut txt = String::new();
6815 for c in cipher.clone()
6816 { write!(txt, "{:02X} ", c); }
6817 assert_eq!(txt, "37 31 93 6E B5 8F FF 5C 21 EF BD 48 ");
6818
6819 let mut recovered = String::new();
6820 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6821 println!("B =\t{}", recovered);
6822 assert_eq!(recovered, "PARK Youngho");
6823 assert_eq!(recovered, message);
6824 println!();
6825
6826 // Normal case for the message of 16 bytes
6827 let key = 0x_1234567890ABCDEF_u64;
6828 println!("K =\t{:#016X}", key);
6829 let mut a_des = DES::new_with_key_u64(key);
6830
6831 let message = "고맙습니다.";
6832 println!("M =\t{}", message);
6833 let iv = 0x_FEDCBA0987654321_u64;
6834 println!("IV = {}", iv);
6835 let mut cipher = [0_u8; 16];
6836 a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
6837 print!("C =\t");
6838 for c in cipher.clone()
6839 { print!("{:02X} ", c); }
6840 println!();
6841 let mut txt = String::new();
6842 for c in cipher.clone()
6843 { write!(txt, "{:02X} ", c); }
6844 assert_eq!(txt, "8D C3 61 CE 32 4F 7C A3 FA 63 5E AF A4 18 0A 6E ");
6845
6846 let mut recovered = String::new();
6847 a_des.decrypt_array_into_string(iv, &cipher, &mut recovered);
6848 println!("B =\t{}", recovered);
6849 assert_eq!(recovered, "고맙습니다.");
6850 assert_eq!(recovered, message);
6851 println!("-------------------------------");
6852}54fn des_encrypt_ctr()
55{
56 println!("des_encrypt_ctr()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
60
61 // Normal case
62 let key = 0x_1234567890ABCDEF_u64;
63 println!("K =\t{:#016X}", key);
64 let mut a_des = DES::new_with_key_u64(key);
65
66 let message = "In the beginning God created the heavens and the earth.";
67 println!("M =\t{}", message);
68 let nonce = 0x_FEDCBA0987654321_u64;
69 println!("Nonce = {}", nonce);
70 let mut cipher = [0_u8; 55];
71 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
72 print!("C (16 rounds) =\t");
73 for c in cipher.clone()
74 { print!("{:02X} ", c); }
75 println!();
76 let mut txt = String::new();
77 for c in cipher.clone()
78 { write!(txt, "{:02X} ", c); }
79 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
80 println!();
81
82 // Expanded case for 128 rounds
83 let key = 0x_1234567890ABCDEF_u64;
84 println!("K =\t{:#016X}", key);
85 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
86
87 let message = "In the beginning God created the heavens and the earth.";
88 println!("M =\t{}", message);
89
90 let nonce = 0x_FEDCBA0987654321_u64;
91 println!("Nonce = {}", nonce);
92 let mut cipher = [0_u8; 55];
93 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
94 print!("C (128 rounds) =\t");
95 for c in cipher.clone()
96 { print!("{:02X} ", c); }
97 println!();
98 let mut txt = String::new();
99 for c in cipher.clone()
100 { write!(txt, "{:02X} ", c); }
101 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
102 println!();
103
104 // Expanded case for 0 rounds which means that key is meaningless
105 let key1 = 0x_1234567890ABCDEF_u64;
106 let key2 = 0_u64;
107 println!("K =\t{:#016X}", key);
108 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
109 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
110
111 let message = "In the beginning God created the heavens and the earth.";
112 println!("M =\t{}", message);
113 let nonce = 0x_FEDCBA0987654321_u64;
114 println!("Nonce = {}", nonce);
115 let mut cipher1 = [0_u8; 55];
116 let mut cipher2 = [0_u8; 55];
117 c_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher1.as_mut_ptr());
118 d_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher2.as_mut_ptr());
119 print!("C (0 rounds) =\t");
120 for c in cipher1.clone()
121 { print!("{:02X} ", c); }
122 println!();
123 let mut txt = String::new();
124 for c in cipher1.clone()
125 { write!(txt, "{:02X} ", c); }
126 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
127 print!("D (0 rounds) =\t");
128 for c in cipher2.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher2.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
135 println!();
136
137 // Normal case for the message of 0 bytes
138 let key = 0x_1234567890ABCDEF_u64;
139 println!("K =\t{:#016X}", key);
140 let mut a_des = DES::new_with_key_u64(key);
141
142 let message = "";
143 println!("M =\t{}", message);
144 let nonce = 0x_FEDCBA0987654321_u64;
145 println!("Nonce = {}", nonce);
146 let mut cipher = [0_u8; 0];
147 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
148 print!("C =\t");
149 for c in cipher.clone()
150 { print!("{:02X} ", c); }
151 println!();
152 let mut txt = String::new();
153 for c in cipher.clone()
154 { write!(txt, "{:02X} ", c); }
155 assert_eq!(txt, "");
156 println!();
157
158 // Normal case for the message shorter than 8 bytes
159 let key = 0x_1234567890ABCDEF_u64;
160 println!("K =\t{:#016X}", key);
161 let mut a_des = DES::new_with_key_u64(key);
162
163 let message = "7 bytes";
164 println!("M =\t{}", message);
165 let nonce = 0x_FEDCBA0987654321_u64;
166 println!("Nonce = {}", nonce);
167 let mut cipher = [0_u8; 7];
168 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
169 print!("C =\t");
170 for c in cipher.clone()
171 { print!("{:02X} ", c); }
172 println!();
173 let mut txt = String::new();
174 for c in cipher.clone()
175 { write!(txt, "{:02X} ", c); }
176 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
177 println!();
178
179 // Normal case for the message of 8 bytes
180 let key = 0x_1234567890ABCDEF_u64;
181 println!("K =\t{:#016X}", key);
182 let mut a_des = DES::new_with_key_u64(key);
183
184 let message = "I am OK.";
185 println!("M =\t{}", message);
186 let nonce = 0x_FEDCBA0987654321_u64;
187 println!("Nonce = {}", nonce);
188 let mut cipher = [0_u8; 8];
189 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
190 print!("C =\t");
191 for c in cipher.clone()
192 { print!("{:02X} ", c); }
193 println!();
194 let mut txt = String::new();
195 for c in cipher.clone()
196 { write!(txt, "{:02X} ", c); }
197 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
198 println!();
199
200 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
201 let key = 0x_1234567890ABCDEF_u64;
202 println!("K =\t{:#016X}", key);
203 let mut a_des = DES::new_with_key_u64(key);
204
205 let message = "PARK Youngho";
206 println!("M =\t{}", message);
207 let nonce = 0x_FEDCBA0987654321_u64;
208 println!("Nonce = {}", nonce);
209 let mut cipher = [0_u8; 12];
210 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
211 print!("C =\t");
212 for c in cipher.clone()
213 { print!("{:02X} ", c); }
214 println!();
215 let mut txt = String::new();
216 for c in cipher.clone()
217 { write!(txt, "{:02X} ", c); }
218 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
219 println!();
220
221 // Normal case for the message of 16 bytes
222 let key = 0x_1234567890ABCDEF_u64;
223 println!("K =\t{:#016X}", key);
224 let mut a_des = DES::new_with_key_u64(key);
225
226 let message = "고맙습니다.";
227 println!("M =\t{}", message);
228 let nonce = 0x_FEDCBA0987654321_u64;
229 println!("Nonce = {}", nonce);
230 let mut cipher = [0_u8; 16];
231 a_des.encrypt(nonce, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
232 print!("C =\t");
233 for c in cipher.clone()
234 { print!("{:02X} ", c); }
235 println!();
236 let mut txt = String::new();
237 for c in cipher.clone()
238 { write!(txt, "{:02X} ", c); }
239 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
240 println!("-------------------------------");
241}
242
243fn des_encrypt_ctr_into_vec()
244{
245 println!("des_encrypt_ctr_into_vec()");
246 use std::io::Write;
247 use std::fmt::Write as _;
248 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
249
250 // Normal case
251 let key = 0x_1234567890ABCDEF_u64;
252 println!("K =\t{:#016X}", key);
253 let mut a_des = DES::new_with_key_u64(key);
254
255 let message = "In the beginning God created the heavens and the earth.";
256 println!("M =\t{}", message);
257 let nonce = 0x_FEDCBA0987654321_u64;
258 println!("Nonce = {}", nonce);
259 let mut cipher = Vec::<u8>::new();
260 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
261 print!("C (16 rounds) =\t");
262 for c in cipher.clone()
263 { print!("{:02X} ", c); }
264 println!();
265 let mut txt = String::new();
266 for c in cipher.clone()
267 { write!(txt, "{:02X} ", c); }
268 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
269 println!();
270
271 // Expanded case for 128 rounds
272 let key = 0x_1234567890ABCDEF_u64;
273 println!("K =\t{:#016X}", key);
274 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
275
276 let message = "In the beginning God created the heavens and the earth.";
277 println!("M =\t{}", message);
278 let nonce = 0x_FEDCBA0987654321_u64;
279 println!("Nonce = {}", nonce);
280 let mut cipher = Vec::<u8>::new();
281 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
282 print!("C (128 rounds) =\t");
283 for c in cipher.clone()
284 { print!("{:02X} ", c); }
285 println!();
286 let mut txt = String::new();
287 for c in cipher.clone()
288 { write!(txt, "{:02X} ", c); }
289 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
290 println!();
291
292 // Expanded case for 0 rounds which means that key is meaningless
293 let key1 = 0x_1234567890ABCDEF_u64;
294 let key2 = 0_u64;
295 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
296 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
297 println!("K =\t{:#016X}", key);
298
299 let message = "In the beginning God created the heavens and the earth.";
300 println!("M =\t{}", message);
301 let nonce = 0x_FEDCBA0987654321_u64;
302 println!("Nonce = {}", nonce);
303 let mut cipher1 = Vec::<u8>::new();
304 let mut cipher2 = Vec::<u8>::new();
305 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
306 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
307 print!("C (0 rounds) =\t");
308 for c in cipher1.clone()
309 { print!("{:02X} ", c); }
310 println!();
311 let mut txt = String::new();
312 for c in cipher1.clone()
313 { write!(txt, "{:02X} ", c); }
314 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
315 print!("D (0 rounds) =\t");
316 for c in cipher2.clone()
317 { print!("{:02X} ", c); }
318 println!();
319 let mut txt = String::new();
320 for c in cipher2.clone()
321 { write!(txt, "{:02X} ", c); }
322 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
323 println!();
324
325 // Normal case for the message of 0 bytes
326 let key = 0x_1234567890ABCDEF_u64;
327 println!("K =\t{:#016X}", key);
328 let mut a_des = DES::new_with_key_u64(key);
329
330 let message = "";
331 println!("M =\t{}", message);
332 let nonce = 0x_FEDCBA0987654321_u64;
333 println!("Nonce = {}", nonce);
334 let mut cipher = Vec::<u8>::new();
335 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
336 print!("C =\t");
337 for c in cipher.clone()
338 { print!("{:02X} ", c); }
339 println!();
340 let mut txt = String::new();
341 for c in cipher.clone()
342 { write!(txt, "{:02X} ", c); }
343 assert_eq!(txt, "");
344 println!();
345
346 // Normal case for the message shorter than 8 bytes
347 let key = 0x_1234567890ABCDEF_u64;
348 println!("K =\t{:#016X}", key);
349 let mut a_des = DES::new_with_key_u64(key);
350
351 let message = "7 bytes";
352 println!("M =\t{}", message);
353 let nonce = 0x_FEDCBA0987654321_u64;
354 println!("Nonce = {}", nonce);
355 let mut cipher = Vec::<u8>::new();
356 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
357 print!("C =\t");
358 for c in cipher.clone()
359 { print!("{:02X} ", c); }
360 println!();
361 let mut txt = String::new();
362 for c in cipher.clone()
363 { write!(txt, "{:02X} ", c); }
364 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
365 println!();
366
367 // Normal case for the message of 8 bytes
368 let key = 0x_1234567890ABCDEF_u64;
369 println!("K =\t{:#016X}", key);
370 let mut a_des = DES::new_with_key_u64(key);
371
372 let message = "I am OK.";
373 println!("M =\t{}", message);
374 let nonce = 0x_FEDCBA0987654321_u64;
375 println!("Nonce = {}", nonce);
376 let mut cipher = Vec::<u8>::new();
377 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
378 print!("C =\t");
379 for c in cipher.clone()
380 { print!("{:02X} ", c); }
381 println!();
382 let mut txt = String::new();
383 for c in cipher.clone()
384 { write!(txt, "{:02X} ", c); }
385 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
386 println!();
387
388 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
389 let key = 0x_1234567890ABCDEF_u64;
390 println!("K =\t{:#016X}", key);
391 let mut a_des = DES::new_with_key_u64(key);
392
393 let message = "PARK Youngho";
394 println!("M =\t{}", message);
395 let nonce = 0x_FEDCBA0987654321_u64;
396 println!("Nonce = {}", nonce);
397 let mut cipher = Vec::<u8>::new();
398 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
399 print!("C =\t");
400 for c in cipher.clone()
401 { print!("{:02X} ", c); }
402 println!();
403 let mut txt = String::new();
404 for c in cipher.clone()
405 { write!(txt, "{:02X} ", c); }
406 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
407 println!();
408
409 // Normal case for the message of 16 bytes
410 let key = 0x_1234567890ABCDEF_u64;
411 println!("K =\t{:#016X}", key);
412 let mut a_des = DES::new_with_key_u64(key);
413
414 let message = "고맙습니다.";
415 println!("M =\t{}", message);
416 let nonce = 0x_FEDCBA0987654321_u64;
417 println!("Nonce = {}", nonce);
418 let mut cipher = Vec::<u8>::new();
419 a_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
420 print!("C =\t");
421 for c in cipher.clone()
422 { print!("{:02X} ", c); }
423 println!();
424 let mut txt = String::new();
425 for c in cipher.clone()
426 { write!(txt, "{:02X} ", c); }
427 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
428 println!("-------------------------------");
429}
430
431fn des_encrypt_ctr_into_array()
432{
433 println!("des_encrypt_ctr_into_array()");
434 use std::io::Write;
435 use std::fmt::Write as _;
436 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
437
438 // Normal case
439 let key = 0x_1234567890ABCDEF_u64;
440 println!("K =\t{:#016X}", key);
441 let mut a_des = DES::new_with_key_u64(key);
442
443 let message = "In the beginning God created the heavens and the earth.";
444 println!("M =\t{}", message);
445 let nonce = 0x_FEDCBA0987654321_u64;
446 println!("Nonce = {}", nonce);
447 let mut cipher = [0_u8; 55];
448 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
449 print!("C (16 rounds) =\t");
450 for c in cipher.clone()
451 { print!("{:02X} ", c); }
452 println!();
453 let mut txt = String::new();
454 for c in cipher.clone()
455 { write!(txt, "{:02X} ", c); }
456 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
457 println!();
458
459 // Expanded case for 128 rounds
460 let key = 0x_1234567890ABCDEF_u64;
461 println!("K =\t{:#016X}", key);
462 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
463
464 let message = "In the beginning God created the heavens and the earth.";
465 println!("M =\t{}", message);
466 let nonce = 0x_FEDCBA0987654321_u64;
467 println!("Nonce = {}", nonce);
468 let mut cipher = [0_u8; 55];
469 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
470 print!("C (128 rounds) =\t");
471 for c in cipher.clone()
472 { print!("{:02X} ", c); }
473 println!();
474 let mut txt = String::new();
475 for c in cipher.clone()
476 { write!(txt, "{:02X} ", c); }
477 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
478 println!();
479
480 // Expanded case for 0 rounds which means that key is meaningless
481 let key1 = 0x_1234567890ABCDEF_u64;
482 let key2 = 0_u64;
483 println!("K =\t{:#016X}", key);
484 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
485 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
486
487 let message = "In the beginning God created the heavens and the earth.";
488 println!("M =\t{}", message);
489 let nonce = 0x_FEDCBA0987654321_u64;
490 println!("Nonce = {}", nonce);
491 let mut cipher1 = [0_u8; 55];
492 let mut cipher2 = [0_u8; 55];
493 c_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
494 d_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
495 print!("C (0 rounds) =\t");
496 for c in cipher1.clone()
497 { print!("{:02X} ", c); }
498 println!();
499 let mut txt = String::new();
500 for c in cipher1.clone()
501 { write!(txt, "{:02X} ", c); }
502 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
503 print!("D (0 rounds) =\t");
504 for c in cipher2.clone()
505 { print!("{:02X} ", c); }
506 println!();
507 let mut txt = String::new();
508 for c in cipher2.clone()
509 { write!(txt, "{:02X} ", c); }
510 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
511 println!();
512
513 // Normal case for the message of 0 bytes
514 let key = 0x_1234567890ABCDEF_u64;
515 println!("K =\t{:#016X}", key);
516 let mut a_des = DES::new_with_key_u64(key);
517
518 let message = "";
519 println!("M =\t{}", message);
520 let nonce = 0x_FEDCBA0987654321_u64;
521 println!("Nonce = {}", nonce);
522 let mut cipher = [0_u8; 0];
523 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
524 print!("C =\t");
525 for c in cipher.clone()
526 { print!("{:02X} ", c); }
527 println!();
528 let mut txt = String::new();
529 for c in cipher.clone()
530 { write!(txt, "{:02X} ", c); }
531 assert_eq!(txt, "");
532 println!();
533
534 // Normal case for the message shorter than 8 bytes
535 let key = 0x_1234567890ABCDEF_u64;
536 println!("K =\t{:#016X}", key);
537 let mut a_des = DES::new_with_key_u64(key);
538
539 let message = "7 bytes";
540 println!("M =\t{}", message);
541 let nonce = 0x_FEDCBA0987654321_u64;
542 println!("Nonce = {}", nonce);
543 let mut cipher = [0_u8; 7];
544 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
545 print!("C =\t");
546 for c in cipher.clone()
547 { print!("{:02X} ", c); }
548 println!();
549 let mut txt = String::new();
550 for c in cipher.clone()
551 { write!(txt, "{:02X} ", c); }
552 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
553 println!();
554
555 // Normal case for the message of 8 bytes
556 let key = 0x_1234567890ABCDEF_u64;
557 println!("K =\t{:#016X}", key);
558 let mut a_des = DES::new_with_key_u64(key);
559
560 let message = "I am OK.";
561 println!("M =\t{}", message);
562 let nonce = 0x_FEDCBA0987654321_u64;
563 println!("Nonce = {}", nonce);
564 let mut cipher = [0_u8; 8];
565 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
566 print!("C =\t");
567 for c in cipher.clone()
568 { print!("{:02X} ", c); }
569 println!();
570 let mut txt = String::new();
571 for c in cipher.clone()
572 { write!(txt, "{:02X} ", c); }
573 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
574 println!();
575
576 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
577 let key = 0x_1234567890ABCDEF_u64;
578 println!("K =\t{:#016X}", key);
579 let mut a_des = DES::new_with_key_u64(key);
580
581 let message = "PARK Youngho";
582 println!("M =\t{}", message);
583 let nonce = 0x_FEDCBA0987654321_u64;
584 println!("Nonce = {}", nonce);
585 let mut cipher = [0_u8; 12];
586 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
587 print!("C =\t");
588 for c in cipher.clone()
589 { print!("{:02X} ", c); }
590 println!();
591 let mut txt = String::new();
592 for c in cipher.clone()
593 { write!(txt, "{:02X} ", c); }
594 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
595 println!();
596
597 // Normal case for the message of 16 bytes
598 let key = 0x_1234567890ABCDEF_u64;
599 println!("K =\t{:#016X}", key);
600 let mut a_des = DES::new_with_key_u64(key);
601
602 let message = "고맙습니다.";
603 println!("M =\t{}", message);
604 let nonce = 0x_FEDCBA0987654321_u64;
605 println!("Nonce = {}", nonce);
606 let mut cipher = [0_u8; 16];
607 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
608 print!("C =\t");
609 for c in cipher.clone()
610 { print!("{:02X} ", c); }
611 println!();
612 let mut txt = String::new();
613 for c in cipher.clone()
614 { write!(txt, "{:02X} ", c); }
615 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
616 println!("-------------------------------");
617}
618
619fn des_encrypt_str_ctr()
620{
621 println!("des_encrypt_str_ctr()");
622 use std::io::Write;
623 use std::fmt::Write as _;
624 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
625
626 // Normal case
627 let key = 0x_1234567890ABCDEF_u64;
628 println!("K =\t{:#016X}", key);
629 let mut a_des = DES::new_with_key_u64(key);
630
631 let message = "In the beginning God created the heavens and the earth.";
632 println!("M =\t{}", message);
633 let nonce = 0x_FEDCBA0987654321_u64;
634 println!("Nonce = {}", nonce);
635 let mut cipher = [0_u8; 55];
636 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
637 print!("C (16 rounds) =\t");
638 for c in cipher.clone()
639 { print!("{:02X} ", c); }
640 println!();
641 let mut txt = String::new();
642 for c in cipher.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
645 println!();
646
647 // Expanded case for 128 rounds
648 let key = 0x_1234567890ABCDEF_u64;
649 println!("K =\t{:#016X}", key);
650 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
651
652 let message = "In the beginning God created the heavens and the earth.";
653 println!("M =\t{}", message);
654 let nonce = 0x_FEDCBA0987654321_u64;
655 println!("Nonce = {}", nonce);
656 let mut cipher = [0_u8; 55];
657 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
658 print!("C (128 rounds) =\t");
659 for c in cipher.clone()
660 { print!("{:02X} ", c); }
661 println!();
662 let mut txt = String::new();
663 for c in cipher.clone()
664 { write!(txt, "{:02X} ", c); }
665 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
666 println!();
667
668 // Expanded case for 0 rounds which means that key is meaningless
669 let key1 = 0x_1234567890ABCDEF_u64;
670 let key2 = 0_u64;
671 println!("K =\t{:#016X}", key);
672 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
673 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
674
675 let message = "In the beginning God created the heavens and the earth.";
676 println!("M =\t{}", message);
677 let nonce = 0x_FEDCBA0987654321_u64;
678 println!("Nonce = {}", nonce);
679 let mut cipher1 = [0_u8; 55];
680 let mut cipher2 = [0_u8; 55];
681 c_des.encrypt_str(nonce, &message, cipher1.as_mut_ptr());
682 d_des.encrypt_str(nonce, &message, cipher2.as_mut_ptr());
683 print!("C (0 rounds) =\t");
684 for c in cipher1.clone()
685 { print!("{:02X} ", c); }
686 println!();
687 let mut txt = String::new();
688 for c in cipher1.clone()
689 { write!(txt, "{:02X} ", c); }
690 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
691 print!("D (0 rounds) =\t");
692 for c in cipher2.clone()
693 { print!("{:02X} ", c); }
694 println!();
695 let mut txt = String::new();
696 for c in cipher2.clone()
697 { write!(txt, "{:02X} ", c); }
698 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
699 println!();
700
701 // Normal case for the message of 0 bytes
702 let key = 0x_1234567890ABCDEF_u64;
703 println!("K =\t{:#016X}", key);
704 let mut a_des = DES::new_with_key_u64(key);
705
706 let message = "";
707 println!("M =\t{}", message);
708 let nonce = 0x_FEDCBA0987654321_u64;
709 println!("Nonce = {}", nonce);
710 let mut cipher = [0_u8; 0];
711 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "");
720 println!();
721
722 // Normal case for the message shorter than 8 bytes
723 let key = 0x_1234567890ABCDEF_u64;
724 println!("K =\t{:#016X}", key);
725 let mut a_des = DES::new_with_key_u64(key);
726
727 let message = "7 bytes";
728 println!("M =\t{}", message);
729 let nonce = 0x_FEDCBA0987654321_u64;
730 println!("Nonce = {}", nonce);
731 let mut cipher = [0_u8; 7];
732 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
733 print!("C =\t");
734 for c in cipher.clone()
735 { print!("{:02X} ", c); }
736 println!();
737 let mut txt = String::new();
738 for c in cipher.clone()
739 { write!(txt, "{:02X} ", c); }
740 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
741 println!();
742
743 // Normal case for the message of 8 bytes
744 let key = 0x_1234567890ABCDEF_u64;
745 println!("K =\t{:#016X}", key);
746 let mut a_des = DES::new_with_key_u64(key);
747
748 let message = "I am OK.";
749 println!("M =\t{}", message);
750 let nonce = 0x_FEDCBA0987654321_u64;
751 println!("Nonce = {}", nonce);
752 let mut cipher = [0_u8; 8];
753 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
754 print!("C =\t");
755 for c in cipher.clone()
756 { print!("{:02X} ", c); }
757 println!();
758 let mut txt = String::new();
759 for c in cipher.clone()
760 { write!(txt, "{:02X} ", c); }
761 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
762 println!();
763
764 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
765 let key = 0x_1234567890ABCDEF_u64;
766 println!("K =\t{:#016X}", key);
767 let mut a_des = DES::new_with_key_u64(key);
768
769 let message = "PARK Youngho";
770 println!("M =\t{}", message);
771 let nonce = 0x_FEDCBA0987654321_u64;
772 println!("Nonce = {}", nonce);
773 let mut cipher = [0_u8; 12];
774 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
775 print!("C =\t");
776 for c in cipher.clone()
777 { print!("{:02X} ", c); }
778 println!();
779 let mut txt = String::new();
780 for c in cipher.clone()
781 { write!(txt, "{:02X} ", c); }
782 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
783 println!();
784
785 // Normal case for the message of 16 bytes
786 let key = 0x_1234567890ABCDEF_u64;
787 println!("K =\t{:#016X}", key);
788 let mut a_des = DES::new_with_key_u64(key);
789
790 let message = "고맙습니다.";
791 println!("M =\t{}", message);
792 let nonce = 0x_FEDCBA0987654321_u64;
793 println!("Nonce = {}", nonce);
794 let mut cipher = [0_u8; 16];
795 a_des.encrypt_str(nonce, &message, cipher.as_mut_ptr());
796 print!("C =\t");
797 for c in cipher.clone()
798 { print!("{:02X} ", c); }
799 println!();
800 let mut txt = String::new();
801 for c in cipher.clone()
802 { write!(txt, "{:02X} ", c); }
803 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
804 println!("-------------------------------");
805}
806
807fn des_encrypt_str_ctr_into_vec()
808{
809 println!("des_encrypt_str_ctr_into_vec()");
810 use std::io::Write;
811 use std::fmt::Write as _;
812 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
813
814 // Normal case
815 let key = 0x_1234567890ABCDEF_u64;
816 println!("K =\t{:#016X}", key);
817 let mut a_des = DES::new_with_key_u64(key);
818
819 let message = "In the beginning God created the heavens and the earth.";
820 println!("M =\t{}", message);
821 let nonce = 0x_FEDCBA0987654321_u64;
822 println!("Nonce = {}", nonce);
823 let mut cipher = Vec::<u8>::new();
824 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
825 print!("C (16 rounds) =\t");
826 for c in cipher.clone()
827 { print!("{:02X} ", c); }
828 println!();
829 let mut txt = String::new();
830 for c in cipher.clone()
831 { write!(txt, "{:02X} ", c); }
832 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
833 println!();
834
835 // Expanded case for 128 rounds
836 let key = 0x_1234567890ABCDEF_u64;
837 println!("K =\t{:#016X}", key);
838 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
839
840 let message = "In the beginning God created the heavens and the earth.";
841 println!("M =\t{}", message);
842 let nonce = 0x_FEDCBA0987654321_u64;
843 println!("Nonce = {}", nonce);
844 let mut cipher = Vec::<u8>::new();
845 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
846 print!("C (128 rounds) =\t");
847 for c in cipher.clone()
848 { print!("{:02X} ", c); }
849 println!();
850 let mut txt = String::new();
851 for c in cipher.clone()
852 { write!(txt, "{:02X} ", c); }
853 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
854 println!();
855
856 // Expanded case for 0 rounds which means that key is meaningless
857 let key1 = 0x_1234567890ABCDEF_u64;
858 let key2 = 0_u64;
859 println!("K =\t{:#016X}", key);
860 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
861 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
862
863 let message = "In the beginning God created the heavens and the earth.";
864 println!("M =\t{}", message);
865 let nonce = 0x_FEDCBA0987654321_u64;
866 println!("Nonce = {}", nonce);
867 let mut cipher1 = Vec::<u8>::new();
868 let mut cipher2 = Vec::<u8>::new();
869 c_des.encrypt_str_into_vec(nonce, &message, &mut cipher1);
870 d_des.encrypt_str_into_vec(nonce, &message, &mut cipher2);
871 print!("C (0 rounds) =\t");
872 for c in cipher1.clone()
873 { print!("{:02X} ", c); }
874 println!();
875 let mut txt = String::new();
876 for c in cipher1.clone()
877 { write!(txt, "{:02X} ", c); }
878 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
879 print!("D (0 rounds) =\t");
880 for c in cipher2.clone()
881 { print!("{:02X} ", c); }
882 println!();
883 let mut txt = String::new();
884 for c in cipher2.clone()
885 { write!(txt, "{:02X} ", c); }
886 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
887 println!();
888
889 // Normal case for the message of 0 bytes
890 let key = 0x_1234567890ABCDEF_u64;
891 println!("K =\t{:#016X}", key);
892 let mut a_des = DES::new_with_key_u64(key);
893
894 let message = "";
895 println!("M =\t{}", message);
896 let nonce = 0x_FEDCBA0987654321_u64;
897 println!("Nonce = {}", nonce);
898 let mut cipher = Vec::<u8>::new();
899 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
900 print!("C =\t");
901 for c in cipher.clone()
902 { print!("{:02X} ", c); }
903 println!();
904 let mut txt = String::new();
905 for c in cipher.clone()
906 { write!(txt, "{:02X} ", c); }
907 assert_eq!(txt, "");
908 println!();
909
910 // Normal case for the message shorter than 8 bytes
911 let key = 0x_1234567890ABCDEF_u64;
912 println!("K =\t{:#016X}", key);
913 let mut a_des = DES::new_with_key_u64(key);
914
915 let message = "7 bytes";
916 println!("M =\t{}", message);
917 let nonce = 0x_FEDCBA0987654321_u64;
918 println!("Nonce = {}", nonce);
919 let mut cipher = Vec::<u8>::new();
920 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
921 print!("C =\t");
922 for c in cipher.clone()
923 { print!("{:02X} ", c); }
924 println!();
925 let mut txt = String::new();
926 for c in cipher.clone()
927 { write!(txt, "{:02X} ", c); }
928 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
929 println!();
930
931 // Normal case for the message of 8 bytes
932 let key = 0x_1234567890ABCDEF_u64;
933 println!("K =\t{:#016X}", key);
934 let mut a_des = DES::new_with_key_u64(key);
935
936 let message = "I am OK.";
937 println!("M =\t{}", message);
938 let nonce = 0x_FEDCBA0987654321_u64;
939 println!("Nonce = {}", nonce);
940 let mut cipher = Vec::<u8>::new();
941 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
942 print!("C =\t");
943 for c in cipher.clone()
944 { print!("{:02X} ", c); }
945 println!();
946 let mut txt = String::new();
947 for c in cipher.clone()
948 { write!(txt, "{:02X} ", c); }
949 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
950 println!();
951
952 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
953 let key = 0x_1234567890ABCDEF_u64;
954 println!("K =\t{:#016X}", key);
955 let mut a_des = DES::new_with_key_u64(key);
956
957 let message = "PARK Youngho";
958 println!("M =\t{}", message);
959 let nonce = 0x_FEDCBA0987654321_u64;
960 println!("Nonce = {}", nonce);
961 let mut cipher = Vec::<u8>::new();
962 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
963 print!("C =\t");
964 for c in cipher.clone()
965 { print!("{:02X} ", c); }
966 println!();
967 let mut txt = String::new();
968 for c in cipher.clone()
969 { write!(txt, "{:02X} ", c); }
970 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
971 println!();
972
973 // Normal case for the message of 16 bytes
974 let key = 0x_1234567890ABCDEF_u64;
975 println!("K =\t{:#016X}", key);
976 let mut a_des = DES::new_with_key_u64(key);
977
978 let message = "고맙습니다.";
979 println!("M =\t{}", message);
980 let nonce = 0x_FEDCBA0987654321_u64;
981 println!("Nonce = {}", nonce);
982 let mut cipher = Vec::<u8>::new();
983 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
984 print!("C =\t");
985 for c in cipher.clone()
986 { print!("{:02X} ", c); }
987 println!();
988 let mut txt = String::new();
989 for c in cipher.clone()
990 { write!(txt, "{:02X} ", c); }
991 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
992 println!("-------------------------------");
993}
994
995fn des_encrypt_str_ctr_into_array()
996{
997 println!("des_encrypt_str_ctr_into_array()");
998 use std::io::Write;
999 use std::fmt::Write as _;
1000 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
1001
1002 // Normal case
1003 let key = 0x_1234567890ABCDEF_u64;
1004 println!("K =\t{:#016X}", key);
1005 let mut a_des = DES::new_with_key_u64(key);
1006
1007 let message = "In the beginning God created the heavens and the earth.";
1008 println!("M =\t{}", message);
1009 let nonce = 0x_FEDCBA0987654321_u64;
1010 println!("Nonce = {}", nonce);
1011 let mut cipher = [0_u8; 55];
1012 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1013 print!("C (16 rounds) =\t");
1014 for c in cipher.clone()
1015 { print!("{:02X} ", c); }
1016 println!();
1017 let mut txt = String::new();
1018 for c in cipher.clone()
1019 { write!(txt, "{:02X} ", c); }
1020 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
1021 println!();
1022
1023 // Expanded case for 128 rounds
1024 let key = 0x_1234567890ABCDEF_u64;
1025 println!("K =\t{:#016X}", key);
1026 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1027
1028 let message = "In the beginning God created the heavens and the earth.";
1029 println!("M =\t{}", message);
1030 let nonce = 0x_FEDCBA0987654321_u64;
1031 println!("Nonce = {}", nonce);
1032 let mut cipher = [0_u8; 55];
1033 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1034 print!("C (128 rounds) =\t");
1035 for c in cipher.clone()
1036 { print!("{:02X} ", c); }
1037 println!();
1038 let mut txt = String::new();
1039 for c in cipher.clone()
1040 { write!(txt, "{:02X} ", c); }
1041 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
1042 println!();
1043
1044 // Expanded case for 0 rounds which means that key is meaningless
1045 let key1 = 0x_1234567890ABCDEF_u64;
1046 let key2 = 0_u64;
1047 println!("K =\t{:#016X}", key);
1048 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1049 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1050
1051 let message = "In the beginning God created the heavens and the earth.";
1052 println!("M =\t{}", message);
1053 let nonce = 0x_FEDCBA0987654321_u64;
1054 println!("Nonce = {}", nonce);
1055 let mut cipher1 = [0_u8; 55];
1056 let mut cipher2 = [0_u8; 55];
1057 c_des.encrypt_str_into_array(nonce, &message, &mut cipher1);
1058 d_des.encrypt_str_into_array(nonce, &message, &mut cipher2);
1059 print!("C (0 rounds) =\t");
1060 for c in cipher1.clone()
1061 { print!("{:02X} ", c); }
1062 println!();
1063 let mut txt = String::new();
1064 for c in cipher1.clone()
1065 { write!(txt, "{:02X} ", c); }
1066 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1067 print!("D (0 rounds) =\t");
1068 for c in cipher2.clone()
1069 { print!("{:02X} ", c); }
1070 println!();
1071 let mut txt = String::new();
1072 for c in cipher2.clone()
1073 { write!(txt, "{:02X} ", c); }
1074 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1075 println!();
1076
1077 // Normal case for the message of 0 bytes
1078 let key = 0x_1234567890ABCDEF_u64;
1079 println!("K =\t{:#016X}", key);
1080 let mut a_des = DES::new_with_key_u64(key);
1081
1082 let message = "";
1083 println!("M =\t{}", message);
1084 let nonce = 0x_FEDCBA0987654321_u64;
1085 println!("Nonce = {}", nonce);
1086 let mut cipher = [0_u8; 0];
1087 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1088 print!("C =\t");
1089 for c in cipher.clone()
1090 { print!("{:02X} ", c); }
1091 println!();
1092 let mut txt = String::new();
1093 for c in cipher.clone()
1094 { write!(txt, "{:02X} ", c); }
1095 assert_eq!(txt, "");
1096 println!();
1097
1098 // Normal case for the message shorter than 8 bytes
1099 let key = 0x_1234567890ABCDEF_u64;
1100 println!("K =\t{:#016X}", key);
1101 let mut a_des = DES::new_with_key_u64(key);
1102
1103 let message = "7 bytes";
1104 println!("M =\t{}", message);
1105 let nonce = 0x_FEDCBA0987654321_u64;
1106 println!("Nonce = {}", nonce);
1107 let mut cipher = [0_u8; 7];
1108 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1109 print!("C =\t");
1110 for c in cipher.clone()
1111 { print!("{:02X} ", c); }
1112 println!();
1113 let mut txt = String::new();
1114 for c in cipher.clone()
1115 { write!(txt, "{:02X} ", c); }
1116 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
1117 println!();
1118
1119 // Normal case for the message of 8 bytes
1120 let key = 0x_1234567890ABCDEF_u64;
1121 println!("K =\t{:#016X}", key);
1122 let mut a_des = DES::new_with_key_u64(key);
1123
1124 let message = "I am OK.";
1125 println!("M =\t{}", message);
1126 let nonce = 0x_FEDCBA0987654321_u64;
1127 println!("Nonce = {}", nonce);
1128 let mut cipher = [0_u8; 8];
1129 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1130 print!("C =\t");
1131 for c in cipher.clone()
1132 { print!("{:02X} ", c); }
1133 println!();
1134 let mut txt = String::new();
1135 for c in cipher.clone()
1136 { write!(txt, "{:02X} ", c); }
1137 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
1138 println!();
1139
1140 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1141 let key = 0x_1234567890ABCDEF_u64;
1142 println!("K =\t{:#016X}", key);
1143 let mut a_des = DES::new_with_key_u64(key);
1144
1145 let message = "PARK Youngho";
1146 println!("M =\t{}", message);
1147 let nonce = 0x_FEDCBA0987654321_u64;
1148 println!("Nonce = {}", nonce);
1149 let mut cipher = [0_u8; 12];
1150 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1151 print!("C =\t");
1152 for c in cipher.clone()
1153 { print!("{:02X} ", c); }
1154 println!();
1155 let mut txt = String::new();
1156 for c in cipher.clone()
1157 { write!(txt, "{:02X} ", c); }
1158 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
1159 println!();
1160
1161 // Normal case for the message of 16 bytes
1162 let key = 0x_1234567890ABCDEF_u64;
1163 println!("K =\t{:#016X}", key);
1164 let mut a_des = DES::new_with_key_u64(key);
1165
1166 let message = "고맙습니다.";
1167 println!("M =\t{}", message);
1168 let nonce = 0x_FEDCBA0987654321_u64;
1169 println!("Nonce = {}", nonce);
1170 let mut cipher = [0_u8; 16];
1171 a_des.encrypt_str_into_array(nonce, &message, &mut cipher);
1172 print!("C =\t");
1173 for c in cipher.clone()
1174 { print!("{:02X} ", c); }
1175 println!();
1176 let mut txt = String::new();
1177 for c in cipher.clone()
1178 { write!(txt, "{:02X} ", c); }
1179 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
1180 println!("-------------------------------");
1181}
1182
1183fn des_encrypt_string_ctr()
1184{
1185 println!("des_encrypt_string_ctr()");
1186 use std::io::Write;
1187 use std::fmt::Write as _;
1188 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
1189
1190 // Normal case
1191 let key = 0x_1234567890ABCDEF_u64;
1192 println!("K =\t{:#016X}", key);
1193 let mut a_des = DES::new_with_key_u64(key);
1194
1195 let message = "In the beginning God created the heavens and the earth.".to_string();
1196 println!("M =\t{}", message);
1197 let nonce = 0x_FEDCBA0987654321_u64;
1198 println!("Nonce = {}", nonce);
1199 let mut cipher = [0_u8; 55];
1200 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1201 print!("C (16 rounds) =\t");
1202 for c in cipher.clone()
1203 { print!("{:02X} ", c); }
1204 println!();
1205 let mut txt = String::new();
1206 for c in cipher.clone()
1207 { write!(txt, "{:02X} ", c); }
1208 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
1209 println!();
1210
1211 // Expanded case for 128 rounds
1212 let key = 0x_1234567890ABCDEF_u64;
1213 println!("K =\t{:#016X}", key);
1214 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1215
1216 let message = "In the beginning God created the heavens and the earth.".to_string();
1217 println!("M =\t{}", message);
1218 let nonce = 0x_FEDCBA0987654321_u64;
1219 println!("Nonce = {}", nonce);
1220 let mut cipher = [0_u8; 55];
1221 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1222 print!("C (128 rounds) =\t");
1223 for c in cipher.clone()
1224 { print!("{:02X} ", c); }
1225 println!();
1226 let mut txt = String::new();
1227 for c in cipher.clone()
1228 { write!(txt, "{:02X} ", c); }
1229 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
1230 println!();
1231
1232 // Expanded case for 0 rounds which means that key is meaningless
1233 let key1 = 0x_1234567890ABCDEF_u64;
1234 let key2 = 0_u64;
1235 println!("K =\t{:#016X}", key);
1236 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1237 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1238
1239 let message = "In the beginning God created the heavens and the earth.".to_string();
1240 println!("M =\t{}", message);
1241 let nonce = 0x_FEDCBA0987654321_u64;
1242 println!("Nonce = {}", nonce);
1243 let mut cipher1 = [0_u8; 55];
1244 let mut cipher2 = [0_u8; 55];
1245 c_des.encrypt_string(nonce, &message, cipher1.as_mut_ptr());
1246 d_des.encrypt_string(nonce, &message, cipher2.as_mut_ptr());
1247 print!("C (0 rounds) =\t");
1248 for c in cipher1.clone()
1249 { print!("{:02X} ", c); }
1250 println!();
1251 let mut txt = String::new();
1252 for c in cipher1.clone()
1253 { write!(txt, "{:02X} ", c); }
1254 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1255 print!("D (0 rounds) =\t");
1256 for c in cipher2.clone()
1257 { print!("{:02X} ", c); }
1258 println!();
1259 let mut txt = String::new();
1260 for c in cipher2.clone()
1261 { write!(txt, "{:02X} ", c); }
1262 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1263 println!();
1264
1265 // Normal case for the message of 0 bytes
1266 let key = 0x_1234567890ABCDEF_u64;
1267 println!("K =\t{:#016X}", key);
1268 let mut a_des = DES::new_with_key_u64(key);
1269
1270 let message = "".to_string();
1271 println!("M =\t{}", message);
1272 let nonce = 0x_FEDCBA0987654321_u64;
1273 println!("Nonce = {}", nonce);
1274 let mut cipher = [0_u8; 0];
1275 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1276 print!("C =\t");
1277 for c in cipher.clone()
1278 { print!("{:02X} ", c); }
1279 println!();
1280 let mut txt = String::new();
1281 for c in cipher.clone()
1282 { write!(txt, "{:02X} ", c); }
1283 assert_eq!(txt, "");
1284 println!();
1285
1286 // Normal case for the message shorter than 8 bytes
1287 let key = 0x_1234567890ABCDEF_u64;
1288 println!("K =\t{:#016X}", key);
1289 let mut a_des = DES::new_with_key_u64(key);
1290
1291 let message = "7 bytes".to_string();
1292 println!("M =\t{}", message);
1293 let nonce = 0x_FEDCBA0987654321_u64;
1294 println!("Nonce = {}", nonce);
1295 let mut cipher = [0_u8; 7];
1296 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1297 print!("C =\t");
1298 for c in cipher.clone()
1299 { print!("{:02X} ", c); }
1300 println!();
1301 let mut txt = String::new();
1302 for c in cipher.clone()
1303 { write!(txt, "{:02X} ", c); }
1304 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
1305 println!();
1306
1307 // Normal case for the message of 8 bytes
1308 let key = 0x_1234567890ABCDEF_u64;
1309 println!("K =\t{:#016X}", key);
1310 let mut a_des = DES::new_with_key_u64(key);
1311
1312 let message = "I am OK.".to_string();
1313 println!("M =\t{}", message);
1314 let nonce = 0x_FEDCBA0987654321_u64;
1315 println!("Nonce = {}", nonce);
1316 let mut cipher = [0_u8; 8];
1317 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1318 print!("C =\t");
1319 for c in cipher.clone()
1320 { print!("{:02X} ", c); }
1321 println!();
1322 let mut txt = String::new();
1323 for c in cipher.clone()
1324 { write!(txt, "{:02X} ", c); }
1325 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
1326 println!();
1327
1328 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1329 let key = 0x_1234567890ABCDEF_u64;
1330 println!("K =\t{:#016X}", key);
1331 let mut a_des = DES::new_with_key_u64(key);
1332
1333 let message = "PARK Youngho".to_string();
1334 println!("M =\t{}", message);
1335 let nonce = 0x_FEDCBA0987654321_u64;
1336 println!("Nonce = {}", nonce);
1337 let mut cipher = [0_u8; 12];
1338 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1339 print!("C =\t");
1340 for c in cipher.clone()
1341 { print!("{:02X} ", c); }
1342 println!();
1343 let mut txt = String::new();
1344 for c in cipher.clone()
1345 { write!(txt, "{:02X} ", c); }
1346 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
1347 println!();
1348
1349 // Normal case for the message of 16 bytes
1350 let key = 0x_1234567890ABCDEF_u64;
1351 println!("K =\t{:#016X}", key);
1352 let mut a_des = DES::new_with_key_u64(key);
1353
1354 let message = "고맙습니다.".to_string();
1355 println!("M =\t{}", message);
1356 let nonce = 0x_FEDCBA0987654321_u64;
1357 println!("Nonce = {}", nonce);
1358 let mut cipher = [0_u8; 16];
1359 a_des.encrypt_string(nonce, &message, cipher.as_mut_ptr());
1360 print!("C =\t");
1361 for c in cipher.clone()
1362 { print!("{:02X} ", c); }
1363 println!();
1364 let mut txt = String::new();
1365 for c in cipher.clone()
1366 { write!(txt, "{:02X} ", c); }
1367 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
1368 println!("-------------------------------");
1369}
1370
1371fn des_encrypt_string_ctr_into_vec()
1372{
1373 println!("des_encrypt_string_ctr_into_vec()");
1374 use std::io::Write;
1375 use std::fmt::Write as _;
1376 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
1377
1378 // Normal case
1379 let key = 0x_1234567890ABCDEF_u64;
1380 println!("K =\t{:#016X}", key);
1381 let mut a_des = DES::new_with_key_u64(key);
1382
1383 let message = "In the beginning God created the heavens and the earth.".to_string();
1384 println!("M =\t{}", message);
1385 let nonce = 0x_FEDCBA0987654321_u64;
1386 println!("Nonce = {}", nonce);
1387 let mut cipher = Vec::<u8>::new();
1388 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1389 print!("C (16 rounds) =\t");
1390 for c in cipher.clone()
1391 { print!("{:02X} ", c); }
1392 println!();
1393 let mut txt = String::new();
1394 for c in cipher.clone()
1395 { write!(txt, "{:02X} ", c); }
1396 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
1397 println!();
1398
1399 // Expanded case for 128 rounds
1400 let key = 0x_1234567890ABCDEF_u64;
1401 println!("K =\t{:#016X}", key);
1402 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1403
1404 let message = "In the beginning God created the heavens and the earth.".to_string();
1405 println!("M =\t{}", message);
1406 let nonce = 0x_FEDCBA0987654321_u64;
1407 println!("Nonce = {}", nonce);
1408 let mut cipher = Vec::<u8>::new();
1409 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1410 print!("C (128 rounds) =\t");
1411 for c in cipher.clone()
1412 { print!("{:02X} ", c); }
1413 println!();
1414 let mut txt = String::new();
1415 for c in cipher.clone()
1416 { write!(txt, "{:02X} ", c); }
1417 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
1418 println!();
1419
1420 // Expanded case for 0 rounds which means that key is meaningless
1421 let key1 = 0x_1234567890ABCDEF_u64;
1422 let key2 = 0_u64;
1423 println!("K =\t{:#016X}", key);
1424 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1425 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1426
1427 let message = "In the beginning God created the heavens and the earth.".to_string();
1428 println!("M =\t{}", message);
1429 let nonce = 0x_FEDCBA0987654321_u64;
1430 println!("Nonce = {}", nonce);
1431 let mut cipher1 = Vec::<u8>::new();
1432 let mut cipher2 = Vec::<u8>::new();
1433 c_des.encrypt_string_into_vec(nonce, &message, &mut cipher1);
1434 d_des.encrypt_string_into_vec(nonce, &message, &mut cipher2);
1435 print!("C (0 rounds) =\t");
1436 for c in cipher1.clone()
1437 { print!("{:02X} ", c); }
1438 println!();
1439 let mut txt = String::new();
1440 for c in cipher1.clone()
1441 { write!(txt, "{:02X} ", c); }
1442 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1443 print!("D (0 rounds) =\t");
1444 for c in cipher2.clone()
1445 { print!("{:02X} ", c); }
1446 println!();
1447 let mut txt = String::new();
1448 for c in cipher2.clone()
1449 { write!(txt, "{:02X} ", c); }
1450 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1451 println!();
1452
1453 // Normal case for the message of 0 bytes
1454 let key = 0x_1234567890ABCDEF_u64;
1455 println!("K =\t{:#016X}", key);
1456 let mut a_des = DES::new_with_key_u64(key);
1457
1458 let message = "".to_string();
1459 println!("M =\t{}", message);
1460 let nonce = 0x_FEDCBA0987654321_u64;
1461 println!("Nonce = {}", nonce);
1462 let mut cipher = Vec::<u8>::new();
1463 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1464 print!("C =\t");
1465 for c in cipher.clone()
1466 { print!("{:02X} ", c); }
1467 println!();
1468 let mut txt = String::new();
1469 for c in cipher.clone()
1470 { write!(txt, "{:02X} ", c); }
1471 assert_eq!(txt, "");
1472 println!();
1473
1474 // Normal case for the message shorter than 8 bytes
1475 let key = 0x_1234567890ABCDEF_u64;
1476 println!("K =\t{:#016X}", key);
1477 let mut a_des = DES::new_with_key_u64(key);
1478
1479 let message = "7 bytes".to_string();
1480 println!("M =\t{}", message);
1481 let nonce = 0x_FEDCBA0987654321_u64;
1482 println!("Nonce = {}", nonce);
1483 let mut cipher = Vec::<u8>::new();
1484 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1485 print!("C =\t");
1486 for c in cipher.clone()
1487 { print!("{:02X} ", c); }
1488 println!();
1489 let mut txt = String::new();
1490 for c in cipher.clone()
1491 { write!(txt, "{:02X} ", c); }
1492 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
1493 println!();
1494
1495 // Normal case for the message of 8 bytes
1496 let key = 0x_1234567890ABCDEF_u64;
1497 println!("K =\t{:#016X}", key);
1498 let mut a_des = DES::new_with_key_u64(key);
1499
1500 let message = "I am OK.".to_string();
1501 println!("M =\t{}", message);
1502 let nonce = 0x_FEDCBA0987654321_u64;
1503 println!("Nonce = {}", nonce);
1504 let mut cipher = Vec::<u8>::new();
1505 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1506 print!("C =\t");
1507 for c in cipher.clone()
1508 { print!("{:02X} ", c); }
1509 println!();
1510 let mut txt = String::new();
1511 for c in cipher.clone()
1512 { write!(txt, "{:02X} ", c); }
1513 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
1514 println!();
1515
1516 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1517 let key = 0x_1234567890ABCDEF_u64;
1518 println!("K =\t{:#016X}", key);
1519 let mut a_des = DES::new_with_key_u64(key);
1520
1521 let message = "PARK Youngho".to_string();
1522 println!("M =\t{}", message);
1523 let nonce = 0x_FEDCBA0987654321_u64;
1524 println!("Nonce = {}", nonce);
1525 let mut cipher = Vec::<u8>::new();
1526 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1527 print!("C =\t");
1528 for c in cipher.clone()
1529 { print!("{:02X} ", c); }
1530 println!();
1531 let mut txt = String::new();
1532 for c in cipher.clone()
1533 { write!(txt, "{:02X} ", c); }
1534 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
1535 println!();
1536
1537 // Normal case for the message of 16 bytes
1538 let key = 0x_1234567890ABCDEF_u64;
1539 println!("K =\t{:#016X}", key);
1540 let mut a_des = DES::new_with_key_u64(key);
1541
1542 let message = "고맙습니다.".to_string();
1543 println!("M =\t{}", message);
1544 let nonce = 0x_FEDCBA0987654321_u64;
1545 println!("Nonce = {}", nonce);
1546 let mut cipher = Vec::<u8>::new();
1547 a_des.encrypt_string_into_vec(nonce, &message, &mut cipher);
1548 print!("C =\t");
1549 for c in cipher.clone()
1550 { print!("{:02X} ", c); }
1551 println!();
1552 let mut txt = String::new();
1553 for c in cipher.clone()
1554 { write!(txt, "{:02X} ", c); }
1555 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
1556 println!("-------------------------------");
1557}
1558
1559fn des_encrypt_string_ctr_into_array()
1560{
1561 println!("des_encrypt_string_ctr_into_array()");
1562 use std::io::Write;
1563 use std::fmt::Write as _;
1564 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
1565
1566 // Normal case
1567 let key = 0x_1234567890ABCDEF_u64;
1568 println!("K =\t{:#016X}", key);
1569 let mut a_des = DES::new_with_key_u64(key);
1570
1571 let message = "In the beginning God created the heavens and the earth.".to_string();
1572 println!("M =\t{}", message);
1573 let nonce = 0x_FEDCBA0987654321_u64;
1574 println!("Nonce = {}", nonce);
1575 let mut cipher = [0_u8; 55];
1576 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1577 print!("C (16 rounds) =\t");
1578 for c in cipher.clone()
1579 { print!("{:02X} ", c); }
1580 println!();
1581 let mut txt = String::new();
1582 for c in cipher.clone()
1583 { write!(txt, "{:02X} ", c); }
1584 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
1585 println!();
1586
1587 // Expanded case for 128 rounds
1588 let key = 0x_1234567890ABCDEF_u64;
1589 println!("K =\t{:#016X}", key);
1590 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1591
1592 let message = "In the beginning God created the heavens and the earth.".to_string();
1593 println!("M =\t{}", message);
1594 let nonce = 0x_FEDCBA0987654321_u64;
1595 println!("Nonce = {}", nonce);
1596 let mut cipher = [0_u8; 55];
1597 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1598 print!("C (128 rounds) =\t");
1599 for c in cipher.clone()
1600 { print!("{:02X} ", c); }
1601 println!();
1602 let mut txt = String::new();
1603 for c in cipher.clone()
1604 { write!(txt, "{:02X} ", c); }
1605 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
1606 println!();
1607
1608 // Expanded case for 0 rounds which means that key is meaningless
1609 let key1 = 0x_1234567890ABCDEF_u64;
1610 let key2 = 0_u64;
1611 println!("K =\t{:#016X}", key);
1612 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1613 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1614
1615 let message = "In the beginning God created the heavens and the earth.".to_string();
1616 println!("M =\t{}", message);
1617 let nonce = 0x_FEDCBA0987654321_u64;
1618 println!("Nonce = {}", nonce);
1619 let mut cipher1 = [0_u8; 55];
1620 let mut cipher2 = [0_u8; 55];
1621 c_des.encrypt_string_into_array(nonce, &message, &mut cipher1);
1622 d_des.encrypt_string_into_array(nonce, &message, &mut cipher2);
1623 print!("C (0 rounds) =\t");
1624 for c in cipher1.clone()
1625 { print!("{:02X} ", c); }
1626 println!();
1627 let mut txt = String::new();
1628 for c in cipher1.clone()
1629 { write!(txt, "{:02X} ", c); }
1630 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1631 print!("D (0 rounds) =\t");
1632 for c in cipher2.clone()
1633 { print!("{:02X} ", c); }
1634 println!();
1635 let mut txt = String::new();
1636 for c in cipher2.clone()
1637 { write!(txt, "{:02X} ", c); }
1638 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1639 println!();
1640
1641 // Normal case for the message of 0 bytes
1642 let key = 0x_1234567890ABCDEF_u64;
1643 println!("K =\t{:#016X}", key);
1644 let mut a_des = DES::new_with_key_u64(key);
1645
1646 let message = "".to_string();
1647 println!("M =\t{}", message);
1648 let nonce = 0x_FEDCBA0987654321_u64;
1649 println!("Nonce = {}", nonce);
1650 let mut cipher = [0_u8; 0];
1651 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1652 print!("C =\t");
1653 for c in cipher.clone()
1654 { print!("{:02X} ", c); }
1655 println!();
1656 let mut txt = String::new();
1657 for c in cipher.clone()
1658 { write!(txt, "{:02X} ", c); }
1659 assert_eq!(txt, "");
1660 println!();
1661
1662 // Normal case for the message shorter than 8 bytes
1663 let key = 0x_1234567890ABCDEF_u64;
1664 println!("K =\t{:#016X}", key);
1665 let mut a_des = DES::new_with_key_u64(key);
1666
1667 let message = "7 bytes".to_string();
1668 println!("M =\t{}", message);
1669 let nonce = 0x_FEDCBA0987654321_u64;
1670 println!("Nonce = {}", nonce);
1671 let mut cipher = [0_u8; 7];
1672 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1673 print!("C =\t");
1674 for c in cipher.clone()
1675 { print!("{:02X} ", c); }
1676 println!();
1677 let mut txt = String::new();
1678 for c in cipher.clone()
1679 { write!(txt, "{:02X} ", c); }
1680 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
1681 println!();
1682
1683 // Normal case for the message of 8 bytes
1684 let key = 0x_1234567890ABCDEF_u64;
1685 println!("K =\t{:#016X}", key);
1686 let mut a_des = DES::new_with_key_u64(key);
1687
1688 let message = "I am OK.".to_string();
1689 println!("M =\t{}", message);
1690 let nonce = 0x_FEDCBA0987654321_u64;
1691 println!("Nonce = {}", nonce);
1692 let mut cipher = [0_u8; 8];
1693 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1694 print!("C =\t");
1695 for c in cipher.clone()
1696 { print!("{:02X} ", c); }
1697 println!();
1698 let mut txt = String::new();
1699 for c in cipher.clone()
1700 { write!(txt, "{:02X} ", c); }
1701 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
1702 println!();
1703
1704 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1705 let key = 0x_1234567890ABCDEF_u64;
1706 println!("K =\t{:#016X}", key);
1707 let mut a_des = DES::new_with_key_u64(key);
1708
1709 let message = "PARK Youngho".to_string();
1710 println!("M =\t{}", message);
1711 let nonce = 0x_FEDCBA0987654321_u64;
1712 println!("Nonce = {}", nonce);
1713 let mut cipher = [0_u8; 12];
1714 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1715 print!("C =\t");
1716 for c in cipher.clone()
1717 { print!("{:02X} ", c); }
1718 println!();
1719 let mut txt = String::new();
1720 for c in cipher.clone()
1721 { write!(txt, "{:02X} ", c); }
1722 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
1723 println!();
1724
1725 // Normal case for the message of 16 bytes
1726 let key = 0x_1234567890ABCDEF_u64;
1727 println!("K =\t{:#016X}", key);
1728 let mut a_des = DES::new_with_key_u64(key);
1729
1730 let message = "고맙습니다.".to_string();
1731 println!("M =\t{}", message);
1732 let nonce = 0x_FEDCBA0987654321_u64;
1733 println!("Nonce = {}", nonce);
1734 let mut cipher = [0_u8; 16];
1735 a_des.encrypt_string_into_array(nonce, &message, &mut cipher);
1736 print!("C =\t");
1737 for c in cipher.clone()
1738 { print!("{:02X} ", c); }
1739 println!();
1740 let mut txt = String::new();
1741 for c in cipher.clone()
1742 { write!(txt, "{:02X} ", c); }
1743 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
1744 println!("-------------------------------");
1745}
1746
1747fn des_encrypt_vec_ctr()
1748{
1749 println!("des_encrypt_vec_ctr()");
1750 use std::io::Write;
1751 use std::fmt::Write as _;
1752 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
1753
1754 // Normal case
1755 let key = 0x_1234567890ABCDEF_u64;
1756 println!("K =\t{:#016X}", key);
1757 let mut a_des = DES::new_with_key_u64(key);
1758
1759 let message = "In the beginning God created the heavens and the earth.";
1760 println!("M =\t{}", message);
1761 let message = unsafe { message.to_string().as_mut_vec().clone() };
1762 let nonce = 0x_FEDCBA0987654321_u64;
1763 println!("Nonce = {}", nonce);
1764 let mut cipher = [0_u8; 55];
1765 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1766 print!("C (16 rounds) =\t");
1767 for c in cipher.clone()
1768 { print!("{:02X} ", c); }
1769 println!();
1770 let mut txt = String::new();
1771 for c in cipher.clone()
1772 { write!(txt, "{:02X} ", c); }
1773 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
1774 println!();
1775
1776 // Expanded case for 128 rounds
1777 let key = 0x_1234567890ABCDEF_u64;
1778 println!("K =\t{:#016X}", key);
1779 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1780
1781 let message = "In the beginning God created the heavens and the earth.";
1782 println!("M =\t{}", message);
1783 let message = unsafe { message.to_string().as_mut_vec().clone() };
1784 let nonce = 0x_FEDCBA0987654321_u64;
1785 println!("Nonce = {}", nonce);
1786 let mut cipher = [0_u8; 55];
1787 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1788 print!("C (128 rounds) =\t");
1789 for c in cipher.clone()
1790 { print!("{:02X} ", c); }
1791 println!();
1792 let mut txt = String::new();
1793 for c in cipher.clone()
1794 { write!(txt, "{:02X} ", c); }
1795 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
1796 println!();
1797
1798 // Expanded case for 0 rounds which means that key is meaningless
1799 let key1 = 0x_1234567890ABCDEF_u64;
1800 let key2 = 0_u64;
1801 println!("K1 =\t{:#016X}", key1);
1802 println!("K2 =\t{:#016X}", key2);
1803 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1804 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1805
1806 let message = "In the beginning God created the heavens and the earth.";
1807 println!("M =\t{}", message);
1808 let message = unsafe { message.to_string().as_mut_vec().clone() };
1809 let nonce = 0x_FEDCBA0987654321_u64;
1810 println!("Nonce = {}", nonce);
1811 let mut cipher1 = [0_u8; 55];
1812 let mut cipher2 = [0_u8; 55];
1813 c_des.encrypt_vec(nonce, &message, cipher1.as_mut_ptr());
1814 d_des.encrypt_vec(nonce, &message, cipher2.as_mut_ptr());
1815 print!("C (0 rounds) =\t");
1816 for c in cipher1.clone()
1817 { print!("{:02X} ", c); }
1818 println!();
1819 let mut txt = String::new();
1820 for c in cipher1.clone()
1821 { write!(txt, "{:02X} ", c); }
1822 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1823 print!("D (0 rounds) =\t");
1824 for c in cipher2.clone()
1825 { print!("{:02X} ", c); }
1826 println!();
1827 let mut txt = String::new();
1828 for c in cipher2.clone()
1829 { write!(txt, "{:02X} ", c); }
1830 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
1831 println!();
1832
1833 // Normal case for the message of 0 bytes
1834 let key = 0x_1234567890ABCDEF_u64;
1835 println!("K =\t{:#016X}", key);
1836 let mut a_des = DES::new_with_key_u64(key);
1837
1838 let message = "";
1839 println!("M =\t{}", message);
1840 let message = unsafe { message.to_string().as_mut_vec().clone() };
1841 let nonce = 0x_FEDCBA0987654321_u64;
1842 println!("Nonce = {}", nonce);
1843 let mut cipher = [0_u8; 0];
1844 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1845 print!("C =\t");
1846 for c in cipher.clone()
1847 { print!("{:02X} ", c); }
1848 println!();
1849 let mut txt = String::new();
1850 for c in cipher.clone()
1851 { write!(txt, "{:02X} ", c); }
1852 assert_eq!(txt, "");
1853 println!();
1854
1855 // Normal case for the message shorter than 8 bytes
1856 let key = 0x_1234567890ABCDEF_u64;
1857 println!("K =\t{:#016X}", key);
1858 let mut a_des = DES::new_with_key_u64(key);
1859
1860 let message = "7 bytes";
1861 println!("M =\t{}", message);
1862 let message = unsafe { message.to_string().as_mut_vec().clone() };
1863 let nonce = 0x_FEDCBA0987654321_u64;
1864 println!("Nonce = {}", nonce);
1865 let mut cipher = [0_u8; 7];
1866 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1867 print!("C =\t");
1868 for c in cipher.clone()
1869 { print!("{:02X} ", c); }
1870 println!();
1871 let mut txt = String::new();
1872 for c in cipher.clone()
1873 { write!(txt, "{:02X} ", c); }
1874 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
1875 println!();
1876
1877 // Normal case for the message of 8 bytes
1878 let key = 0x_1234567890ABCDEF_u64;
1879 println!("K =\t{:#016X}", key);
1880 let mut a_des = DES::new_with_key_u64(key);
1881
1882 let message = "I am OK.";
1883 println!("M =\t{}", message);
1884 let message = unsafe { message.to_string().as_mut_vec().clone() };
1885 let nonce = 0x_FEDCBA0987654321_u64;
1886 println!("Nonce = {}", nonce);
1887 let mut cipher = [0_u8; 8];
1888 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1889 print!("C =\t");
1890 for c in cipher.clone()
1891 { print!("{:02X} ", c); }
1892 println!();
1893 let mut txt = String::new();
1894 for c in cipher.clone()
1895 { write!(txt, "{:02X} ", c); }
1896 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
1897 println!();
1898
1899 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
1900 let key = 0x_1234567890ABCDEF_u64;
1901 println!("K =\t{:#016X}", key);
1902 let mut a_des = DES::new_with_key_u64(key);
1903
1904 let message = "PARK Youngho";
1905 println!("M =\t{}", message);
1906 let message = unsafe { message.to_string().as_mut_vec().clone() };
1907 let nonce = 0x_FEDCBA0987654321_u64;
1908 println!("Nonce = {}", nonce);
1909 let mut cipher = [0_u8; 12];
1910 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1911 print!("C =\t");
1912 for c in cipher.clone()
1913 { print!("{:02X} ", c); }
1914 println!();
1915 let mut txt = String::new();
1916 for c in cipher.clone()
1917 { write!(txt, "{:02X} ", c); }
1918 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
1919 println!();
1920
1921 // Normal case for the message of 16 bytes
1922 let key = 0x_1234567890ABCDEF_u64;
1923 println!("K =\t{:#016X}", key);
1924 let mut a_des = DES::new_with_key_u64(key);
1925
1926 let message = "고맙습니다.";
1927 println!("M =\t{}", message);
1928 let message = unsafe { message.to_string().as_mut_vec().clone() };
1929 let nonce = 0x_FEDCBA0987654321_u64;
1930 println!("Nonce = {}", nonce);
1931 let mut cipher = [0_u8; 16];
1932 a_des.encrypt_vec(nonce, &message, cipher.as_mut_ptr());
1933 print!("C =\t");
1934 for c in cipher.clone()
1935 { print!("{:02X} ", c); }
1936 println!();
1937 let mut txt = String::new();
1938 for c in cipher.clone()
1939 { write!(txt, "{:02X} ", c); }
1940 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
1941 println!("-------------------------------");
1942}
1943
1944fn des_encrypt_vec_ctr_into_vec()
1945{
1946 println!("des_encrypt_vec_ctr_into_vec()");
1947 use std::io::Write;
1948 use std::fmt::Write as _;
1949 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
1950
1951 // Normal case
1952 let key = 0x_1234567890ABCDEF_u64;
1953 println!("K =\t{:#016X}", key);
1954 let mut a_des = DES::new_with_key_u64(key);
1955
1956 let message = "In the beginning God created the heavens and the earth.";
1957 println!("M =\t{}", message);
1958 let message = unsafe { message.to_string().as_mut_vec().clone() };
1959 let nonce = 0x_FEDCBA0987654321_u64;
1960 println!("Nonce = {}", nonce);
1961 let mut cipher = Vec::<u8>::new();
1962 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
1963 print!("C (16 rounds) =\t");
1964 for c in cipher.clone()
1965 { print!("{:02X} ", c); }
1966 println!();
1967 let mut txt = String::new();
1968 for c in cipher.clone()
1969 { write!(txt, "{:02X} ", c); }
1970 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
1971 println!();
1972
1973 // Expanded case for 128 rounds
1974 let key = 0x_1234567890ABCDEF_u64;
1975 println!("K =\t{:#016X}", key);
1976 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1977
1978 let message = "In the beginning God created the heavens and the earth.";
1979 println!("M =\t{}", message);
1980 let message = unsafe { message.to_string().as_mut_vec().clone() };
1981 let nonce = 0x_FEDCBA0987654321_u64;
1982 println!("Nonce = {}", nonce);
1983 let mut cipher = Vec::<u8>::new();
1984 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
1985 print!("C (128 rounds) =\t");
1986 for c in cipher.clone()
1987 { print!("{:02X} ", c); }
1988 println!();
1989 let mut txt = String::new();
1990 for c in cipher.clone()
1991 { write!(txt, "{:02X} ", c); }
1992 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
1993 println!();
1994
1995 // Expanded case for 0 rounds which means that key is meaningless
1996 let key1 = 0x_1234567890ABCDEF_u64;
1997 let key2 = 0_u64;
1998 println!("K1 =\t{:#016X}", key1);
1999 println!("K2 =\t{:#016X}", key2);
2000 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2001 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2002
2003 let message = "In the beginning God created the heavens and the earth.";
2004 println!("M =\t{}", message);
2005 let message = unsafe { message.to_string().as_mut_vec().clone() };
2006
2007 let nonce = 0x_FEDCBA0987654321_u64;
2008 println!("Nonce = {}", nonce);
2009 let mut cipher1 = Vec::<u8>::new();
2010 let mut cipher2 = Vec::<u8>::new();
2011 c_des.encrypt_vec_into_vec(nonce, &message, &mut cipher1);
2012 d_des.encrypt_vec_into_vec(nonce, &message, &mut cipher2);
2013 print!("C (0 rounds) =\t");
2014 for c in cipher1.clone()
2015 { print!("{:02X} ", c); }
2016 println!();
2017 let mut txt = String::new();
2018 for c in cipher1.clone()
2019 { write!(txt, "{:02X} ", c); }
2020 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2021 print!("D (0 rounds) =\t");
2022 for c in cipher2.clone()
2023 { print!("{:02X} ", c); }
2024 println!();
2025 let mut txt = String::new();
2026 for c in cipher2.clone()
2027 { write!(txt, "{:02X} ", c); }
2028 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2029 println!();
2030
2031 // Normal case for the message of 0 bytes
2032 let key = 0x_1234567890ABCDEF_u64;
2033 println!("K =\t{:#016X}", key);
2034 let mut a_des = DES::new_with_key_u64(key);
2035
2036 let message = "";
2037 println!("M =\t{}", message);
2038 let message = unsafe { message.to_string().as_mut_vec().clone() };
2039 let nonce = 0x_FEDCBA0987654321_u64;
2040 println!("Nonce = {}", nonce);
2041 let mut cipher = Vec::<u8>::new();
2042 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
2043 print!("C =\t");
2044 for c in cipher.clone()
2045 { print!("{:02X} ", c); }
2046 println!();
2047 let mut txt = String::new();
2048 for c in cipher.clone()
2049 { write!(txt, "{:02X} ", c); }
2050 assert_eq!(txt, "");
2051 println!();
2052
2053 // Normal case for the message shorter than 8 bytes
2054 let key = 0x_1234567890ABCDEF_u64;
2055 println!("K =\t{:#016X}", key);
2056 let mut a_des = DES::new_with_key_u64(key);
2057
2058 let message = "7 bytes";
2059 println!("M =\t{}", message);
2060 let message = unsafe { message.to_string().as_mut_vec().clone() };
2061 let nonce = 0x_FEDCBA0987654321_u64;
2062 println!("Nonce = {}", nonce);
2063 let mut cipher = Vec::<u8>::new();
2064 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
2065 print!("C =\t");
2066 for c in cipher.clone()
2067 { print!("{:02X} ", c); }
2068 println!();
2069 let mut txt = String::new();
2070 for c in cipher.clone()
2071 { write!(txt, "{:02X} ", c); }
2072 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
2073 println!();
2074
2075 // Normal case for the message of 8 bytes
2076 let key = 0x_1234567890ABCDEF_u64;
2077 println!("K =\t{:#016X}", key);
2078 let mut a_des = DES::new_with_key_u64(key);
2079
2080 let message = "I am OK.";
2081 println!("M =\t{}", message);
2082 let message = unsafe { message.to_string().as_mut_vec().clone() };
2083 let nonce = 0x_FEDCBA0987654321_u64;
2084 println!("Nonce = {}", nonce);
2085 let mut cipher = Vec::<u8>::new();
2086 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
2087 print!("C =\t");
2088 for c in cipher.clone()
2089 { print!("{:02X} ", c); }
2090 println!();
2091 let mut txt = String::new();
2092 for c in cipher.clone()
2093 { write!(txt, "{:02X} ", c); }
2094 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
2095 println!();
2096
2097 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2098 let key = 0x_1234567890ABCDEF_u64;
2099 println!("K =\t{:#016X}", key);
2100 let mut a_des = DES::new_with_key_u64(key);
2101
2102 let message = "PARK Youngho";
2103 println!("M =\t{}", message);
2104 let message = unsafe { message.to_string().as_mut_vec().clone() };
2105 let nonce = 0x_FEDCBA0987654321_u64;
2106 println!("Nonce = {}", nonce);
2107 let mut cipher = Vec::<u8>::new();
2108 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
2109 print!("C =\t");
2110 for c in cipher.clone()
2111 { print!("{:02X} ", c); }
2112 println!();
2113 let mut txt = String::new();
2114 for c in cipher.clone()
2115 { write!(txt, "{:02X} ", c); }
2116 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
2117 println!();
2118
2119 // Normal case for the message of 16 bytes
2120 let key = 0x_1234567890ABCDEF_u64;
2121 println!("K =\t{:#016X}", key);
2122 let mut a_des = DES::new_with_key_u64(key);
2123
2124 let message = "고맙습니다.";
2125 println!("M =\t{}", message);
2126 let message = unsafe { message.to_string().as_mut_vec().clone() };
2127 let nonce = 0x_FEDCBA0987654321_u64;
2128 println!("Nonce = {}", nonce);
2129 let mut cipher = Vec::<u8>::new();
2130 a_des.encrypt_vec_into_vec(nonce, &message, &mut cipher);
2131 print!("C =\t");
2132 for c in cipher.clone()
2133 { print!("{:02X} ", c); }
2134 println!();
2135 let mut txt = String::new();
2136 for c in cipher.clone()
2137 { write!(txt, "{:02X} ", c); }
2138 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
2139 println!("-------------------------------");
2140}
2141
2142fn des_encrypt_vec_ctr_into_array()
2143{
2144 println!("des_encrypt_vec_ctr_into_array()");
2145 use std::io::Write;
2146 use std::fmt::Write as _;
2147 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
2148
2149 // Normal case
2150 let key = 0x_1234567890ABCDEF_u64;
2151 println!("K =\t{:#016X}", key);
2152 let mut a_des = DES::new_with_key_u64(key);
2153
2154 let message = "In the beginning God created the heavens and the earth.";
2155 println!("M =\t{}", message);
2156 let message = unsafe { message.to_string().as_mut_vec().clone() };
2157 let nonce = 0x_FEDCBA0987654321_u64;
2158 println!("Nonce = {}", nonce);
2159 let mut cipher = [0_u8; 55];
2160 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2161 print!("C (16 rounds) =\t");
2162 for c in cipher.clone()
2163 { print!("{:02X} ", c); }
2164 println!();
2165 let mut txt = String::new();
2166 for c in cipher.clone()
2167 { write!(txt, "{:02X} ", c); }
2168 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
2169 println!();
2170
2171 // Expanded case for 128 rounds
2172 let key = 0x_1234567890ABCDEF_u64;
2173 println!("K =\t{:#016X}", key);
2174 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2175
2176 let message = "In the beginning God created the heavens and the earth.";
2177 println!("M =\t{}", message);
2178 let message = unsafe { message.to_string().as_mut_vec().clone() };
2179 let nonce = 0x_FEDCBA0987654321_u64;
2180 println!("Nonce = {}", nonce);
2181 let mut cipher = [0_u8; 55];
2182 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2183 print!("C (128 rounds) =\t");
2184 for c in cipher.clone()
2185 { print!("{:02X} ", c); }
2186 println!();
2187 let mut txt = String::new();
2188 for c in cipher.clone()
2189 { write!(txt, "{:02X} ", c); }
2190 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
2191 println!();
2192
2193 // Expanded case for 0 rounds which means that key is meaningless
2194 let key1 = 0x_1234567890ABCDEF_u64;
2195 let key2 = 0_u64;
2196 println!("K1 =\t{:#016X}", key1);
2197 println!("K2 =\t{:#016X}", key2);
2198 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2199 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2200
2201 let message = "In the beginning God created the heavens and the earth.";
2202 println!("M =\t{}", message);
2203 let message = unsafe { message.to_string().as_mut_vec().clone() };
2204 let nonce = 0x_FEDCBA0987654321_u64;
2205 println!("Nonce = {}", nonce);
2206 let mut cipher1 = [0_u8; 55];
2207 let mut cipher2 = [0_u8; 55];
2208 c_des.encrypt_vec_into_array(nonce, &message, &mut cipher1);
2209 d_des.encrypt_vec_into_array(nonce, &message, &mut cipher2);
2210 print!("C (0 rounds) =\t");
2211 for c in cipher1.clone()
2212 { print!("{:02X} ", c); }
2213 println!();
2214 let mut txt = String::new();
2215 for c in cipher1.clone()
2216 { write!(txt, "{:02X} ", c); }
2217 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2218 print!("D (0 rounds) =\t");
2219 for c in cipher2.clone()
2220 { print!("{:02X} ", c); }
2221 println!();
2222 let mut txt = String::new();
2223 for c in cipher2.clone()
2224 { write!(txt, "{:02X} ", c); }
2225 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2226 println!();
2227
2228 // Normal case for the message of 0 bytes
2229 let key = 0x_1234567890ABCDEF_u64;
2230 println!("K =\t{:#016X}", key);
2231 let mut a_des = DES::new_with_key_u64(key);
2232
2233 let message = "";
2234 println!("M =\t{}", message);
2235 let message = unsafe { message.to_string().as_mut_vec().clone() };
2236 let nonce = 0x_FEDCBA0987654321_u64;
2237 println!("Nonce = {}", nonce);
2238 let mut cipher = [0_u8; 0];
2239 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2240 print!("C =\t");
2241 for c in cipher.clone()
2242 { print!("{:02X} ", c); }
2243 println!();
2244 let mut txt = String::new();
2245 for c in cipher.clone()
2246 { write!(txt, "{:02X} ", c); }
2247 assert_eq!(txt, "");
2248 println!();
2249
2250 // Normal case for the message shorter than 8 bytes
2251 let key = 0x_1234567890ABCDEF_u64;
2252 println!("K =\t{:#016X}", key);
2253 let mut a_des = DES::new_with_key_u64(key);
2254
2255 let message = "7 bytes";
2256 println!("M =\t{}", message);
2257 let message = unsafe { message.to_string().as_mut_vec().clone() };
2258 let nonce = 0x_FEDCBA0987654321_u64;
2259 println!("Nonce = {}", nonce);
2260 let mut cipher = [0_u8; 7];
2261 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2262 print!("C =\t");
2263 for c in cipher.clone()
2264 { print!("{:02X} ", c); }
2265 println!();
2266 let mut txt = String::new();
2267 for c in cipher.clone()
2268 { write!(txt, "{:02X} ", c); }
2269 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
2270 println!();
2271
2272 // Normal case for the message of 8 bytes
2273 let key = 0x_1234567890ABCDEF_u64;
2274 println!("K =\t{:#016X}", key);
2275 let mut a_des = DES::new_with_key_u64(key);
2276
2277 let message = "I am OK.";
2278 println!("M =\t{}", message);
2279 let message = unsafe { message.to_string().as_mut_vec().clone() };
2280 let nonce = 0x_FEDCBA0987654321_u64;
2281 println!("Nonce = {}", nonce);
2282 let mut cipher = [0_u8; 8];
2283 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2284 print!("C =\t");
2285 for c in cipher.clone()
2286 { print!("{:02X} ", c); }
2287 println!();
2288 let mut txt = String::new();
2289 for c in cipher.clone()
2290 { write!(txt, "{:02X} ", c); }
2291 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
2292 println!();
2293
2294 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2295 let key = 0x_1234567890ABCDEF_u64;
2296 println!("K =\t{:#016X}", key);
2297 let mut a_des = DES::new_with_key_u64(key);
2298
2299 let message = "PARK Youngho";
2300 println!("M =\t{}", message);
2301 let message = unsafe { message.to_string().as_mut_vec().clone() };
2302 let nonce = 0x_FEDCBA0987654321_u64;
2303 println!("Nonce = {}", nonce);
2304 let mut cipher = [0_u8; 12];
2305 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2306 print!("C =\t");
2307 for c in cipher.clone()
2308 { print!("{:02X} ", c); }
2309 println!();
2310 let mut txt = String::new();
2311 for c in cipher.clone()
2312 { write!(txt, "{:02X} ", c); }
2313 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
2314 println!();
2315
2316 // Normal case for the message of 16 bytes
2317 let key = 0x_1234567890ABCDEF_u64;
2318 println!("K =\t{:#016X}", key);
2319 let mut a_des = DES::new_with_key_u64(key);
2320
2321 let message = "고맙습니다.";
2322 println!("M =\t{}", message);
2323 let message = unsafe { message.to_string().as_mut_vec().clone() };
2324 let nonce = 0x_FEDCBA0987654321_u64;
2325 println!("Nonce = {}", nonce);
2326 let mut cipher = [0_u8; 16];
2327 a_des.encrypt_vec_into_array(nonce, &message, &mut cipher);
2328 print!("C =\t");
2329 for c in cipher.clone()
2330 { print!("{:02X} ", c); }
2331 println!();
2332 let mut txt = String::new();
2333 for c in cipher.clone()
2334 { write!(txt, "{:02X} ", c); }
2335 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
2336 println!("-------------------------------");
2337}
2338
2339fn des_encrypt_array_ctr()
2340{
2341 println!("des_encrypt_array_ctr()");
2342 use std::io::Write;
2343 use std::fmt::Write as _;
2344 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
2345
2346 // Normal case
2347 let key = 0x_1234567890ABCDEF_u64;
2348 println!("K =\t{:#016X}", key);
2349 let mut a_des = DES::new_with_key_u64(key);
2350
2351 let mes = "In the beginning God created the heavens and the earth.";
2352 println!("M =\t{}", mes);
2353 let mut message = [0_u8; 55];
2354 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2355 let nonce = 0x_FEDCBA0987654321_u64;
2356 println!("Nonce = {}", nonce);
2357 let mut cipher = [0_u8; 55];
2358 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2359 print!("C (16 rounds) =\t");
2360 for c in cipher.clone()
2361 { print!("{:02X} ", c); }
2362 println!();
2363 let mut txt = String::new();
2364 for c in cipher.clone()
2365 { write!(txt, "{:02X} ", c); }
2366 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
2367 println!();
2368
2369 // Expanded case for 128 rounds
2370 let key = 0x_1234567890ABCDEF_u64;
2371 println!("K =\t{:#016X}", key);
2372 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2373
2374 let mes = "In the beginning God created the heavens and the earth.";
2375 println!("M =\t{}", mes);
2376 let mut message = [0_u8; 55];
2377 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2378 let nonce = 0x_FEDCBA0987654321_u64;
2379 println!("Nonce = {}", nonce);
2380 let mut cipher = [0_u8; 55];
2381 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2382 print!("C (128 rounds) =\t");
2383 for c in cipher.clone()
2384 { print!("{:02X} ", c); }
2385 println!();
2386 let mut txt = String::new();
2387 for c in cipher.clone()
2388 { write!(txt, "{:02X} ", c); }
2389 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
2390 println!();
2391
2392 // Expanded case for 0 rounds which means that key is meaningless
2393 let key1 = 0x_1234567890ABCDEF_u64;
2394 let key2 = 0_u64;
2395 println!("K1 =\t{:#016X}", key1);
2396 println!("K2 =\t{:#016X}", key2);
2397 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2398 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2399
2400 let mes = "In the beginning God created the heavens and the earth.";
2401 println!("M =\t{}", mes);
2402 let mut message = [0_u8; 55];
2403 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2404 let nonce = 0x_FEDCBA0987654321_u64;
2405 println!("Nonce = {}", nonce);
2406 let mut cipher1 = [0_u8; 55];
2407 let mut cipher2 = [0_u8; 55];
2408 c_des.encrypt_array(nonce, &message, cipher1.as_mut_ptr());
2409 d_des.encrypt_array(nonce, &message, cipher2.as_mut_ptr());
2410 print!("C (0 rounds) =\t");
2411 for c in cipher1.clone()
2412 { print!("{:02X} ", c); }
2413 println!();
2414 let mut txt = String::new();
2415 for c in cipher1.clone()
2416 { write!(txt, "{:02X} ", c); }
2417 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2418 print!("D (0 rounds) =\t");
2419 for c in cipher2.clone()
2420 { print!("{:02X} ", c); }
2421 println!();
2422 let mut txt = String::new();
2423 for c in cipher2.clone()
2424 { write!(txt, "{:02X} ", c); }
2425 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2426 println!();
2427
2428 // Normal case for the message of 0 bytes
2429 let key = 0x_1234567890ABCDEF_u64;
2430 println!("K =\t{:#016X}", key);
2431 let mut a_des = DES::new_with_key_u64(key);
2432
2433 let mes = "";
2434 println!("M =\t{}", mes);
2435 let mut message = [0_u8; 0];
2436 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2437 let nonce = 0x_FEDCBA0987654321_u64;
2438 println!("Nonce = {}", nonce);
2439 let mut cipher = [0_u8; 0];
2440 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2441 print!("C =\t");
2442 for c in cipher.clone()
2443 { print!("{:02X} ", c); }
2444 println!();
2445 let mut txt = String::new();
2446 for c in cipher.clone()
2447 { write!(txt, "{:02X} ", c); }
2448 assert_eq!(txt, "");
2449 println!();
2450
2451 // Normal case for the message shorter than 8 bytes
2452 let key = 0x_1234567890ABCDEF_u64;
2453 println!("K =\t{:#016X}", key);
2454 let mut a_des = DES::new_with_key_u64(key);
2455
2456 let mes = "7 bytes";
2457 println!("M =\t{}", mes);
2458 let mut message = [0_u8; 7];
2459 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2460 let nonce = 0x_FEDCBA0987654321_u64;
2461 println!("Nonce = {}", nonce);
2462 let mut cipher = [0_u8; 7];
2463 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2464 print!("C =\t");
2465 for c in cipher.clone()
2466 { print!("{:02X} ", c); }
2467 println!();
2468 let mut txt = String::new();
2469 for c in cipher.clone()
2470 { write!(txt, "{:02X} ", c); }
2471 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
2472 println!();
2473
2474 // Normal case for the message of 8 bytes
2475 let key = 0x_1234567890ABCDEF_u64;
2476 println!("K =\t{:#016X}", key);
2477 let mut a_des = DES::new_with_key_u64(key);
2478
2479 let mes = "I am OK.";
2480 println!("M =\t{}", mes);
2481 let mut message = [0_u8; 8];
2482 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2483 let nonce = 0x_FEDCBA0987654321_u64;
2484 println!("Nonce = {}", nonce);
2485 let mut cipher = [0_u8; 8];
2486 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2487 print!("C =\t");
2488 for c in cipher.clone()
2489 { print!("{:02X} ", c); }
2490 println!();
2491 let mut txt = String::new();
2492 for c in cipher.clone()
2493 { write!(txt, "{:02X} ", c); }
2494 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
2495 println!();
2496
2497 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2498 let key = 0x_1234567890ABCDEF_u64;
2499 println!("K =\t{:#016X}", key);
2500 let mut a_des = DES::new_with_key_u64(key);
2501
2502 let mes = "PARK Youngho";
2503 println!("M =\t{}", mes);
2504 let mut message = [0_u8; 12];
2505 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2506 let nonce = 0x_FEDCBA0987654321_u64;
2507 println!("Nonce = {}", nonce);
2508 let mut cipher = [0_u8; 12];
2509 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2510 print!("C =\t");
2511 for c in cipher.clone()
2512 { print!("{:02X} ", c); }
2513 println!();
2514 let mut txt = String::new();
2515 for c in cipher.clone()
2516 { write!(txt, "{:02X} ", c); }
2517 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
2518 println!();
2519
2520 // Normal case for the message of 16 bytes
2521 let key = 0x_1234567890ABCDEF_u64;
2522 println!("K =\t{:#016X}", key);
2523 let mut a_des = DES::new_with_key_u64(key);
2524
2525 let mes = "고맙습니다.";
2526 println!("M =\t{}", mes);
2527 let mut message = [0_u8; 16];
2528 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2529 let nonce = 0x_FEDCBA0987654321_u64;
2530 println!("Nonce = {}", nonce);
2531 let mut cipher = [0_u8; 16];
2532 a_des.encrypt_array(nonce, &message, cipher.as_mut_ptr());
2533 print!("C =\t");
2534 for c in cipher.clone()
2535 { print!("{:02X} ", c); }
2536 println!();
2537 let mut txt = String::new();
2538 for c in cipher.clone()
2539 { write!(txt, "{:02X} ", c); }
2540 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
2541 println!("-------------------------------");
2542}
2543
2544fn des_encrypt_array_ctr_into_vec()
2545{
2546 println!("des_encrypt_array_ctr_into_vec()");
2547 use std::io::Write;
2548 use std::fmt::Write as _;
2549 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
2550
2551 // Normal case
2552 let key = 0x_1234567890ABCDEF_u64;
2553 println!("K =\t{:#016X}", key);
2554 let mut a_des = DES::new_with_key_u64(key);
2555
2556 let mes = "In the beginning God created the heavens and the earth.";
2557 println!("M =\t{}", mes);
2558 let mut message = [0_u8; 55];
2559 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2560 let nonce = 0x_FEDCBA0987654321_u64;
2561 println!("Nonce = {}", nonce);
2562 let mut cipher = Vec::<u8>::new();
2563 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2564 print!("C (16 rounds) =\t");
2565 for c in cipher.clone()
2566 { print!("{:02X} ", c); }
2567 println!();
2568 let mut txt = String::new();
2569 for c in cipher.clone()
2570 { write!(txt, "{:02X} ", c); }
2571 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
2572 println!();
2573
2574 // Expanded case for 128 rounds
2575 let key = 0x_1234567890ABCDEF_u64;
2576 println!("K =\t{:#016X}", key);
2577 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2578
2579 let mes = "In the beginning God created the heavens and the earth.";
2580 println!("M =\t{}", mes);
2581 let mut message = [0_u8; 55];
2582 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2583 let nonce = 0x_FEDCBA0987654321_u64;
2584 println!("Nonce = {}", nonce);
2585 let mut cipher = Vec::<u8>::new();
2586 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2587 print!("C (128 rounds) =\t");
2588 for c in cipher.clone()
2589 { print!("{:02X} ", c); }
2590 println!();
2591 let mut txt = String::new();
2592 for c in cipher.clone()
2593 { write!(txt, "{:02X} ", c); }
2594 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
2595 println!();
2596
2597 // Expanded case for 0 rounds which means that key is meaningless
2598 let key1 = 0x_1234567890ABCDEF_u64;
2599 let key2 = 0_u64;
2600 println!("K1 =\t{:#016X}", key1);
2601 println!("K2 =\t{:#016X}", key2);
2602 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2603 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2604
2605 let mes = "In the beginning God created the heavens and the earth.";
2606 println!("M =\t{}", mes);
2607 let mut message = [0_u8; 55];
2608 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2609
2610 let nonce = 0x_FEDCBA0987654321_u64;
2611 println!("Nonce = {}", nonce);
2612 let mut cipher1 = Vec::<u8>::new();
2613 let mut cipher2 = Vec::<u8>::new();
2614 c_des.encrypt_array_into_vec(nonce, &message, &mut cipher1);
2615 d_des.encrypt_array_into_vec(nonce, &message, &mut cipher2);
2616 print!("C (0 rounds) =\t");
2617 for c in cipher1.clone()
2618 { print!("{:02X} ", c); }
2619 println!();
2620 let mut txt = String::new();
2621 for c in cipher1.clone()
2622 { write!(txt, "{:02X} ", c); }
2623 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2624 print!("D (0 rounds) =\t");
2625 for c in cipher2.clone()
2626 { print!("{:02X} ", c); }
2627 println!();
2628 let mut txt = String::new();
2629 for c in cipher2.clone()
2630 { write!(txt, "{:02X} ", c); }
2631 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2632 println!();
2633
2634 // Normal case for the message of 0 bytes
2635 let key = 0x_1234567890ABCDEF_u64;
2636 println!("K =\t{:#016X}", key);
2637 let mut a_des = DES::new_with_key_u64(key);
2638
2639 let mes = "";
2640 println!("M =\t{}", mes);
2641 let mut message = [0_u8; 0];
2642 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2643 let nonce = 0x_FEDCBA0987654321_u64;
2644 println!("Nonce = {}", nonce);
2645 let mut cipher = Vec::<u8>::new();
2646 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2647 print!("C =\t");
2648 for c in cipher.clone()
2649 { print!("{:02X} ", c); }
2650 println!();
2651 let mut txt = String::new();
2652 for c in cipher.clone()
2653 { write!(txt, "{:02X} ", c); }
2654 assert_eq!(txt, "");
2655 println!();
2656
2657 // Normal case for the message shorter than 8 bytes
2658 let key = 0x_1234567890ABCDEF_u64;
2659 println!("K =\t{:#016X}", key);
2660 let mut a_des = DES::new_with_key_u64(key);
2661
2662 let mes = "7 bytes";
2663 println!("M =\t{}", mes);
2664 let mut message = [0_u8; 7];
2665 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2666 let nonce = 0x_FEDCBA0987654321_u64;
2667 println!("Nonce = {}", nonce);
2668 let mut cipher = Vec::<u8>::new();
2669 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2670 print!("C =\t");
2671 for c in cipher.clone()
2672 { print!("{:02X} ", c); }
2673 println!();
2674 let mut txt = String::new();
2675 for c in cipher.clone()
2676 { write!(txt, "{:02X} ", c); }
2677 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
2678 println!();
2679
2680 // Normal case for the message of 8 bytes
2681 let key = 0x_1234567890ABCDEF_u64;
2682 println!("K =\t{:#016X}", key);
2683 let mut a_des = DES::new_with_key_u64(key);
2684
2685 let mes = "I am OK.";
2686 println!("M =\t{}", mes);
2687 let mut message = [0_u8; 8];
2688 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2689 let nonce = 0x_FEDCBA0987654321_u64;
2690 println!("Nonce = {}", nonce);
2691 let mut cipher = Vec::<u8>::new();
2692 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2693 print!("C =\t");
2694 for c in cipher.clone()
2695 { print!("{:02X} ", c); }
2696 println!();
2697 let mut txt = String::new();
2698 for c in cipher.clone()
2699 { write!(txt, "{:02X} ", c); }
2700 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
2701 println!();
2702
2703 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2704 let key = 0x_1234567890ABCDEF_u64;
2705 println!("K =\t{:#016X}", key);
2706 let mut a_des = DES::new_with_key_u64(key);
2707
2708 let mes = "PARK Youngho";
2709 println!("M =\t{}", mes);
2710 let mut message = [0_u8; 12];
2711 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2712 let nonce = 0x_FEDCBA0987654321_u64;
2713 println!("Nonce = {}", nonce);
2714 let mut cipher = Vec::<u8>::new();
2715 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2716 print!("C =\t");
2717 for c in cipher.clone()
2718 { print!("{:02X} ", c); }
2719 println!();
2720 let mut txt = String::new();
2721 for c in cipher.clone()
2722 { write!(txt, "{:02X} ", c); }
2723 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
2724 println!();
2725
2726 // Normal case for the message of 16 bytes
2727 let key = 0x_1234567890ABCDEF_u64;
2728 println!("K =\t{:#016X}", key);
2729 let mut a_des = DES::new_with_key_u64(key);
2730
2731 let mes = "고맙습니다.";
2732 println!("M =\t{}", mes);
2733 let mut message = [0_u8; 16];
2734 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2735 let nonce = 0x_FEDCBA0987654321_u64;
2736 println!("Nonce = {}", nonce);
2737 let mut cipher = Vec::<u8>::new();
2738 a_des.encrypt_array_into_vec(nonce, &message, &mut cipher);
2739 print!("C =\t");
2740 for c in cipher.clone()
2741 { print!("{:02X} ", c); }
2742 println!();
2743 let mut txt = String::new();
2744 for c in cipher.clone()
2745 { write!(txt, "{:02X} ", c); }
2746 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
2747 println!("-------------------------------");
2748}
2749
2750fn des_encrypt_array_ctr_into_array()
2751{
2752 println!("des_encrypt_array_ctr_into_array()");
2753 use std::io::Write;
2754 use std::fmt::Write as _;
2755 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
2756
2757 // Normal case
2758 let key = 0x_1234567890ABCDEF_u64;
2759 println!("K =\t{:#016X}", key);
2760 let mut a_des = DES::new_with_key_u64(key);
2761
2762 let mes = "In the beginning God created the heavens and the earth.";
2763 println!("M =\t{}", mes);
2764 let mut message = [0_u8; 55];
2765 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2766 let nonce = 0x_FEDCBA0987654321_u64;
2767 println!("Nonce = {}", nonce);
2768 let mut cipher = [0_u8; 55];
2769 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2770 for c in cipher.clone()
2771 { print!("{:02X} ", c); }
2772 println!();
2773 let mut txt = String::new();
2774 for c in cipher.clone()
2775 { write!(txt, "{:02X} ", c); }
2776 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
2777 println!();
2778
2779 // Expanded case for 128 rounds
2780 let key = 0x_1234567890ABCDEF_u64;
2781 println!("K =\t{:#016X}", key);
2782 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2783
2784 let mes = "In the beginning God created the heavens and the earth.";
2785 println!("M =\t{}", mes);
2786 let mut message = [0_u8; 55];
2787 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2788 let nonce = 0x_FEDCBA0987654321_u64;
2789 println!("Nonce = {}", nonce);
2790 let mut cipher = [0_u8; 55];
2791 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2792 print!("C (128 rounds) =\t");
2793 for c in cipher.clone()
2794 { print!("{:02X} ", c); }
2795 println!();
2796 let mut txt = String::new();
2797 for c in cipher.clone()
2798 { write!(txt, "{:02X} ", c); }
2799 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
2800 println!();
2801
2802 // Expanded case for 0 rounds which means that key is meaningless
2803 let key1 = 0x_1234567890ABCDEF_u64;
2804 let key2 = 0_u64;
2805 println!("K1 =\t{:#016X}", key1);
2806 println!("K2 =\t{:#016X}", key2);
2807 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2808 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2809
2810 let mes = "In the beginning God created the heavens and the earth.";
2811 println!("M =\t{}", mes);
2812 let mut message = [0_u8; 55];
2813 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2814 let nonce = 0x_FEDCBA0987654321_u64;
2815 println!("Nonce = {}", nonce);
2816 let mut cipher1 = [0_u8; 55];
2817 let mut cipher2 = [0_u8; 55];
2818 c_des.encrypt_array_into_array(nonce, &message, &mut cipher1);
2819 d_des.encrypt_array_into_array(nonce, &message, &mut cipher2);
2820 print!("C (0 rounds) =\t");
2821 for c in cipher1.clone()
2822 { print!("{:02X} ", c); }
2823 println!();
2824 let mut txt = String::new();
2825 for c in cipher1.clone()
2826 { write!(txt, "{:02X} ", c); }
2827 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2828 print!("D (0 rounds) =\t");
2829 for c in cipher2.clone()
2830 { print!("{:02X} ", c); }
2831 println!();
2832 let mut txt = String::new();
2833 for c in cipher2.clone()
2834 { write!(txt, "{:02X} ", c); }
2835 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
2836 println!();
2837
2838 // Normal case for the message of 0 bytes
2839 let key = 0x_1234567890ABCDEF_u64;
2840 println!("K =\t{:#016X}", key);
2841 let mut a_des = DES::new_with_key_u64(key);
2842
2843 let mes = "";
2844 println!("M =\t{}", mes);
2845 let mut message = [0_u8; 0];
2846 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2847 let nonce = 0x_FEDCBA0987654321_u64;
2848 println!("Nonce = {}", nonce);
2849 let mut cipher = [0_u8; 0];
2850 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2851 print!("C =\t");
2852 for c in cipher.clone()
2853 { print!("{:02X} ", c); }
2854 println!();
2855 let mut txt = String::new();
2856 for c in cipher.clone()
2857 { write!(txt, "{:02X} ", c); }
2858 assert_eq!(txt, "");
2859 println!();
2860
2861 // Normal case for the message shorter than 8 bytes
2862 let key = 0x_1234567890ABCDEF_u64;
2863 println!("K =\t{:#016X}", key);
2864 let mut a_des = DES::new_with_key_u64(key);
2865
2866 let mes = "7 bytes";
2867 println!("M =\t{}", mes);
2868 let mut message = [0_u8; 7];
2869 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2870 let nonce = 0x_FEDCBA0987654321_u64;
2871 println!("Nonce = {}", nonce);
2872 let mut cipher = [0_u8; 7];
2873 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2874 print!("C =\t");
2875 for c in cipher.clone()
2876 { print!("{:02X} ", c); }
2877 println!();
2878 let mut txt = String::new();
2879 for c in cipher.clone()
2880 { write!(txt, "{:02X} ", c); }
2881 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
2882 println!();
2883
2884 // Normal case for the message of 8 bytes
2885 let key = 0x_1234567890ABCDEF_u64;
2886 println!("K =\t{:#016X}", key);
2887 let mut a_des = DES::new_with_key_u64(key);
2888
2889 let mes = "I am OK.";
2890 println!("M =\t{}", mes);
2891 let mut message = [0_u8; 8];
2892 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2893 let nonce = 0x_FEDCBA0987654321_u64;
2894 println!("Nonce = {}", nonce);
2895 let mut cipher = [0_u8; 8];
2896 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2897 print!("C =\t");
2898 for c in cipher.clone()
2899 { print!("{:02X} ", c); }
2900 println!();
2901 let mut txt = String::new();
2902 for c in cipher.clone()
2903 { write!(txt, "{:02X} ", c); }
2904 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
2905 println!();
2906
2907 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
2908 let key = 0x_1234567890ABCDEF_u64;
2909 println!("K =\t{:#016X}", key);
2910 let mut a_des = DES::new_with_key_u64(key);
2911
2912 let mes = "PARK Youngho";
2913 println!("M =\t{}", mes);
2914 let mut message = [0_u8; 12];
2915 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2916 let nonce = 0x_FEDCBA0987654321_u64;
2917 println!("Nonce = {}", nonce);
2918 let mut cipher = [0_u8; 12];
2919 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2920 print!("C =\t");
2921 for c in cipher.clone()
2922 { print!("{:02X} ", c); }
2923 println!();
2924 let mut txt = String::new();
2925 for c in cipher.clone()
2926 { write!(txt, "{:02X} ", c); }
2927 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
2928 println!();
2929
2930 // Normal case for the message of 16 bytes
2931 let key = 0x_1234567890ABCDEF_u64;
2932 println!("K =\t{:#016X}", key);
2933 let mut a_des = DES::new_with_key_u64(key);
2934
2935 let mes = "고맙습니다.";
2936 println!("M =\t{}", mes);
2937 let mut message = [0_u8; 16];
2938 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
2939 let nonce = 0x_FEDCBA0987654321_u64;
2940 println!("Nonce = {}", nonce);
2941 let mut cipher = [0_u8; 16];
2942 a_des.encrypt_array_into_array(nonce, &message, &mut cipher);
2943 print!("C =\t");
2944 for c in cipher.clone()
2945 { print!("{:02X} ", c); }
2946 println!();
2947 let mut txt = String::new();
2948 for c in cipher.clone()
2949 { write!(txt, "{:02X} ", c); }
2950 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
2951 println!("-------------------------------");
2952}
2953
2954fn des_decrypt_ctr()
2955{
2956 println!("des_decrypt_ctr()");
2957 use std::io::Write;
2958 use std::fmt::Write as _;
2959 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
2960
2961 // Normal case
2962 let key = 0x_1234567890ABCDEF_u64;
2963 println!("K =\t{:#016X}", key);
2964 let mut a_des = DES::new_with_key_u64(key);
2965
2966 let message = "In the beginning God created the heavens and the earth.";
2967 println!("M =\t{}", message);
2968 let nonce = 0x_FEDCBA0987654321_u64;
2969 println!("Nonce = {}", nonce);
2970 let mut cipher = Vec::<u8>::new();
2971 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
2972 print!("C (16 rounds) =\t");
2973 for c in cipher.clone()
2974 { print!("{:02X} ", c); }
2975 println!();
2976 let mut txt = String::new();
2977 for c in cipher.clone()
2978 { write!(txt, "{:02X} ", c); }
2979 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
2980
2981 let mut recovered = vec![0; 55];
2982 a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
2983 print!("Ba (16 rounds) =\t");
2984 for b in recovered.clone()
2985 { print!("{:02X} ", b); }
2986 println!();
2987 let mut txt = String::new();
2988 for c in recovered.clone()
2989 { write!(txt, "{:02X} ", c); }
2990 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
2991
2992 let mut converted = String::new();
2993 unsafe { converted.as_mut_vec() }.append(&mut recovered);
2994
2995 println!("Bb (16 rounds) =\t{}", converted);
2996 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
2997 assert_eq!(converted, message);
2998 println!();
2999
3000 // Expanded case for 128 rounds
3001 let key = 0x_1234567890ABCDEF_u64;
3002 println!("K =\t{:#016X}", key);
3003 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3004
3005 let message = "In the beginning God created the heavens and the earth.";
3006 println!("M =\t{}", message);
3007 let nonce = 0x_FEDCBA0987654321_u64;
3008 println!("Nonce = {}", nonce);
3009 let mut cipher = Vec::<u8>::new();
3010 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3011 print!("C (128 rounds) =\t");
3012 for c in cipher.clone()
3013 { print!("{:02X} ", c); }
3014 println!();
3015 let mut txt = String::new();
3016 for c in cipher.clone()
3017 { write!(txt, "{:02X} ", c); }
3018 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
3019
3020 let mut recovered = vec![0; 55];
3021 a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3022 print!("Ba (128 rounds) =\t");
3023 for b in recovered.clone()
3024 { print!("{:02X} ", b); }
3025 println!();
3026 let mut txt = String::new();
3027 for c in recovered.clone()
3028 { write!(txt, "{:02X} ", c); }
3029 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3030
3031 let mut converted = String::new();
3032 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3033
3034 println!("Bb (128 rounds) =\t{}", converted);
3035 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3036 assert_eq!(converted, message);
3037 println!();
3038
3039 // Expanded case for 0 rounds which means that key is meaningless
3040 let key1 = 0x_1234567890ABCDEF_u64;
3041 let key2 = 0_u64;
3042 println!("K =\t{:#016X}", key);
3043 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3044 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3045
3046 let message = "In the beginning God created the heavens and the earth.";
3047 println!("M =\t{}", message);
3048 let nonce = 0x_FEDCBA0987654321_u64;
3049 println!("Nonce = {}", nonce);
3050 let mut cipher1 = Vec::<u8>::new();
3051 let mut cipher2 = Vec::<u8>::new();
3052 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
3053 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
3054 print!("C (0 rounds) =\t");
3055 for c in cipher1.clone()
3056 { print!("{:02X} ", c); }
3057 println!();
3058 let mut txt = String::new();
3059 for c in cipher1.clone()
3060 { write!(txt, "{:02X} ", c); }
3061 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
3062 print!("D (0 rounds) =\t");
3063 for c in cipher2.clone()
3064 { print!("{:02X} ", c); }
3065 println!();
3066 let mut txt = String::new();
3067 for c in cipher2.clone()
3068 { write!(txt, "{:02X} ", c); }
3069 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
3070
3071 let mut recovered1 = vec![0; 55];
3072 let mut recovered2 = vec![0; 55];
3073 c_des.decrypt(nonce, cipher1.as_ptr(), cipher1.len() as u64, recovered1.as_mut_ptr());
3074 d_des.decrypt(nonce, cipher2.as_ptr(), cipher2.len() as u64, recovered2.as_mut_ptr());
3075 print!("B1a (0 rounds) =\t");
3076 for b in recovered1.clone()
3077 { print!("{:02X} ", b); }
3078 println!();
3079 let mut txt = String::new();
3080 for c in recovered1.clone()
3081 { write!(txt, "{:02X} ", c); }
3082 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3083 print!("B2a (0 rounds) =\t");
3084 for b in recovered2.clone()
3085 { print!("{:02X} ", b); }
3086 println!();
3087 let mut txt = String::new();
3088 for c in recovered2.clone()
3089 { write!(txt, "{:02X} ", c); }
3090 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3091
3092 let mut converted1 = String::new();
3093 let mut converted2 = String::new();
3094 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3095 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3096
3097 println!("B1b (0 rounds) =\t{}", converted1);
3098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3099 assert_eq!(converted1, message);
3100 println!("B2b (0 rounds) =\t{}", converted2);
3101 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3102 assert_eq!(converted2, message);
3103 assert_eq!(converted1, converted1);
3104 println!();
3105
3106 // Normal case for the message of 0 bytes
3107 let key = 0x_1234567890ABCDEF_u64;
3108 println!("K =\t{:#016X}", key);
3109 let mut a_des = DES::new_with_key_u64(key);
3110
3111 let message = "";
3112 println!("M =\t{}", message);
3113 let nonce = 0x_FEDCBA0987654321_u64;
3114 println!("Nonce = {}", nonce);
3115 let mut cipher = Vec::<u8>::new();
3116 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3117 print!("C =\t");
3118 for c in cipher.clone()
3119 { print!("{:02X} ", c); }
3120 println!();
3121 let mut txt = String::new();
3122 for c in cipher.clone()
3123 { write!(txt, "{:02X} ", c); }
3124 assert_eq!(txt, "");
3125
3126 let mut recovered = vec![0; 8];
3127 let len = a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3128 print!("Ba =\t");
3129 for b in recovered.clone()
3130 { print!("{:02X} ", b); }
3131 println!();
3132 let mut txt = String::new();
3133 for c in recovered.clone()
3134 { write!(txt, "{:02X} ", c); }
3135 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3136
3137 let mut converted = String::new();
3138 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3139 converted.truncate(len as usize);
3140
3141 println!("Bb =\t{}", converted);
3142 assert_eq!(converted, "");
3143 assert_eq!(converted, message);
3144 println!();
3145
3146 // Normal case for the message shorter than 8 bytes
3147 let key = 0x_1234567890ABCDEF_u64;
3148 println!("K =\t{:#016X}", key);
3149 let mut a_des = DES::new_with_key_u64(key);
3150
3151 let message = "7 bytes";
3152 println!("M =\t{}", message);
3153 let nonce = 0x_FEDCBA0987654321_u64;
3154 println!("Nonce = {}", nonce);
3155 let mut cipher = Vec::<u8>::new();
3156 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3157 print!("C =\t");
3158 for c in cipher.clone()
3159 { print!("{:02X} ", c); }
3160 println!();
3161 let mut txt = String::new();
3162 for c in cipher.clone()
3163 { write!(txt, "{:02X} ", c); }
3164 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
3165
3166 let mut recovered = vec![0; 8];
3167 let len = a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3168 print!("Ba =\t");
3169 for b in recovered.clone()
3170 { print!("{:02X} ", b); }
3171 println!();
3172 let mut txt = String::new();
3173 for c in recovered.clone()
3174 { write!(txt, "{:02X} ", c); }
3175 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3176
3177 let mut converted = String::new();
3178 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3179 converted.truncate(len as usize);
3180
3181 println!("Bb =\t{}", converted);
3182 assert_eq!(converted, "7 bytes");
3183 assert_eq!(converted, message);
3184 println!();
3185
3186 // Normal case for the message of 8 bytes
3187 let key = 0x_1234567890ABCDEF_u64;
3188 println!("K =\t{:#016X}", key);
3189 let mut a_des = DES::new_with_key_u64(key);
3190
3191 let message = "I am OK.";
3192 println!("M =\t{}", message);
3193 let nonce = 0x_FEDCBA0987654321_u64;
3194 println!("Nonce = {}", nonce);
3195 let mut cipher = Vec::<u8>::new();
3196 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3197 print!("C =\t");
3198 for c in cipher.clone()
3199 { print!("{:02X} ", c); }
3200 println!();
3201 let mut txt = String::new();
3202 for c in cipher.clone()
3203 { write!(txt, "{:02X} ", c); }
3204 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
3205
3206 let mut recovered = vec![0; 16];
3207 let len = a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3208 print!("Ba =\t");
3209 for b in recovered.clone()
3210 { print!("{:02X} ", b); }
3211 println!();
3212 let mut txt = String::new();
3213 for c in recovered.clone()
3214 { write!(txt, "{:02X} ", c); }
3215 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3216
3217 let mut converted = String::new();
3218 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3219 converted.truncate(len as usize);
3220
3221 println!("Bb =\t{}", converted);
3222 assert_eq!(converted, "I am OK.");
3223 assert_eq!(converted, message);
3224 println!();
3225
3226 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3227 let key = 0x_1234567890ABCDEF_u64;
3228 println!("K =\t{:#016X}", key);
3229 let mut a_des = DES::new_with_key_u64(key);
3230
3231 let message = "PARK Youngho";
3232 println!("M =\t{}", message);
3233 let nonce = 0x_FEDCBA0987654321_u64;
3234 println!("Nonce = {}", nonce);
3235 let mut cipher = Vec::<u8>::new();
3236 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3237 print!("C =\t");
3238 for c in cipher.clone()
3239 { print!("{:02X} ", c); }
3240 println!();
3241 let mut txt = String::new();
3242 for c in cipher.clone()
3243 { write!(txt, "{:02X} ", c); }
3244 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
3245
3246 let mut recovered = vec![0; 16];
3247 let len = a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3248 print!("Ba =\t");
3249 for b in recovered.clone()
3250 { print!("{:02X} ", b); }
3251 println!();
3252 let mut txt = String::new();
3253 for c in recovered.clone()
3254 { write!(txt, "{:02X} ", c); }
3255 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3256
3257 let mut converted = String::new();
3258 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3259 converted.truncate(len as usize);
3260
3261 println!("Bb =\t{}", converted);
3262 assert_eq!(converted, "PARK Youngho");
3263 assert_eq!(converted, message);
3264 println!();
3265
3266 // Normal case for the message of 16 bytes
3267 let key = 0x_1234567890ABCDEF_u64;
3268 println!("K =\t{:#016X}", key);
3269 let mut a_des = DES::new_with_key_u64(key);
3270
3271 let message = "고맙습니다.";
3272 println!("M =\t{}", message);
3273 let nonce = 0x_FEDCBA0987654321_u64;
3274 println!("Nonce = {}", nonce);
3275 let mut cipher = Vec::<u8>::new();
3276 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3277 print!("C =\t");
3278 for c in cipher.clone()
3279 { print!("{:02X} ", c); }
3280 println!();
3281 let mut txt = String::new();
3282 for c in cipher.clone()
3283 { write!(txt, "{:02X} ", c); }
3284 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
3285
3286 let mut recovered = vec![0; 24];
3287 let len = a_des.decrypt(nonce, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
3288 print!("Ba =\t");
3289 for b in recovered.clone()
3290 { print!("{:02X} ", b); }
3291 println!();
3292 let mut txt = String::new();
3293 for c in recovered.clone()
3294 { write!(txt, "{:02X} ", c); }
3295 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3296
3297 let mut converted = String::new();
3298 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3299 converted.truncate(len as usize);
3300
3301 println!("Bb =\t{}", converted);
3302 assert_eq!(converted, "고맙습니다.");
3303 assert_eq!(converted, message);
3304 println!("-------------------------------");
3305}
3306
3307fn des_decrypt_ctr_into_vec()
3308{
3309 println!("des_decrypt_ctr_into_vec()");
3310 use std::io::Write;
3311 use std::fmt::Write as _;
3312 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
3313
3314 // Normal case
3315 let key = 0x_1234567890ABCDEF_u64;
3316 println!("K =\t{:#016X}", key);
3317 let mut a_des = DES::new_with_key_u64(key);
3318
3319 let message = "In the beginning God created the heavens and the earth.";
3320 println!("M =\t{}", message);
3321 let nonce = 0x_FEDCBA0987654321_u64;
3322 println!("Nonce = {}", nonce);
3323 let mut cipher = Vec::<u8>::new();
3324 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3325 print!("C (16 rounds) =\t");
3326 for c in cipher.clone()
3327 { print!("{:02X} ", c); }
3328 println!();
3329 let mut txt = String::new();
3330 for c in cipher.clone()
3331 { write!(txt, "{:02X} ", c); }
3332 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
3333
3334 let mut recovered = Vec::<u8>::new();
3335 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3336 print!("Ba (16 rounds) =\t");
3337 for b in recovered.clone()
3338 { print!("{:02X} ", b); }
3339 println!();
3340 let mut txt = String::new();
3341 for c in recovered.clone()
3342 { write!(txt, "{:02X} ", c); }
3343 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3344
3345 let mut converted = String::new();
3346 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3347
3348 println!("Bb (16 rounds) =\t{}", converted);
3349 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3350 assert_eq!(converted, message);
3351 println!();
3352
3353 // Expanded case for 128 rounds
3354 let key = 0x_1234567890ABCDEF_u64;
3355 println!("K =\t{:#016X}", key);
3356 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3357
3358 let message = "In the beginning God created the heavens and the earth.";
3359 println!("M =\t{}", message);
3360 let nonce = 0x_FEDCBA0987654321_u64;
3361 println!("Nonce = {}", nonce);
3362 let mut cipher = Vec::<u8>::new();
3363 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3364 print!("C (128 rounds) =\t");
3365 for c in cipher.clone()
3366 { print!("{:02X} ", c); }
3367 println!();
3368 let mut txt = String::new();
3369 for c in cipher.clone()
3370 { write!(txt, "{:02X} ", c); }
3371 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
3372
3373 let mut recovered = Vec::<u8>::new();
3374 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3375 print!("Ba (128 rounds) =\t");
3376 for b in recovered.clone()
3377 { print!("{:02X} ", b); }
3378 println!();
3379 let mut txt = String::new();
3380 for c in recovered.clone()
3381 { write!(txt, "{:02X} ", c); }
3382 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3383
3384 let mut converted = String::new();
3385 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3386
3387 println!("Bb (128 rounds) =\t{}", converted);
3388 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3389 assert_eq!(converted, message);
3390 println!();
3391
3392 // Expanded case for 0 rounds which means that key is meaningless
3393 let key1 = 0x_1234567890ABCDEF_u64;
3394 let key2 = 0_u64;
3395 println!("K =\t{:#016X}", key);
3396 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3397 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3398
3399 let message = "In the beginning God created the heavens and the earth.";
3400 println!("M =\t{}", message);
3401 let nonce = 0x_FEDCBA0987654321_u64;
3402 println!("Nonce = {}", nonce);
3403 let mut cipher1 = Vec::<u8>::new();
3404 let mut cipher2 = Vec::<u8>::new();
3405 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
3406 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
3407 print!("C (0 rounds) =\t");
3408 for c in cipher1.clone()
3409 { print!("{:02X} ", c); }
3410 println!();
3411 let mut txt = String::new();
3412 for c in cipher1.clone()
3413 { write!(txt, "{:02X} ", c); }
3414 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
3415 print!("D (0 rounds) =\t");
3416 for c in cipher2.clone()
3417 { print!("{:02X} ", c); }
3418 println!();
3419 let mut txt = String::new();
3420 for c in cipher2.clone()
3421 { write!(txt, "{:02X} ", c); }
3422 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
3423
3424 let mut recovered1 = Vec::<u8>::new();
3425 let mut recovered2 = Vec::<u8>::new();
3426 c_des.decrypt_into_vec(nonce, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3427 d_des.decrypt_into_vec(nonce, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3428 print!("B1a (0 rounds) =\t");
3429 for b in recovered1.clone()
3430 { print!("{:02X} ", b); }
3431 println!();
3432 let mut txt = String::new();
3433 for c in recovered1.clone()
3434 { write!(txt, "{:02X} ", c); }
3435 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3436 print!("B2a (0 rounds) =\t");
3437 for b in recovered2.clone()
3438 { print!("{:02X} ", b); }
3439 println!();
3440 let mut txt = String::new();
3441 for c in recovered2.clone()
3442 { write!(txt, "{:02X} ", c); }
3443 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
3444
3445 let mut converted1 = String::new();
3446 let mut converted2 = String::new();
3447 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
3448 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
3449
3450 println!("B1b (0 rounds) =\t{}", converted1);
3451 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3452 assert_eq!(converted1, message);
3453 println!("B2b (0 rounds) =\t{}", converted2);
3454 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3455 assert_eq!(converted2, message);
3456 assert_eq!(converted1, converted1);
3457 println!();
3458
3459 // Normal case for the message of 0 bytes
3460 let key = 0x_1234567890ABCDEF_u64;
3461 println!("K =\t{:#016X}", key);
3462 let mut a_des = DES::new_with_key_u64(key);
3463
3464 let message = "";
3465 println!("M =\t{}", message);
3466 let nonce = 0x_FEDCBA0987654321_u64;
3467 println!("Nonce = {}", nonce);
3468 let mut cipher = Vec::<u8>::new();
3469 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3470 print!("C =\t");
3471 for c in cipher.clone()
3472 { print!("{:02X} ", c); }
3473 println!();
3474 let mut txt = String::new();
3475 for c in cipher.clone()
3476 { write!(txt, "{:02X} ", c); }
3477 assert_eq!(txt, "");
3478
3479 let mut recovered = Vec::<u8>::new();
3480 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3481 print!("Ba =\t");
3482 for b in recovered.clone()
3483 { print!("{:02X} ", b); }
3484 println!();
3485 let mut txt = String::new();
3486 for c in recovered.clone()
3487 { write!(txt, "{:02X} ", c); }
3488 assert_eq!(txt, "");
3489
3490 let mut converted = String::new();
3491 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3492
3493 println!("Bb =\t{}", converted);
3494 assert_eq!(converted, "");
3495 assert_eq!(converted, message);
3496 println!();
3497
3498 // Normal case for the message shorter than 8 bytes
3499 let key = 0x_1234567890ABCDEF_u64;
3500 println!("K =\t{:#016X}", key);
3501 let mut a_des = DES::new_with_key_u64(key);
3502
3503 let message = "7 bytes";
3504 println!("M =\t{}", message);
3505 let nonce = 0x_FEDCBA0987654321_u64;
3506 println!("Nonce = {}", nonce);
3507 let mut cipher = Vec::<u8>::new();
3508 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3509 print!("C =\t");
3510 for c in cipher.clone()
3511 { print!("{:02X} ", c); }
3512 println!();
3513 let mut txt = String::new();
3514 for c in cipher.clone()
3515 { write!(txt, "{:02X} ", c); }
3516 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
3517
3518 let mut recovered = Vec::<u8>::new();
3519 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3520 print!("Ba =\t");
3521 for b in recovered.clone()
3522 { print!("{:02X} ", b); }
3523 println!();
3524 let mut txt = String::new();
3525 for c in recovered.clone()
3526 { write!(txt, "{:02X} ", c); }
3527 assert_eq!(txt, "37 20 62 79 74 65 73 ");
3528
3529 let mut converted = String::new();
3530 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3531
3532 println!("Bb =\t{}", converted);
3533 assert_eq!(converted, "7 bytes");
3534 assert_eq!(converted, message);
3535 println!();
3536
3537 // Normal case for the message of 8 bytes
3538 let key = 0x_1234567890ABCDEF_u64;
3539 println!("K =\t{:#016X}", key);
3540 let mut a_des = DES::new_with_key_u64(key);
3541
3542 let message = "I am OK.";
3543 println!("M =\t{}", message);
3544 let nonce = 0x_FEDCBA0987654321_u64;
3545 println!("Nonce = {}", nonce);
3546 let mut cipher = Vec::<u8>::new();
3547 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3548 print!("C =\t");
3549 for c in cipher.clone()
3550 { print!("{:02X} ", c); }
3551 println!();
3552 let mut txt = String::new();
3553 for c in cipher.clone()
3554 { write!(txt, "{:02X} ", c); }
3555 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
3556
3557 let mut recovered = Vec::<u8>::new();
3558 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3559 print!("Ba =\t");
3560 for b in recovered.clone()
3561 { print!("{:02X} ", b); }
3562 println!();
3563 let mut txt = String::new();
3564 for c in recovered.clone()
3565 { write!(txt, "{:02X} ", c); }
3566 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
3567
3568 let mut converted = String::new();
3569 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3570
3571 println!("Bb =\t{}", converted);
3572 assert_eq!(converted, "I am OK.");
3573 assert_eq!(converted, message);
3574 println!();
3575
3576 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3577 let key = 0x_1234567890ABCDEF_u64;
3578 println!("K =\t{:#016X}", key);
3579 let mut a_des = DES::new_with_key_u64(key);
3580
3581 let message = "PARK Youngho";
3582 println!("M =\t{}", message);
3583 let nonce = 0x_FEDCBA0987654321_u64;
3584 println!("Nonce = {}", nonce);
3585 let mut cipher = Vec::<u8>::new();
3586 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3587 print!("C =\t");
3588 for c in cipher.clone()
3589 { print!("{:02X} ", c); }
3590 println!();
3591 let mut txt = String::new();
3592 for c in cipher.clone()
3593 { write!(txt, "{:02X} ", c); }
3594 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
3595
3596 let mut recovered = Vec::<u8>::new();
3597 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3598 print!("Ba =\t");
3599 for b in recovered.clone()
3600 { print!("{:02X} ", b); }
3601 println!();
3602 let mut txt = String::new();
3603 for c in recovered.clone()
3604 { write!(txt, "{:02X} ", c); }
3605 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
3606
3607 let mut converted = String::new();
3608 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3609
3610 println!("Bb =\t{}", converted);
3611 assert_eq!(converted, "PARK Youngho");
3612 assert_eq!(converted, message);
3613 println!();
3614
3615 // Normal case for the message of 16 bytes
3616 let key = 0x_1234567890ABCDEF_u64;
3617 println!("K =\t{:#016X}", key);
3618 let mut a_des = DES::new_with_key_u64(key);
3619
3620 let message = "고맙습니다.";
3621 println!("M =\t{}", message);
3622 let nonce = 0x_FEDCBA0987654321_u64;
3623 println!("Nonce = {}", nonce);
3624 let mut cipher = Vec::<u8>::new();
3625 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3626 print!("C =\t");
3627 for c in cipher.clone()
3628 { print!("{:02X} ", c); }
3629 println!();
3630 let mut txt = String::new();
3631 for c in cipher.clone()
3632 { write!(txt, "{:02X} ", c); }
3633 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
3634
3635 let mut recovered = Vec::<u8>::new();
3636 a_des.decrypt_into_vec(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3637 print!("Ba =\t");
3638 for b in recovered.clone()
3639 { print!("{:02X} ", b); }
3640 println!();
3641 let mut txt = String::new();
3642 for c in recovered.clone()
3643 { write!(txt, "{:02X} ", c); }
3644 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
3645
3646 let mut converted = String::new();
3647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
3648
3649 println!("Bb =\t{}", converted);
3650 assert_eq!(converted, "고맙습니다.");
3651 assert_eq!(converted, message);
3652 println!("-------------------------------");
3653}
3654
3655fn des_decrypt_ctr_into_array()
3656{
3657 println!("des_decrypt_ctr_into_array()");
3658 use std::io::Write;
3659 use std::fmt::Write as _;
3660 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
3661
3662 // Normal case
3663 let key = 0x_1234567890ABCDEF_u64;
3664 println!("K =\t{:#016X}", key);
3665 let mut a_des = DES::new_with_key_u64(key);
3666
3667 let message = "In the beginning God created the heavens and the earth.";
3668 println!("M =\t{}", message);
3669 let nonce = 0x_FEDCBA0987654321_u64;
3670 println!("Nonce = {}", nonce);
3671 let mut cipher = Vec::<u8>::new();
3672 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3673 print!("C (16 rounds) =\t");
3674 for c in cipher.clone()
3675 { print!("{:02X} ", c); }
3676 println!();
3677 let mut txt = String::new();
3678 for c in cipher.clone()
3679 { write!(txt, "{:02X} ", c); }
3680 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
3681
3682 let mut recovered = [0u8; 56];
3683 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3684 print!("Ba (16 rounds) =\t");
3685 for b in recovered.clone()
3686 { print!("{:02X} ", b); }
3687 println!();
3688 let mut txt = String::new();
3689 for c in recovered.clone()
3690 { write!(txt, "{:02X} ", c); }
3691 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3692
3693 let mut converted = String::new();
3694 unsafe { converted.as_mut_vec() }.write(&recovered);
3695 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3696 println!("Bb (16 rounds) =\t{}", converted);
3697 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3698 assert_eq!(converted, message);
3699 println!();
3700
3701 // Expanded case for 128 rounds
3702 let key = 0x_1234567890ABCDEF_u64;
3703 println!("K =\t{:#016X}", key);
3704 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
3705
3706 let message = "In the beginning God created the heavens and the earth.";
3707 println!("M =\t{}", message);
3708 let nonce = 0x_FEDCBA0987654321_u64;
3709 println!("Nonce = {}", nonce);
3710 let mut cipher = Vec::<u8>::new();
3711 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3712 print!("C (128 rounds) =\t");
3713 for c in cipher.clone()
3714 { print!("{:02X} ", c); }
3715 println!();
3716 let mut txt = String::new();
3717 for c in cipher.clone()
3718 { write!(txt, "{:02X} ", c); }
3719 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
3720
3721 let mut recovered = [0u8; 56];
3722 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3723 print!("Ba (16 rounds) =\t");
3724 for b in recovered.clone()
3725 { print!("{:02X} ", b); }
3726 println!();
3727 let mut txt = String::new();
3728 for c in recovered.clone()
3729 { write!(txt, "{:02X} ", c); }
3730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3731
3732 let mut converted = String::new();
3733 unsafe { converted.as_mut_vec() }.write(&recovered);
3734 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3735 println!("Bb (16 rounds) =\t{}", converted);
3736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
3737 assert_eq!(converted, message);
3738 println!();
3739
3740 // Expanded case for 0 rounds which means that key is meaningless
3741 let key1 = 0x_1234567890ABCDEF_u64;
3742 let key2 = 0_u64;
3743 println!("K =\t{:#016X}", key);
3744 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
3745 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
3746
3747 let message = "In the beginning God created the heavens and the earth.";
3748 println!("M =\t{}", message);
3749 let nonce = 0x_FEDCBA0987654321_u64;
3750 println!("Nonce = {}", nonce);
3751 let mut cipher1 = Vec::<u8>::new();
3752 let mut cipher2 = Vec::<u8>::new();
3753 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
3754 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
3755 print!("C (0 rounds) =\t");
3756 for c in cipher1.clone()
3757 { print!("{:02X} ", c); }
3758 println!();
3759 let mut txt = String::new();
3760 for c in cipher1.clone()
3761 { write!(txt, "{:02X} ", c); }
3762 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
3763 print!("D (0 rounds) =\t");
3764 for c in cipher2.clone()
3765 { print!("{:02X} ", c); }
3766 println!();
3767 let mut txt = String::new();
3768 for c in cipher2.clone()
3769 { write!(txt, "{:02X} ", c); }
3770 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
3771
3772 let mut recovered1 = [0u8; 56];
3773 let mut recovered2 = [0u8; 56];
3774 let len1 = c_des.decrypt_into_array(nonce, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
3775 let len2 = d_des.decrypt_into_array(nonce, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
3776 print!("B1a (0 rounds) =\t");
3777 for b in recovered1.clone()
3778 { print!("{:02X} ", b); }
3779 println!();
3780 let mut txt = String::new();
3781 for c in recovered1.clone()
3782 { write!(txt, "{:02X} ", c); }
3783 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3784 print!("B2a (0 rounds) =\t");
3785 for b in recovered2.clone()
3786 { print!("{:02X} ", b); }
3787 println!();
3788 let mut txt = String::new();
3789 for c in recovered.clone()
3790 { write!(txt, "{:02X} ", c); }
3791 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
3792
3793 let mut converted1 = String::new();
3794 let mut converted2 = String::new();
3795 unsafe { converted1.as_mut_vec() }.write(&recovered1);
3796 unsafe { converted2.as_mut_vec() }.write(&recovered2);
3797 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
3798 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
3799 println!("B1b (0 rounds) =\t{}", converted1);
3800 println!("B2b (0 rounds) =\t{}", converted2);
3801 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
3802 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
3803 assert_eq!(converted1, message);
3804 assert_eq!(converted2, message);
3805 assert_eq!(converted1, converted2);
3806 println!();
3807
3808 // Normal case for the message of 0 bytes
3809 let key = 0x_1234567890ABCDEF_u64;
3810 println!("K =\t{:#016X}", key);
3811 let mut a_des = DES::new_with_key_u64(key);
3812
3813 let message = "";
3814 println!("M =\t{}", message);
3815 let nonce = 0x_FEDCBA0987654321_u64;
3816 println!("Nonce = {}", nonce);
3817 let mut cipher = Vec::<u8>::new();
3818 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3819 print!("C =\t");
3820 for c in cipher.clone()
3821 { print!("{:02X} ", c); }
3822 println!();
3823 let mut txt = String::new();
3824 for c in cipher.clone()
3825 { write!(txt, "{:02X} ", c); }
3826 assert_eq!(txt, "");
3827
3828 let mut recovered = [0u8; 8];
3829 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3830
3831 print!("Ba =\t");
3832 for b in recovered.clone()
3833 { print!("{:02X} ", b); }
3834 println!();
3835 let mut txt = String::new();
3836 for c in recovered.clone()
3837 { write!(txt, "{:02X} ", c); }
3838 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
3839
3840 let mut converted = String::new();
3841 unsafe { converted.as_mut_vec() }.write(&recovered);
3842 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3843 println!("Bb =\t{}", converted);
3844 assert_eq!(converted, "");
3845 assert_eq!(converted, message);
3846 println!();
3847
3848 // Normal case for the message shorter than 8 bytes
3849 let key = 0x_1234567890ABCDEF_u64;
3850 println!("K =\t{:#016X}", key);
3851 let mut a_des = DES::new_with_key_u64(key);
3852
3853 let message = "7 bytes";
3854 println!("M =\t{}", message);
3855 let nonce = 0x_FEDCBA0987654321_u64;
3856 println!("Nonce = {}", nonce);
3857 let mut cipher = Vec::<u8>::new();
3858 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3859 print!("C =\t");
3860 for c in cipher.clone()
3861 { print!("{:02X} ", c); }
3862 println!();
3863 let mut txt = String::new();
3864 for c in cipher.clone()
3865 { write!(txt, "{:02X} ", c); }
3866 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
3867
3868 let mut recovered = [0u8; 8];
3869 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3870
3871 print!("Ba =\t");
3872 for b in recovered.clone()
3873 { print!("{:02X} ", b); }
3874 println!();
3875 let mut txt = String::new();
3876 for c in recovered.clone()
3877 { write!(txt, "{:02X} ", c); }
3878 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
3879
3880 let mut converted = String::new();
3881 unsafe { converted.as_mut_vec() }.write(&recovered);
3882 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3883 println!("Bb =\t{}", converted);
3884 assert_eq!(converted, "7 bytes");
3885 assert_eq!(converted, message);
3886 println!();
3887
3888 // Normal case for the message of 8 bytes
3889 let key = 0x_1234567890ABCDEF_u64;
3890 println!("K =\t{:#016X}", key);
3891 let mut a_des = DES::new_with_key_u64(key);
3892
3893 let message = "I am OK.";
3894 println!("M =\t{}", message);
3895 let nonce = 0x_FEDCBA0987654321_u64;
3896 println!("Nonce = {}", nonce);
3897 let mut cipher = Vec::<u8>::new();
3898 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3899 print!("C =\t");
3900 for c in cipher.clone()
3901 { print!("{:02X} ", c); }
3902 println!();
3903 let mut txt = String::new();
3904 for c in cipher.clone()
3905 { write!(txt, "{:02X} ", c); }
3906 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
3907
3908 let mut recovered = [0u8; 16];
3909 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3910
3911 print!("Ba =\t");
3912 for b in recovered.clone()
3913 { print!("{:02X} ", b); }
3914 println!();
3915 let mut txt = String::new();
3916 for c in recovered.clone()
3917 { write!(txt, "{:02X} ", c); }
3918 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
3919
3920 let mut converted = String::new();
3921 unsafe { converted.as_mut_vec() }.write(&recovered);
3922 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3923 println!("Bb =\t{}", converted);
3924 assert_eq!(converted, "I am OK.");
3925 assert_eq!(converted, message);
3926 println!();
3927
3928 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
3929 let key = 0x_1234567890ABCDEF_u64;
3930 println!("K =\t{:#016X}", key);
3931 let mut a_des = DES::new_with_key_u64(key);
3932
3933 let message = "PARK Youngho";
3934 println!("M =\t{}", message);
3935 let nonce = 0x_FEDCBA0987654321_u64;
3936 println!("Nonce = {}", nonce);
3937 let mut cipher = Vec::<u8>::new();
3938 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3939 print!("C =\t");
3940 for c in cipher.clone()
3941 { print!("{:02X} ", c); }
3942 println!();
3943 let mut txt = String::new();
3944 for c in cipher.clone()
3945 { write!(txt, "{:02X} ", c); }
3946 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
3947
3948 let mut recovered = [0u8; 16];
3949 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3950
3951 print!("Ba =\t");
3952 for b in recovered.clone()
3953 { print!("{:02X} ", b); }
3954 println!();
3955 let mut txt = String::new();
3956 for c in recovered.clone()
3957 { write!(txt, "{:02X} ", c); }
3958 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
3959
3960 let mut converted = String::new();
3961 unsafe { converted.as_mut_vec() }.write(&recovered);
3962 unsafe { converted.as_mut_vec() }.truncate(len as usize);
3963 println!("Bb =\t{}", converted);
3964 assert_eq!(converted, "PARK Youngho");
3965 assert_eq!(converted, message);
3966 println!();
3967
3968 // Normal case for the message of 16 bytes
3969 let key = 0x_1234567890ABCDEF_u64;
3970 println!("K =\t{:#016X}", key);
3971 let mut a_des = DES::new_with_key_u64(key);
3972
3973 let message = "고맙습니다.";
3974 println!("M =\t{}", message);
3975 let nonce = 0x_FEDCBA0987654321_u64;
3976 println!("Nonce = {}", nonce);
3977 let mut cipher = Vec::<u8>::new();
3978 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
3979 print!("C =\t");
3980 for c in cipher.clone()
3981 { print!("{:02X} ", c); }
3982 println!();
3983 let mut txt = String::new();
3984 for c in cipher.clone()
3985 { write!(txt, "{:02X} ", c); }
3986 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
3987
3988 let mut recovered = [0u8; 24];
3989 let len = a_des.decrypt_into_array(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
3990
3991 print!("Ba =\t");
3992 for b in recovered.clone()
3993 { print!("{:02X} ", b); }
3994 println!();
3995 let mut txt = String::new();
3996 for c in recovered.clone()
3997 { write!(txt, "{:02X} ", c); }
3998 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
3999
4000 let mut converted = String::new();
4001 unsafe { converted.as_mut_vec() }.write(&recovered);
4002 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4003 println!("Bb =\t{}", converted);
4004 assert_eq!(converted, "고맙습니다.");
4005 assert_eq!(converted, message);
4006 println!("-------------------------------");
4007}
4008
4009fn des_decrypt_ctr_into_string()
4010{
4011 println!("des_decrypt_ctr_into_string()");
4012 use std::io::Write;
4013 use std::fmt::Write as _;
4014 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
4015
4016 // Normal case
4017 let key = 0x_1234567890ABCDEF_u64;
4018 println!("K =\t{:#016X}", key);
4019 let mut a_des = DES::new_with_key_u64(key);
4020
4021 let message = "In the beginning God created the heavens and the earth.";
4022 println!("M =\t{}", message);
4023 let nonce = 0x_FEDCBA0987654321_u64;
4024 println!("Nonce = {}", nonce);
4025 let mut cipher = Vec::<u8>::new();
4026 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4027 print!("C (16 rounds) =\t");
4028 for c in cipher.clone()
4029 { print!("{:02X} ", c); }
4030 println!();
4031 let mut txt = String::new();
4032 for c in cipher.clone()
4033 { write!(txt, "{:02X} ", c); }
4034 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
4035
4036 let mut recovered = String::new();
4037 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4038 println!("B (16 rounds) =\t{}", recovered);
4039 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4040 assert_eq!(recovered, message);
4041 println!();
4042
4043 // Expanded case for 128 rounds
4044 let key = 0x_1234567890ABCDEF_u64;
4045 println!("K =\t{:#016X}", key);
4046 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4047
4048 let message = "In the beginning God created the heavens and the earth.";
4049 println!("M =\t{}", message);
4050 let nonce = 0x_FEDCBA0987654321_u64;
4051 println!("Nonce = {}", nonce);
4052 let mut cipher = Vec::<u8>::new();
4053 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4054 print!("C (128 rounds) =\t");
4055 for c in cipher.clone()
4056 { print!("{:02X} ", c); }
4057 println!();
4058 let mut txt = String::new();
4059 for c in cipher.clone()
4060 { write!(txt, "{:02X} ", c); }
4061 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
4062
4063 let mut recovered = String::new();
4064 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4065 println!("B (128 rounds) =\t{}", recovered);
4066 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
4067 assert_eq!(recovered, message);
4068 println!();
4069
4070 // Expanded case for 0 rounds which means that key is meaningless
4071 let key1 = 0x_1234567890ABCDEF_u64;
4072 let key2 = 0_u64;
4073 println!("K =\t{:#016X}", key);
4074 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4075 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4076
4077 let message = "In the beginning God created the heavens and the earth.";
4078 println!("M =\t{}", message);
4079 let nonce = 0x_FEDCBA0987654321_u64;
4080 println!("Nonce = {}", nonce);
4081 let mut cipher1 = Vec::<u8>::new();
4082 let mut cipher2 = Vec::<u8>::new();
4083 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
4084 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
4085 print!("C (0 rounds) =\t");
4086 for c in cipher1.clone()
4087 { print!("{:02X} ", c); }
4088 println!();
4089 let mut txt = String::new();
4090 for c in cipher1.clone()
4091 { write!(txt, "{:02X} ", c); }
4092 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
4093 print!("D (0 rounds) =\t");
4094 for c in cipher2.clone()
4095 { print!("{:02X} ", c); }
4096 println!();
4097 let mut txt = String::new();
4098 for c in cipher2.clone()
4099 { write!(txt, "{:02X} ", c); }
4100 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
4101
4102 let mut recovered1 = String::new();
4103 let mut recovered2 = String::new();
4104 c_des.decrypt_into_string(nonce, cipher1.as_ptr(), cipher1.len() as u64, &mut recovered1);
4105 d_des.decrypt_into_string(nonce, cipher2.as_ptr(), cipher2.len() as u64, &mut recovered2);
4106 println!("B1 (0 rounds) =\t{}", recovered1);
4107 println!("B2 (0 rounds) =\t{}", recovered2);
4108 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
4109 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
4110 assert_eq!(recovered1, message);
4111 assert_eq!(recovered2, message);
4112 assert_eq!(recovered1, recovered2);
4113 println!();
4114
4115 // Normal case for the message of 0 bytes
4116 let key = 0x_1234567890ABCDEF_u64;
4117 println!("K =\t{:#016X}", key);
4118 let mut a_des = DES::new_with_key_u64(key);
4119
4120 let message = "";
4121 println!("M =\t{}", message);
4122 let nonce = 0x_FEDCBA0987654321_u64;
4123 println!("Nonce = {}", nonce);
4124 let mut cipher = Vec::<u8>::new();
4125 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4126 print!("C =\t");
4127 for c in cipher.clone()
4128 { print!("{:02X} ", c); }
4129 println!();
4130 let mut txt = String::new();
4131 for c in cipher.clone()
4132 { write!(txt, "{:02X} ", c); }
4133 assert_eq!(txt, "");
4134
4135 let mut recovered = String::new();
4136 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4137 println!("B =\t{}", recovered);
4138 assert_eq!(recovered, "");
4139 assert_eq!(recovered, message);
4140 println!();
4141
4142 // Normal case for the message shorter than 8 bytes
4143 let key = 0x_1234567890ABCDEF_u64;
4144 println!("K =\t{:#016X}", key);
4145 let mut a_des = DES::new_with_key_u64(key);
4146
4147 let message = "7 bytes";
4148 println!("M =\t{}", message);
4149 let nonce = 0x_FEDCBA0987654321_u64;
4150 println!("Nonce = {}", nonce);
4151 let mut cipher = Vec::<u8>::new();
4152 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4153 print!("C =\t");
4154 for c in cipher.clone()
4155 { print!("{:02X} ", c); }
4156 println!();
4157 let mut txt = String::new();
4158 for c in cipher.clone()
4159 { write!(txt, "{:02X} ", c); }
4160 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
4161
4162 let mut recovered = String::new();
4163 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4164 println!("B =\t{}", recovered);
4165 assert_eq!(recovered, "7 bytes");
4166 assert_eq!(recovered, message);
4167 println!();
4168
4169 // Normal case for the message of 8 bytes
4170 let key = 0x_1234567890ABCDEF_u64;
4171 println!("K =\t{:#016X}", key);
4172 let mut a_des = DES::new_with_key_u64(key);
4173
4174 let message = "I am OK.";
4175 println!("M =\t{}", message);
4176 let nonce = 0x_FEDCBA0987654321_u64;
4177 println!("Nonce = {}", nonce);
4178 let mut cipher = Vec::<u8>::new();
4179 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4180 print!("C =\t");
4181 for c in cipher.clone()
4182 { print!("{:02X} ", c); }
4183 println!();
4184 let mut txt = String::new();
4185 for c in cipher.clone()
4186 { write!(txt, "{:02X} ", c); }
4187 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
4188
4189 let mut recovered = String::new();
4190 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4191 println!("B =\t{}", recovered);
4192 assert_eq!(recovered, "I am OK.");
4193 assert_eq!(recovered, message);
4194 println!();
4195
4196 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4197 let key = 0x_1234567890ABCDEF_u64;
4198 println!("K =\t{:#016X}", key);
4199 let mut a_des = DES::new_with_key_u64(key);
4200
4201 let message = "PARK Youngho";
4202 println!("M =\t{}", message);
4203 let nonce = 0x_FEDCBA0987654321_u64;
4204 println!("Nonce = {}", nonce);
4205 let mut cipher = Vec::<u8>::new();
4206 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4207 print!("C =\t");
4208 for c in cipher.clone()
4209 { print!("{:02X} ", c); }
4210 println!();
4211 let mut txt = String::new();
4212 for c in cipher.clone()
4213 { write!(txt, "{:02X} ", c); }
4214 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
4215
4216 let mut recovered = String::new();
4217 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4218 println!("B =\t{}", recovered);
4219 assert_eq!(recovered, "PARK Youngho");
4220 assert_eq!(recovered, message);
4221 println!();
4222
4223 // Normal case for the message of 16 bytes
4224 let key = 0x_1234567890ABCDEF_u64;
4225 println!("K =\t{:#016X}", key);
4226 let mut a_des = DES::new_with_key_u64(key);
4227
4228 let message = "고맙습니다.";
4229 println!("M =\t{}", message);
4230 let nonce = 0x_FEDCBA0987654321_u64;
4231 println!("Nonce = {}", nonce);
4232 let mut cipher = Vec::<u8>::new();
4233 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4234 print!("C =\t");
4235 for c in cipher.clone()
4236 { print!("{:02X} ", c); }
4237 println!();
4238 let mut txt = String::new();
4239 for c in cipher.clone()
4240 { write!(txt, "{:02X} ", c); }
4241 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
4242
4243 let mut recovered = String::new();
4244 a_des.decrypt_into_string(nonce, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
4245 println!("B =\t{}", recovered);
4246 assert_eq!(recovered, "고맙습니다.");
4247 assert_eq!(recovered, message);
4248 println!("-------------------------------");
4249}
4250
4251fn des_decrypt_vec_ctr()
4252{
4253 println!("des_decrypt_vec_ctr()");
4254 use std::io::Write;
4255 use std::fmt::Write as _;
4256 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
4257
4258 // Normal case
4259 let key = 0x_1234567890ABCDEF_u64;
4260 println!("K =\t{:#016X}", key);
4261 let mut a_des = DES::new_with_key_u64(key);
4262
4263 let message = "In the beginning God created the heavens and the earth.";
4264 println!("M =\t{}", message);
4265 let nonce = 0x_FEDCBA0987654321_u64;
4266 println!("Nonce = {}", nonce);
4267 let mut cipher = Vec::<u8>::new();
4268 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4269 print!("C (16 rounds) =\t");
4270 for c in cipher.clone()
4271 { print!("{:02X} ", c); }
4272 println!();
4273 let mut txt = String::new();
4274 for c in cipher.clone()
4275 { write!(txt, "{:02X} ", c); }
4276 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
4277
4278 let mut recovered = vec![0; 55];
4279 a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4280 print!("Ba (16 rounds) =\t");
4281 for b in recovered.clone()
4282 { print!("{:02X} ", b); }
4283 println!();
4284 let mut txt = String::new();
4285 for c in recovered.clone()
4286 { write!(txt, "{:02X} ", c); }
4287 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4288
4289 let mut converted = String::new();
4290 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4291
4292 println!("Bb (16 rounds) =\t{}", converted);
4293 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4294 assert_eq!(converted, message);
4295 println!();
4296
4297 // Expanded case for 128 rounds
4298 let key = 0x_1234567890ABCDEF_u64;
4299 println!("K =\t{:#016X}", key);
4300 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4301
4302 let message = "In the beginning God created the heavens and the earth.";
4303 println!("M =\t{}", message);
4304 let nonce = 0x_FEDCBA0987654321_u64;
4305 println!("Nonce = {}", nonce);
4306 let mut cipher = Vec::<u8>::new();
4307 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4308 print!("C (128 rounds) =\t");
4309 for c in cipher.clone()
4310 { print!("{:02X} ", c); }
4311 println!();
4312 let mut txt = String::new();
4313 for c in cipher.clone()
4314 { write!(txt, "{:02X} ", c); }
4315 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
4316
4317 let mut recovered = vec![0; 55];
4318 a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4319 print!("Ba (128 rounds) =\t");
4320 for b in recovered.clone()
4321 { print!("{:02X} ", b); }
4322 println!();
4323 let mut txt = String::new();
4324 for c in recovered.clone()
4325 { write!(txt, "{:02X} ", c); }
4326 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4327
4328 let mut converted = String::new();
4329 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4330
4331 println!("Bb (128 rounds) =\t{}", converted);
4332 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4333 assert_eq!(converted, message);
4334 println!();
4335
4336 // Expanded case for 0 rounds which means that key is meaningless
4337 let key1 = 0x_1234567890ABCDEF_u64;
4338 let key2 = 0_u64;
4339 println!("K =\t{:#016X}", key);
4340 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4341 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4342
4343 let message = "In the beginning God created the heavens and the earth.";
4344 println!("M =\t{}", message);
4345 let nonce = 0x_FEDCBA0987654321_u64;
4346 println!("Nonce = {}", nonce);
4347 let mut cipher1 = Vec::<u8>::new();
4348 let mut cipher2 = Vec::<u8>::new();
4349 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
4350 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
4351 print!("C (0 rounds) =\t");
4352 for c in cipher1.clone()
4353 { print!("{:02X} ", c); }
4354 println!();
4355 let mut txt = String::new();
4356 for c in cipher1.clone()
4357 { write!(txt, "{:02X} ", c); }
4358 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
4359 print!("D (0 rounds) =\t");
4360 for c in cipher2.clone()
4361 { print!("{:02X} ", c); }
4362 println!();
4363 let mut txt = String::new();
4364 for c in cipher2.clone()
4365 { write!(txt, "{:02X} ", c); }
4366 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
4367
4368 let mut recovered1 = vec![0; 55];
4369 let mut recovered2 = vec![0; 55];
4370 c_des.decrypt_vec(nonce, &cipher1, recovered1.as_mut_ptr());
4371 d_des.decrypt_vec(nonce, &cipher2, recovered2.as_mut_ptr());
4372 print!("B1a (0 rounds) =\t");
4373 for b in recovered1.clone()
4374 { print!("{:02X} ", b); }
4375 println!();
4376 let mut txt = String::new();
4377 for c in recovered1.clone()
4378 { write!(txt, "{:02X} ", c); }
4379 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4380 print!("B2a (0 rounds) =\t");
4381 for b in recovered2.clone()
4382 { print!("{:02X} ", b); }
4383 println!();
4384 let mut txt = String::new();
4385 for c in recovered2.clone()
4386 { write!(txt, "{:02X} ", c); }
4387 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4388
4389 let mut converted1 = String::new();
4390 let mut converted2 = String::new();
4391 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4392 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4393
4394 println!("B1b (0 rounds) =\t{}", converted1);
4395 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4396 assert_eq!(converted1, message);
4397 println!("B2b (0 rounds) =\t{}", converted2);
4398 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4399 assert_eq!(converted2, message);
4400 assert_eq!(converted1, converted1);
4401 println!();
4402
4403 // Normal case for the message of 0 bytes
4404 let key = 0x_1234567890ABCDEF_u64;
4405 println!("K =\t{:#016X}", key);
4406 let mut a_des = DES::new_with_key_u64(key);
4407
4408 let message = "";
4409 println!("M =\t{}", message);
4410 let nonce = 0x_FEDCBA0987654321_u64;
4411 println!("Nonce = {}", nonce);
4412 let mut cipher = Vec::<u8>::new();
4413 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4414 print!("C =\t");
4415 for c in cipher.clone()
4416 { print!("{:02X} ", c); }
4417 println!();
4418 let mut txt = String::new();
4419 for c in cipher.clone()
4420 { write!(txt, "{:02X} ", c); }
4421 assert_eq!(txt, "");
4422
4423 let mut recovered = vec![0; 8];
4424 let len = a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4425 print!("Ba =\t");
4426 for b in recovered.clone()
4427 { print!("{:02X} ", b); }
4428 println!();
4429 let mut txt = String::new();
4430 for c in recovered.clone()
4431 { write!(txt, "{:02X} ", c); }
4432 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
4433
4434 let mut converted = String::new();
4435 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4436 converted.truncate(len as usize);
4437
4438 println!("Bb =\t{}", converted);
4439 assert_eq!(converted, "");
4440 assert_eq!(converted, message);
4441 println!();
4442
4443 // Normal case for the message shorter than 8 bytes
4444 let key = 0x_1234567890ABCDEF_u64;
4445 println!("K =\t{:#016X}", key);
4446 let mut a_des = DES::new_with_key_u64(key);
4447
4448 let message = "7 bytes";
4449 println!("M =\t{}", message);
4450 let nonce = 0x_FEDCBA0987654321_u64;
4451 println!("Nonce = {}", nonce);
4452 let mut cipher = Vec::<u8>::new();
4453 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4454 print!("C =\t");
4455 for c in cipher.clone()
4456 { print!("{:02X} ", c); }
4457 println!();
4458 let mut txt = String::new();
4459 for c in cipher.clone()
4460 { write!(txt, "{:02X} ", c); }
4461 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
4462
4463 let mut recovered = vec![0; 8];
4464 let len = a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4465 print!("Ba =\t");
4466 for b in recovered.clone()
4467 { print!("{:02X} ", b); }
4468 println!();
4469 let mut txt = String::new();
4470 for c in recovered.clone()
4471 { write!(txt, "{:02X} ", c); }
4472 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
4473
4474 let mut converted = String::new();
4475 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4476 converted.truncate(len as usize);
4477
4478 println!("Bb =\t{}", converted);
4479 assert_eq!(converted, "7 bytes");
4480 assert_eq!(converted, message);
4481 println!();
4482
4483 // Normal case for the message of 8 bytes
4484 let key = 0x_1234567890ABCDEF_u64;
4485 println!("K =\t{:#016X}", key);
4486 let mut a_des = DES::new_with_key_u64(key);
4487
4488 let message = "I am OK.";
4489 println!("M =\t{}", message);
4490 let nonce = 0x_FEDCBA0987654321_u64;
4491 println!("Nonce = {}", nonce);
4492 let mut cipher = Vec::<u8>::new();
4493 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4494 print!("C =\t");
4495 for c in cipher.clone()
4496 { print!("{:02X} ", c); }
4497 println!();
4498 let mut txt = String::new();
4499 for c in cipher.clone()
4500 { write!(txt, "{:02X} ", c); }
4501 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
4502
4503 let mut recovered = vec![0; 16];
4504 let len = a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4505 print!("Ba =\t");
4506 for b in recovered.clone()
4507 { print!("{:02X} ", b); }
4508 println!();
4509 let mut txt = String::new();
4510 for c in recovered.clone()
4511 { write!(txt, "{:02X} ", c); }
4512 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
4513
4514 let mut converted = String::new();
4515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4516 converted.truncate(len as usize);
4517
4518 println!("Bb =\t{}", converted);
4519 assert_eq!(converted, "I am OK.");
4520 assert_eq!(converted, message);
4521 println!();
4522
4523 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4524 let key = 0x_1234567890ABCDEF_u64;
4525 println!("K =\t{:#016X}", key);
4526 let mut a_des = DES::new_with_key_u64(key);
4527
4528 let message = "PARK Youngho";
4529 println!("M =\t{}", message);
4530 let nonce = 0x_FEDCBA0987654321_u64;
4531 println!("Nonce = {}", nonce);
4532 let mut cipher = Vec::<u8>::new();
4533 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4534 print!("C =\t");
4535 for c in cipher.clone()
4536 { print!("{:02X} ", c); }
4537 println!();
4538 let mut txt = String::new();
4539 for c in cipher.clone()
4540 { write!(txt, "{:02X} ", c); }
4541 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
4542
4543 let mut recovered = vec![0; 16];
4544 let len = a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4545 print!("Ba =\t");
4546 for b in recovered.clone()
4547 { print!("{:02X} ", b); }
4548 println!();
4549 let mut txt = String::new();
4550 for c in recovered.clone()
4551 { write!(txt, "{:02X} ", c); }
4552 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
4553
4554 let mut converted = String::new();
4555 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4556 converted.truncate(len as usize);
4557
4558 println!("Bb =\t{}", converted);
4559 assert_eq!(converted, "PARK Youngho");
4560 assert_eq!(converted, message);
4561 println!();
4562
4563 // Normal case for the message of 16 bytes
4564 let key = 0x_1234567890ABCDEF_u64;
4565 println!("K =\t{:#016X}", key);
4566 let mut a_des = DES::new_with_key_u64(key);
4567
4568 let message = "고맙습니다.";
4569 println!("M =\t{}", message);
4570 let nonce = 0x_FEDCBA0987654321_u64;
4571 println!("Nonce = {}", nonce);
4572 let mut cipher = Vec::<u8>::new();
4573 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4574 print!("C =\t");
4575 for c in cipher.clone()
4576 { print!("{:02X} ", c); }
4577 println!();
4578 let mut txt = String::new();
4579 for c in cipher.clone()
4580 { write!(txt, "{:02X} ", c); }
4581 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
4582
4583 let mut recovered = vec![0; 24];
4584 let len = a_des.decrypt_vec(nonce, &cipher, recovered.as_mut_ptr());
4585 print!("Ba =\t");
4586 for b in recovered.clone()
4587 { print!("{:02X} ", b); }
4588 println!();
4589 let mut txt = String::new();
4590 for c in recovered.clone()
4591 { write!(txt, "{:02X} ", c); }
4592 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
4593
4594 let mut converted = String::new();
4595 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4596 converted.truncate(len as usize);
4597
4598 println!("Bb =\t{}", converted);
4599 assert_eq!(converted, "고맙습니다.");
4600 assert_eq!(converted, message);
4601 println!("-------------------------------");
4602}
4603
4604fn des_decrypt_vec_ctr_into_vec()
4605{
4606 println!("des_decrypt_vec_ctr_into_vec()");
4607 use std::io::Write;
4608 use std::fmt::Write as _;
4609 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
4610
4611 // Normal case
4612 let key = 0x_1234567890ABCDEF_u64;
4613 println!("K =\t{:#016X}", key);
4614 let mut a_des = DES::new_with_key_u64(key);
4615
4616 let message = "In the beginning God created the heavens and the earth.";
4617 println!("M =\t{}", message);
4618 let nonce = 0x_FEDCBA0987654321_u64;
4619 println!("Nonce = {}", nonce);
4620 let mut cipher = Vec::<u8>::new();
4621 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4622 print!("C (16 rounds) =\t");
4623 for c in cipher.clone()
4624 { print!("{:02X} ", c); }
4625 println!();
4626 let mut txt = String::new();
4627 for c in cipher.clone()
4628 { write!(txt, "{:02X} ", c); }
4629 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
4630
4631 let mut recovered = Vec::<u8>::new();
4632 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4633 print!("Ba (16 rounds) =\t");
4634 for b in recovered.clone()
4635 { print!("{:02X} ", b); }
4636 println!();
4637 let mut txt = String::new();
4638 for c in recovered.clone()
4639 { write!(txt, "{:02X} ", c); }
4640 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4641
4642 let mut converted = String::new();
4643 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4644
4645 println!("Bb (16 rounds) =\t{}", converted);
4646 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4647 assert_eq!(converted, message);
4648 println!();
4649
4650 // Expanded case for 128 rounds
4651 let key = 0x_1234567890ABCDEF_u64;
4652 println!("K =\t{:#016X}", key);
4653 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
4654
4655 let message = "In the beginning God created the heavens and the earth.";
4656 println!("M =\t{}", message);
4657 let nonce = 0x_FEDCBA0987654321_u64;
4658 println!("Nonce = {}", nonce);
4659 let mut cipher = Vec::<u8>::new();
4660 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4661 print!("C (128 rounds) =\t");
4662 for c in cipher.clone()
4663 { print!("{:02X} ", c); }
4664 println!();
4665 let mut txt = String::new();
4666 for c in cipher.clone()
4667 { write!(txt, "{:02X} ", c); }
4668 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
4669
4670 let mut recovered = Vec::<u8>::new();
4671 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4672 print!("Ba (128 rounds) =\t");
4673 for b in recovered.clone()
4674 { print!("{:02X} ", b); }
4675 println!();
4676 let mut txt = String::new();
4677 for c in recovered.clone()
4678 { write!(txt, "{:02X} ", c); }
4679 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4680
4681 let mut converted = String::new();
4682 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4683
4684 println!("Bb (128 rounds) =\t{}", converted);
4685 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4686 assert_eq!(converted, message);
4687 println!();
4688
4689 // Expanded case for 0 rounds which means that key is meaningless
4690 let key1 = 0x_1234567890ABCDEF_u64;
4691 let key2 = 0_u64;
4692 println!("K =\t{:#016X}", key);
4693 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
4694 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
4695
4696 let message = "In the beginning God created the heavens and the earth.";
4697 println!("M =\t{}", message);
4698 let nonce = 0x_FEDCBA0987654321_u64;
4699 println!("Nonce = {}", nonce);
4700 let mut cipher1 = Vec::<u8>::new();
4701 let mut cipher2 = Vec::<u8>::new();
4702 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
4703 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
4704 print!("C (0 rounds) =\t");
4705 for c in cipher1.clone()
4706 { print!("{:02X} ", c); }
4707 println!();
4708 let mut txt = String::new();
4709 for c in cipher1.clone()
4710 { write!(txt, "{:02X} ", c); }
4711 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
4712 print!("D (0 rounds) =\t");
4713 for c in cipher2.clone()
4714 { print!("{:02X} ", c); }
4715 println!();
4716 let mut txt = String::new();
4717 for c in cipher2.clone()
4718 { write!(txt, "{:02X} ", c); }
4719 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
4720
4721 let mut recovered1 = Vec::<u8>::new();
4722 let mut recovered2 = Vec::<u8>::new();
4723 c_des.decrypt_vec_into_vec(nonce, &cipher1, &mut recovered1);
4724 d_des.decrypt_vec_into_vec(nonce, &cipher2, &mut recovered2);
4725 print!("B1a (0 rounds) =\t");
4726 for b in recovered1.clone()
4727 { print!("{:02X} ", b); }
4728 println!();
4729 let mut txt = String::new();
4730 for c in recovered1.clone()
4731 { write!(txt, "{:02X} ", c); }
4732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4733 print!("B2a (0 rounds) =\t");
4734 for b in recovered2.clone()
4735 { print!("{:02X} ", b); }
4736 println!();
4737 let mut txt = String::new();
4738 for c in recovered2.clone()
4739 { write!(txt, "{:02X} ", c); }
4740 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
4741
4742 let mut converted1 = String::new();
4743 let mut converted2 = String::new();
4744 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
4745 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
4746
4747 println!("B1b (0 rounds) =\t{}", converted1);
4748 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
4749 assert_eq!(converted1, message);
4750 println!("B2b (0 rounds) =\t{}", converted2);
4751 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
4752 assert_eq!(converted2, message);
4753 assert_eq!(converted1, converted1);
4754 println!();
4755
4756 // Normal case for the message of 0 bytes
4757 let key = 0x_1234567890ABCDEF_u64;
4758 println!("K =\t{:#016X}", key);
4759 let mut a_des = DES::new_with_key_u64(key);
4760
4761 let message = "";
4762 println!("M =\t{}", message);
4763 let nonce = 0x_FEDCBA0987654321_u64;
4764 println!("Nonce = {}", nonce);
4765 let mut cipher = Vec::<u8>::new();
4766 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4767 print!("C =\t");
4768 for c in cipher.clone()
4769 { print!("{:02X} ", c); }
4770 println!();
4771 let mut txt = String::new();
4772 for c in cipher.clone()
4773 { write!(txt, "{:02X} ", c); }
4774 assert_eq!(txt, "");
4775
4776 let mut recovered = Vec::<u8>::new();
4777 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4778 print!("Ba =\t");
4779 for b in recovered.clone()
4780 { print!("{:02X} ", b); }
4781 println!();
4782 let mut txt = String::new();
4783 for c in recovered.clone()
4784 { write!(txt, "{:02X} ", c); }
4785 assert_eq!(txt, "");
4786
4787 let mut converted = String::new();
4788 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4789
4790 println!("Bb =\t{}", converted);
4791 assert_eq!(converted, "");
4792 assert_eq!(converted, message);
4793 println!();
4794
4795 // Normal case for the message shorter than 8 bytes
4796 let key = 0x_1234567890ABCDEF_u64;
4797 println!("K =\t{:#016X}", key);
4798 let mut a_des = DES::new_with_key_u64(key);
4799
4800 let message = "7 bytes";
4801 println!("M =\t{}", message);
4802 let nonce = 0x_FEDCBA0987654321_u64;
4803 println!("Nonce = {}", nonce);
4804 let mut cipher = Vec::<u8>::new();
4805 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4806 print!("C =\t");
4807 for c in cipher.clone()
4808 { print!("{:02X} ", c); }
4809 println!();
4810 let mut txt = String::new();
4811 for c in cipher.clone()
4812 { write!(txt, "{:02X} ", c); }
4813 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
4814
4815 let mut recovered = Vec::<u8>::new();
4816 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4817 print!("Ba =\t");
4818 for b in recovered.clone()
4819 { print!("{:02X} ", b); }
4820 println!();
4821 let mut txt = String::new();
4822 for c in recovered.clone()
4823 { write!(txt, "{:02X} ", c); }
4824 assert_eq!(txt, "37 20 62 79 74 65 73 ");
4825
4826 let mut converted = String::new();
4827 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4828
4829 println!("Bb =\t{}", converted);
4830 assert_eq!(converted, "7 bytes");
4831 assert_eq!(converted, message);
4832 println!();
4833
4834 // Normal case for the message of 8 bytes
4835 let key = 0x_1234567890ABCDEF_u64;
4836 println!("K =\t{:#016X}", key);
4837 let mut a_des = DES::new_with_key_u64(key);
4838
4839 let message = "I am OK.";
4840 println!("M =\t{}", message);
4841 let nonce = 0x_FEDCBA0987654321_u64;
4842 println!("Nonce = {}", nonce);
4843 let mut cipher = Vec::<u8>::new();
4844 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4845 print!("C =\t");
4846 for c in cipher.clone()
4847 { print!("{:02X} ", c); }
4848 println!();
4849 let mut txt = String::new();
4850 for c in cipher.clone()
4851 { write!(txt, "{:02X} ", c); }
4852 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
4853
4854 let mut recovered = Vec::<u8>::new();
4855 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4856 print!("Ba =\t");
4857 for b in recovered.clone()
4858 { print!("{:02X} ", b); }
4859 println!();
4860 let mut txt = String::new();
4861 for c in recovered.clone()
4862 { write!(txt, "{:02X} ", c); }
4863 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
4864
4865 let mut converted = String::new();
4866 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4867
4868 println!("Bb =\t{}", converted);
4869 assert_eq!(converted, "I am OK.");
4870 assert_eq!(converted, message);
4871 println!();
4872
4873 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
4874 let key = 0x_1234567890ABCDEF_u64;
4875 println!("K =\t{:#016X}", key);
4876 let mut a_des = DES::new_with_key_u64(key);
4877
4878 let message = "PARK Youngho";
4879 println!("M =\t{}", message);
4880 let nonce = 0x_FEDCBA0987654321_u64;
4881 println!("Nonce = {}", nonce);
4882 let mut cipher = Vec::<u8>::new();
4883 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4884 print!("C =\t");
4885 for c in cipher.clone()
4886 { print!("{:02X} ", c); }
4887 println!();
4888 let mut txt = String::new();
4889 for c in cipher.clone()
4890 { write!(txt, "{:02X} ", c); }
4891 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
4892
4893 let mut recovered = Vec::<u8>::new();
4894 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4895 print!("Ba =\t");
4896 for b in recovered.clone()
4897 { print!("{:02X} ", b); }
4898 println!();
4899 let mut txt = String::new();
4900 for c in recovered.clone()
4901 { write!(txt, "{:02X} ", c); }
4902 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
4903
4904 let mut converted = String::new();
4905 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4906
4907 println!("Bb =\t{}", converted);
4908 assert_eq!(converted, "PARK Youngho");
4909 assert_eq!(converted, message);
4910 println!();
4911
4912 // Normal case for the message of 16 bytes
4913 let key = 0x_1234567890ABCDEF_u64;
4914 println!("K =\t{:#016X}", key);
4915 let mut a_des = DES::new_with_key_u64(key);
4916
4917 let message = "고맙습니다.";
4918 println!("M =\t{}", message);
4919 let nonce = 0x_FEDCBA0987654321_u64;
4920 println!("Nonce = {}", nonce);
4921 let mut cipher = Vec::<u8>::new();
4922 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4923 print!("C =\t");
4924 for c in cipher.clone()
4925 { print!("{:02X} ", c); }
4926 println!();
4927 let mut txt = String::new();
4928 for c in cipher.clone()
4929 { write!(txt, "{:02X} ", c); }
4930 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
4931
4932 let mut recovered = Vec::<u8>::new();
4933 a_des.decrypt_vec_into_vec(nonce, &cipher, &mut recovered);
4934 print!("Ba =\t");
4935 for b in recovered.clone()
4936 { print!("{:02X} ", b); }
4937 println!();
4938 let mut txt = String::new();
4939 for c in recovered.clone()
4940 { write!(txt, "{:02X} ", c); }
4941 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
4942
4943 let mut converted = String::new();
4944 unsafe { converted.as_mut_vec() }.append(&mut recovered);
4945
4946 println!("Bb =\t{}", converted);
4947 assert_eq!(converted, "고맙습니다.");
4948 assert_eq!(converted, message);
4949 println!("-------------------------------");
4950}
4951
4952fn des_decrypt_vec_ctr_into_array()
4953{
4954 println!("des_decrypt_vec_ctr_into_array()");
4955 use std::io::Write;
4956 use std::fmt::Write as _;
4957 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
4958
4959 // Normal case
4960 let key = 0x_1234567890ABCDEF_u64;
4961 println!("K =\t{:#016X}", key);
4962 let mut a_des = DES::new_with_key_u64(key);
4963
4964 let message = "In the beginning God created the heavens and the earth.";
4965 println!("M =\t{}", message);
4966 let nonce = 0x_FEDCBA0987654321_u64;
4967 println!("Nonce = {}", nonce);
4968 let mut cipher = Vec::<u8>::new();
4969 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
4970 print!("C (16 rounds) =\t");
4971 for c in cipher.clone()
4972 { print!("{:02X} ", c); }
4973 println!();
4974 let mut txt = String::new();
4975 for c in cipher.clone()
4976 { write!(txt, "{:02X} ", c); }
4977 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
4978
4979 let mut recovered = [0u8; 56];
4980 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
4981 print!("Ba (16 rounds) =\t");
4982 for b in recovered.clone()
4983 { print!("{:02X} ", b); }
4984 println!();
4985 let mut txt = String::new();
4986 for c in recovered.clone()
4987 { write!(txt, "{:02X} ", c); }
4988 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
4989
4990 let mut converted = String::new();
4991 unsafe { converted.as_mut_vec() }.write(&recovered);
4992 unsafe { converted.as_mut_vec() }.truncate(len as usize);
4993 println!("Bb (16 rounds) =\t{}", converted);
4994 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
4995 assert_eq!(converted, message);
4996 println!();
4997
4998 // Expanded case for 128 rounds
4999 let key = 0x_1234567890ABCDEF_u64;
5000 println!("K =\t{:#016X}", key);
5001 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5002
5003 let message = "In the beginning God created the heavens and the earth.";
5004 println!("M =\t{}", message);
5005 let nonce = 0x_FEDCBA0987654321_u64;
5006 println!("Nonce = {}", nonce);
5007 let mut cipher = Vec::<u8>::new();
5008 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5009 print!("C (128 rounds) =\t");
5010 for c in cipher.clone()
5011 { print!("{:02X} ", c); }
5012 println!();
5013 let mut txt = String::new();
5014 for c in cipher.clone()
5015 { write!(txt, "{:02X} ", c); }
5016 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
5017
5018 let mut recovered = [0u8; 56];
5019 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
5020 print!("Ba (16 rounds) =\t");
5021 for b in recovered.clone()
5022 { print!("{:02X} ", b); }
5023 println!();
5024 let mut txt = String::new();
5025 for c in recovered.clone()
5026 { write!(txt, "{:02X} ", c); }
5027 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5028
5029 let mut converted = String::new();
5030 unsafe { converted.as_mut_vec() }.write(&recovered);
5031 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5032 println!("Bb (16 rounds) =\t{}", converted);
5033 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5034 assert_eq!(converted, message);
5035 println!();
5036
5037 // Expanded case for 0 rounds which means that key is meaningless
5038 let key1 = 0x_1234567890ABCDEF_u64;
5039 let key2 = 0_u64;
5040 println!("K =\t{:#016X}", key);
5041 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5042 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5043
5044 let message = "In the beginning God created the heavens and the earth.";
5045 println!("M =\t{}", message);
5046 let nonce = 0x_FEDCBA0987654321_u64;
5047 println!("Nonce = {}", nonce);
5048 let mut cipher1 = Vec::<u8>::new();
5049 let mut cipher2 = Vec::<u8>::new();
5050 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
5051 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
5052 print!("C (0 rounds) =\t");
5053 for c in cipher1.clone()
5054 { print!("{:02X} ", c); }
5055 println!();
5056 let mut txt = String::new();
5057 for c in cipher1.clone()
5058 { write!(txt, "{:02X} ", c); }
5059 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
5060 print!("D (0 rounds) =\t");
5061 for c in cipher2.clone()
5062 { print!("{:02X} ", c); }
5063 println!();
5064 let mut txt = String::new();
5065 for c in cipher2.clone()
5066 { write!(txt, "{:02X} ", c); }
5067 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
5068
5069 let mut recovered1 = [0u8; 56];
5070 let mut recovered2 = [0u8; 56];
5071 let len1 = c_des.decrypt_vec_into_array(nonce, &cipher1, &mut recovered1);
5072 let len2 = d_des.decrypt_vec_into_array(nonce, &cipher2, &mut recovered2);
5073 print!("B1a (0 rounds) =\t");
5074 for b in recovered1.clone()
5075 { print!("{:02X} ", b); }
5076 println!();
5077 let mut txt = String::new();
5078 for c in recovered1.clone()
5079 { write!(txt, "{:02X} ", c); }
5080 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5081 print!("B2a (0 rounds) =\t");
5082 for b in recovered2.clone()
5083 { print!("{:02X} ", b); }
5084 println!();
5085 let mut txt = String::new();
5086 for c in recovered.clone()
5087 { write!(txt, "{:02X} ", c); }
5088 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
5089
5090 let mut converted1 = String::new();
5091 let mut converted2 = String::new();
5092 unsafe { converted1.as_mut_vec() }.write(&recovered1);
5093 unsafe { converted2.as_mut_vec() }.write(&recovered2);
5094 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
5095 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
5096 println!("B1b (0 rounds) =\t{}", converted1);
5097 println!("B2b (0 rounds) =\t{}", converted2);
5098 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5099 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5100 assert_eq!(converted1, message);
5101 assert_eq!(converted2, message);
5102 assert_eq!(converted1, converted2);
5103 println!();
5104
5105 // Normal case for the message of 0 bytes
5106 let key = 0x_1234567890ABCDEF_u64;
5107 println!("K =\t{:#016X}", key);
5108 let mut a_des = DES::new_with_key_u64(key);
5109
5110 let message = "";
5111 println!("M =\t{}", message);
5112 let nonce = 0x_FEDCBA0987654321_u64;
5113 println!("Nonce = {}", nonce);
5114 let mut cipher = Vec::<u8>::new();
5115 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5116 print!("C =\t");
5117 for c in cipher.clone()
5118 { print!("{:02X} ", c); }
5119 println!();
5120 let mut txt = String::new();
5121 for c in cipher.clone()
5122 { write!(txt, "{:02X} ", c); }
5123 assert_eq!(txt, "");
5124
5125 let mut recovered = [0u8; 8];
5126 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
5127
5128 print!("Ba =\t");
5129 for b in recovered.clone()
5130 { print!("{:02X} ", b); }
5131 println!();
5132 let mut txt = String::new();
5133 for c in recovered.clone()
5134 { write!(txt, "{:02X} ", c); }
5135 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
5136
5137 let mut converted = String::new();
5138 unsafe { converted.as_mut_vec() }.write(&recovered);
5139 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5140 println!("Bb =\t{}", converted);
5141 assert_eq!(converted, "");
5142 assert_eq!(converted, message);
5143 println!();
5144
5145 // Normal case for the message shorter than 8 bytes
5146 let key = 0x_1234567890ABCDEF_u64;
5147 println!("K =\t{:#016X}", key);
5148 let mut a_des = DES::new_with_key_u64(key);
5149
5150 let message = "7 bytes";
5151 println!("M =\t{}", message);
5152 let nonce = 0x_FEDCBA0987654321_u64;
5153 println!("Nonce = {}", nonce);
5154 let mut cipher = Vec::<u8>::new();
5155 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5156 print!("C =\t");
5157 for c in cipher.clone()
5158 { print!("{:02X} ", c); }
5159 println!();
5160 let mut txt = String::new();
5161 for c in cipher.clone()
5162 { write!(txt, "{:02X} ", c); }
5163 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
5164
5165 let mut recovered = [0u8; 8];
5166 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
5167
5168 print!("Ba =\t");
5169 for b in recovered.clone()
5170 { print!("{:02X} ", b); }
5171 println!();
5172 let mut txt = String::new();
5173 for c in recovered.clone()
5174 { write!(txt, "{:02X} ", c); }
5175 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
5176
5177 let mut converted = String::new();
5178 unsafe { converted.as_mut_vec() }.write(&recovered);
5179 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5180 println!("Bb =\t{}", converted);
5181 assert_eq!(converted, "7 bytes");
5182 assert_eq!(converted, message);
5183 println!();
5184
5185 // Normal case for the message of 8 bytes
5186 let key = 0x_1234567890ABCDEF_u64;
5187 println!("K =\t{:#016X}", key);
5188 let mut a_des = DES::new_with_key_u64(key);
5189
5190 let message = "I am OK.";
5191 println!("M =\t{}", message);
5192 let nonce = 0x_FEDCBA0987654321_u64;
5193 println!("Nonce = {}", nonce);
5194 let mut cipher = Vec::<u8>::new();
5195 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5196 print!("C =\t");
5197 for c in cipher.clone()
5198 { print!("{:02X} ", c); }
5199 println!();
5200 let mut txt = String::new();
5201 for c in cipher.clone()
5202 { write!(txt, "{:02X} ", c); }
5203 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
5204
5205 let mut recovered = [0u8; 16];
5206 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
5207
5208 print!("Ba =\t");
5209 for b in recovered.clone()
5210 { print!("{:02X} ", b); }
5211 println!();
5212 let mut txt = String::new();
5213 for c in recovered.clone()
5214 { write!(txt, "{:02X} ", c); }
5215 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
5216
5217 let mut converted = String::new();
5218 unsafe { converted.as_mut_vec() }.write(&recovered);
5219 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5220 println!("Bb =\t{}", converted);
5221 assert_eq!(converted, "I am OK.");
5222 assert_eq!(converted, message);
5223 println!();
5224
5225 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5226 let key = 0x_1234567890ABCDEF_u64;
5227 println!("K =\t{:#016X}", key);
5228 let mut a_des = DES::new_with_key_u64(key);
5229
5230 let message = "PARK Youngho";
5231 println!("M =\t{}", message);
5232 let nonce = 0x_FEDCBA0987654321_u64;
5233 println!("Nonce = {}", nonce);
5234 let mut cipher = Vec::<u8>::new();
5235 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5236 print!("C =\t");
5237 for c in cipher.clone()
5238 { print!("{:02X} ", c); }
5239 println!();
5240 let mut txt = String::new();
5241 for c in cipher.clone()
5242 { write!(txt, "{:02X} ", c); }
5243 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
5244
5245 let mut recovered = [0u8; 16];
5246 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
5247
5248 print!("Ba =\t");
5249 for b in recovered.clone()
5250 { print!("{:02X} ", b); }
5251 println!();
5252 let mut txt = String::new();
5253 for c in recovered.clone()
5254 { write!(txt, "{:02X} ", c); }
5255 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
5256
5257 let mut converted = String::new();
5258 unsafe { converted.as_mut_vec() }.write(&recovered);
5259 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5260 println!("Bb =\t{}", converted);
5261 assert_eq!(converted, "PARK Youngho");
5262 assert_eq!(converted, message);
5263 println!();
5264
5265 // Normal case for the message of 16 bytes
5266 let key = 0x_1234567890ABCDEF_u64;
5267 println!("K =\t{:#016X}", key);
5268 let mut a_des = DES::new_with_key_u64(key);
5269
5270 let message = "고맙습니다.";
5271 println!("M =\t{}", message);
5272 let nonce = 0x_FEDCBA0987654321_u64;
5273 println!("Nonce = {}", nonce);
5274 let mut cipher = Vec::<u8>::new();
5275 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5276 print!("C =\t");
5277 for c in cipher.clone()
5278 { print!("{:02X} ", c); }
5279 println!();
5280 let mut txt = String::new();
5281 for c in cipher.clone()
5282 { write!(txt, "{:02X} ", c); }
5283 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
5284
5285 let mut recovered = [0u8; 24];
5286 let len = a_des.decrypt_vec_into_array(nonce, &cipher, &mut recovered);
5287
5288 print!("Ba =\t");
5289 for b in recovered.clone()
5290 { print!("{:02X} ", b); }
5291 println!();
5292 let mut txt = String::new();
5293 for c in recovered.clone()
5294 { write!(txt, "{:02X} ", c); }
5295 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
5296
5297 let mut converted = String::new();
5298 unsafe { converted.as_mut_vec() }.write(&recovered);
5299 unsafe { converted.as_mut_vec() }.truncate(len as usize);
5300 println!("Bb =\t{}", converted);
5301 assert_eq!(converted, "고맙습니다.");
5302 assert_eq!(converted, message);
5303 println!("-------------------------------");
5304}
5305
5306fn des_decrypt_vec_ctr_into_string()
5307{
5308 println!("des_decrypt_vec_ctr_into_string()");
5309 use std::io::Write;
5310 use std::fmt::Write as _;
5311 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
5312
5313 // Normal case
5314 let key = 0x_1234567890ABCDEF_u64;
5315 println!("K =\t{:#016X}", key);
5316 let mut a_des = DES::new_with_key_u64(key);
5317
5318 let message = "In the beginning God created the heavens and the earth.";
5319 println!("M =\t{}", message);
5320 let nonce = 0x_FEDCBA0987654321_u64;
5321 println!("Nonce = {}", nonce);
5322 let mut cipher = Vec::<u8>::new();
5323 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5324 print!("C (16 rounds) =\t");
5325 for c in cipher.clone()
5326 { print!("{:02X} ", c); }
5327 println!();
5328 let mut txt = String::new();
5329 for c in cipher.clone()
5330 { write!(txt, "{:02X} ", c); }
5331 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
5332
5333 let mut recovered = String::new();
5334 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5335 println!("B (16 rounds) =\t{}", recovered);
5336 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5337 assert_eq!(recovered, message);
5338 println!();
5339
5340 // Expanded case for 128 rounds
5341 let key = 0x_1234567890ABCDEF_u64;
5342 println!("K =\t{:#016X}", key);
5343 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5344
5345 let message = "In the beginning God created the heavens and the earth.";
5346 println!("M =\t{}", message);
5347 let nonce = 0x_FEDCBA0987654321_u64;
5348 println!("Nonce = {}", nonce);
5349 let mut cipher = Vec::<u8>::new();
5350 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5351 print!("C (128 rounds) =\t");
5352 for c in cipher.clone()
5353 { print!("{:02X} ", c); }
5354 println!();
5355 let mut txt = String::new();
5356 for c in cipher.clone()
5357 { write!(txt, "{:02X} ", c); }
5358 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
5359
5360 let mut recovered = String::new();
5361 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5362 println!("B (128 rounds) =\t{}", recovered);
5363 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
5364 assert_eq!(recovered, message);
5365 println!();
5366
5367 // Expanded case for 0 rounds which means that key is meaningless
5368 let key1 = 0x_1234567890ABCDEF_u64;
5369 let key2 = 0_u64;
5370 println!("K =\t{:#016X}", key);
5371 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5372 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5373
5374 let message = "In the beginning God created the heavens and the earth.";
5375 println!("M =\t{}", message);
5376 let nonce = 0x_FEDCBA0987654321_u64;
5377 println!("Nonce = {}", nonce);
5378 let mut cipher1 = Vec::<u8>::new();
5379 let mut cipher2 = Vec::<u8>::new();
5380 c_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
5381 d_des.encrypt_into_vec(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
5382 print!("C (0 rounds) =\t");
5383 for c in cipher1.clone()
5384 { print!("{:02X} ", c); }
5385 println!();
5386 let mut txt = String::new();
5387 for c in cipher1.clone()
5388 { write!(txt, "{:02X} ", c); }
5389 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
5390 print!("D (0 rounds) =\t");
5391 for c in cipher2.clone()
5392 { print!("{:02X} ", c); }
5393 println!();
5394 let mut txt = String::new();
5395 for c in cipher2.clone()
5396 { write!(txt, "{:02X} ", c); }
5397 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
5398
5399 let mut recovered1 = String::new();
5400 let mut recovered2 = String::new();
5401 c_des.decrypt_vec_into_string(nonce, &cipher1, &mut recovered1);
5402 d_des.decrypt_vec_into_string(nonce, &cipher2, &mut recovered2);
5403 println!("B1 (0 rounds) =\t{}", recovered1);
5404 println!("B2 (0 rounds) =\t{}", recovered2);
5405 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
5406 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
5407 assert_eq!(recovered1, message);
5408 assert_eq!(recovered2, message);
5409 assert_eq!(recovered1, recovered2);
5410 println!();
5411
5412 // Normal case for the message of 0 bytes
5413 let key = 0x_1234567890ABCDEF_u64;
5414 println!("K =\t{:#016X}", key);
5415 let mut a_des = DES::new_with_key_u64(key);
5416
5417 let message = "";
5418 println!("M =\t{}", message);
5419 let nonce = 0x_FEDCBA0987654321_u64;
5420 println!("Nonce = {}", nonce);
5421 let mut cipher = Vec::<u8>::new();
5422 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5423 print!("C =\t");
5424 for c in cipher.clone()
5425 { print!("{:02X} ", c); }
5426 println!();
5427 let mut txt = String::new();
5428 for c in cipher.clone()
5429 { write!(txt, "{:02X} ", c); }
5430 assert_eq!(txt, "");
5431
5432 let mut recovered = String::new();
5433 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5434 println!("B =\t{}", recovered);
5435 assert_eq!(recovered, "");
5436 assert_eq!(recovered, message);
5437 println!();
5438
5439 // Normal case for the message shorter than 8 bytes
5440 let key = 0x_1234567890ABCDEF_u64;
5441 println!("K =\t{:#016X}", key);
5442 let mut a_des = DES::new_with_key_u64(key);
5443
5444 let message = "7 bytes";
5445 println!("M =\t{}", message);
5446 let nonce = 0x_FEDCBA0987654321_u64;
5447 println!("Nonce = {}", nonce);
5448 let mut cipher = Vec::<u8>::new();
5449 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5450 print!("C =\t");
5451 for c in cipher.clone()
5452 { print!("{:02X} ", c); }
5453 println!();
5454 let mut txt = String::new();
5455 for c in cipher.clone()
5456 { write!(txt, "{:02X} ", c); }
5457 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
5458
5459 let mut recovered = String::new();
5460 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5461 println!("B =\t{}", recovered);
5462 assert_eq!(recovered, "7 bytes");
5463 assert_eq!(recovered, message);
5464 println!();
5465
5466 // Normal case for the message of 8 bytes
5467 let key = 0x_1234567890ABCDEF_u64;
5468 println!("K =\t{:#016X}", key);
5469 let mut a_des = DES::new_with_key_u64(key);
5470
5471 let message = "I am OK.";
5472 println!("M =\t{}", message);
5473 let nonce = 0x_FEDCBA0987654321_u64;
5474 println!("Nonce = {}", nonce);
5475 let mut cipher = Vec::<u8>::new();
5476 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5477 print!("C =\t");
5478 for c in cipher.clone()
5479 { print!("{:02X} ", c); }
5480 println!();
5481 let mut txt = String::new();
5482 for c in cipher.clone()
5483 { write!(txt, "{:02X} ", c); }
5484 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
5485
5486 let mut recovered = String::new();
5487 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5488 println!("B =\t{}", recovered);
5489 assert_eq!(recovered, "I am OK.");
5490 assert_eq!(recovered, message);
5491 println!();
5492
5493 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5494 let key = 0x_1234567890ABCDEF_u64;
5495 println!("K =\t{:#016X}", key);
5496 let mut a_des = DES::new_with_key_u64(key);
5497
5498 let message = "PARK Youngho";
5499 println!("M =\t{}", message);
5500 let nonce = 0x_FEDCBA0987654321_u64;
5501 println!("Nonce = {}", nonce);
5502 let mut cipher = Vec::<u8>::new();
5503 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5504 print!("C =\t");
5505 for c in cipher.clone()
5506 { print!("{:02X} ", c); }
5507 println!();
5508 let mut txt = String::new();
5509 for c in cipher.clone()
5510 { write!(txt, "{:02X} ", c); }
5511 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
5512
5513 let mut recovered = String::new();
5514 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5515 println!("B =\t{}", recovered);
5516 assert_eq!(recovered, "PARK Youngho");
5517 assert_eq!(recovered, message);
5518 println!();
5519
5520 // Normal case for the message of 16 bytes
5521 let key = 0x_1234567890ABCDEF_u64;
5522 println!("K =\t{:#016X}", key);
5523 let mut a_des = DES::new_with_key_u64(key);
5524
5525 let message = "고맙습니다.";
5526 println!("M =\t{}", message);
5527 let nonce = 0x_FEDCBA0987654321_u64;
5528 println!("Nonce = {}", nonce);
5529 let mut cipher = Vec::<u8>::new();
5530 a_des.encrypt_str_into_vec(nonce, &message, &mut cipher);
5531 print!("C =\t");
5532 for c in cipher.clone()
5533 { print!("{:02X} ", c); }
5534 println!();
5535 let mut txt = String::new();
5536 for c in cipher.clone()
5537 { write!(txt, "{:02X} ", c); }
5538 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
5539
5540 let mut recovered = String::new();
5541 a_des.decrypt_vec_into_string(nonce, &cipher, &mut recovered);
5542 println!("B =\t{}", recovered);
5543 assert_eq!(recovered, "고맙습니다.");
5544 assert_eq!(recovered, message);
5545 println!("-------------------------------");
5546}
5547
5548fn des_decrypt_array_ctr()
5549{
5550 println!("des_decrypt_array_ctr()");
5551 use std::io::Write;
5552 use std::fmt::Write as _;
5553 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
5554
5555 // Normal case
5556 let key = 0x_1234567890ABCDEF_u64;
5557 println!("K =\t{:#016X}", key);
5558 let mut a_des = DES::new_with_key_u64(key);
5559
5560 let message = "In the beginning God created the heavens and the earth.";
5561 println!("M =\t{}", message);
5562 let nonce = 0x_FEDCBA0987654321_u64;
5563 println!("Nonce = {}", nonce);
5564 let mut cipher = [0_u8; 55];
5565 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5566 print!("C (16 rounds) =\t");
5567 for c in cipher.clone()
5568 { print!("{:02X} ", c); }
5569 println!();
5570 let mut txt = String::new();
5571 for c in cipher.clone()
5572 { write!(txt, "{:02X} ", c); }
5573 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
5574
5575 let mut recovered = vec![0; 55];
5576 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5577 recovered.truncate(len as usize);
5578 print!("Ba (16 rounds) =\t");
5579 for b in recovered.clone()
5580 { print!("{:02X} ", b); }
5581 println!();
5582 let mut txt = String::new();
5583 for c in recovered.clone()
5584 { write!(txt, "{:02X} ", c); }
5585 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5586
5587 let mut converted = String::new();
5588 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5589
5590 println!("Bb (16 rounds) =\t{}", converted);
5591 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5592 assert_eq!(converted, message);
5593 println!();
5594
5595 // Expanded case for 128 rounds
5596 let key = 0x_1234567890ABCDEF_u64;
5597 println!("K =\t{:#016X}", key);
5598 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5599
5600 let message = "In the beginning God created the heavens and the earth.";
5601 println!("M =\t{}", message);
5602 let nonce = 0x_FEDCBA0987654321_u64;
5603 println!("Nonce = {}", nonce);
5604 let mut cipher = [0_u8; 55];
5605 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5606 print!("C (128 rounds) =\t");
5607 for c in cipher.clone()
5608 { print!("{:02X} ", c); }
5609 println!();
5610 let mut txt = String::new();
5611 for c in cipher.clone()
5612 { write!(txt, "{:02X} ", c); }
5613 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
5614
5615 let mut recovered = vec![0; 55];
5616 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5617 recovered.truncate(len as usize);
5618 print!("Ba (128 rounds) =\t");
5619 for b in recovered.clone()
5620 { print!("{:02X} ", b); }
5621 println!();
5622 let mut txt = String::new();
5623 for c in recovered.clone()
5624 { write!(txt, "{:02X} ", c); }
5625 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5626
5627 let mut converted = String::new();
5628 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5629
5630 println!("Bb (128 rounds) =\t{}", converted);
5631 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5632 assert_eq!(converted, message);
5633 println!();
5634
5635 // Expanded case for 0 rounds which means that key is meaningless
5636 let key1 = 0x_1234567890ABCDEF_u64;
5637 let key2 = 0_u64;
5638 println!("K =\t{:#016X}", key);
5639 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
5640 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
5641
5642 let message = "In the beginning God created the heavens and the earth.";
5643 println!("M =\t{}", message);
5644 let nonce = 0x_FEDCBA0987654321_u64;
5645 println!("Nonce = {}", nonce);
5646 let mut cipher1 = [0_u8; 55];
5647 let mut cipher2 = [0_u8; 55];
5648 c_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
5649 d_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
5650 print!("C (0 rounds) =\t");
5651 for c in cipher1.clone()
5652 { print!("{:02X} ", c); }
5653 println!();
5654 let mut txt = String::new();
5655 for c in cipher1.clone()
5656 { write!(txt, "{:02X} ", c); }
5657 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
5658 print!("D (0 rounds) =\t");
5659 for c in cipher2.clone()
5660 { print!("{:02X} ", c); }
5661 println!();
5662 let mut txt = String::new();
5663 for c in cipher2.clone()
5664 { write!(txt, "{:02X} ", c); }
5665 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
5666
5667 let mut recovered1 = vec![0; 55];
5668 let mut recovered2 = vec![0; 55];
5669 let len1 = c_des.decrypt_array(nonce, &cipher1, recovered1.as_mut_ptr());
5670 let len2 = d_des.decrypt_array(nonce, &cipher2, recovered2.as_mut_ptr());
5671 recovered1.truncate(len1 as usize);
5672 recovered2.truncate(len2 as usize);
5673
5674 print!("B1a (0 rounds) =\t");
5675 for b in recovered1.clone()
5676 { print!("{:02X} ", b); }
5677 println!();
5678 let mut txt = String::new();
5679 for c in recovered1.clone()
5680 { write!(txt, "{:02X} ", c); }
5681 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5682 print!("B2a (0 rounds) =\t");
5683 for b in recovered2.clone()
5684 { print!("{:02X} ", b); }
5685 println!();
5686 let mut txt = String::new();
5687 for c in recovered2.clone()
5688 { write!(txt, "{:02X} ", c); }
5689 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5690
5691 let mut converted1 = String::new();
5692 let mut converted2 = String::new();
5693 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
5694 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
5695
5696 println!("B1b (0 rounds) =\t{}", converted1);
5697 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
5698 assert_eq!(converted1, message);
5699 println!("B2b (0 rounds) =\t{}", converted2);
5700 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
5701 assert_eq!(converted2, message);
5702 assert_eq!(converted1, converted1);
5703 println!();
5704
5705 // Normal case for the message of 0 bytes
5706 let key = 0x_1234567890ABCDEF_u64;
5707 println!("K =\t{:#016X}", key);
5708 let mut a_des = DES::new_with_key_u64(key);
5709
5710 let message = "";
5711 println!("M =\t{}", message);
5712 let nonce = 0x_FEDCBA0987654321_u64;
5713 println!("Nonce = {}", nonce);
5714 let mut cipher = [0_u8; 0];
5715 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5716 print!("C =\t");
5717 for c in cipher.clone()
5718 { print!("{:02X} ", c); }
5719 println!();
5720 let mut txt = String::new();
5721 for c in cipher.clone()
5722 { write!(txt, "{:02X} ", c); }
5723 assert_eq!(txt, "");
5724
5725 let mut recovered = vec![0; 8];
5726 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5727 recovered.truncate(len as usize);
5728
5729 print!("Ba =\t");
5730 for b in recovered.clone()
5731 { print!("{:02X} ", b); }
5732 println!();
5733 let mut txt = String::new();
5734 for c in recovered.clone()
5735 { write!(txt, "{:02X} ", c); }
5736 assert_eq!(txt, "");
5737
5738 let mut converted = String::new();
5739 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5740
5741 println!("Bb =\t{}", converted);
5742 assert_eq!(converted, "");
5743 assert_eq!(converted, message);
5744 println!();
5745
5746 // Normal case for the message shorter than 8 bytes
5747 let key = 0x_1234567890ABCDEF_u64;
5748 println!("K =\t{:#016X}", key);
5749 let mut a_des = DES::new_with_key_u64(key);
5750
5751 let message = "7 bytes";
5752 println!("M =\t{}", message);
5753 let nonce = 0x_FEDCBA0987654321_u64;
5754 println!("Nonce = {}", nonce);
5755 let mut cipher = [0_u8; 7];
5756 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5757 print!("C =\t");
5758 for c in cipher.clone()
5759 { print!("{:02X} ", c); }
5760 println!();
5761 let mut txt = String::new();
5762 for c in cipher.clone()
5763 { write!(txt, "{:02X} ", c); }
5764 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
5765
5766 let mut recovered = vec![0; 8];
5767 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5768 recovered.truncate(len as usize);
5769
5770 print!("Ba =\t");
5771 for b in recovered.clone()
5772 { print!("{:02X} ", b); }
5773 println!();
5774 let mut txt = String::new();
5775 for c in recovered.clone()
5776 { write!(txt, "{:02X} ", c); }
5777 assert_eq!(txt, "37 20 62 79 74 65 73 ");
5778
5779 let mut converted = String::new();
5780 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5781
5782 println!("Bb =\t{}", converted);
5783 assert_eq!(converted, "7 bytes");
5784 assert_eq!(converted, message);
5785 println!();
5786
5787 // Normal case for the message of 8 bytes
5788 let key = 0x_1234567890ABCDEF_u64;
5789 println!("K =\t{:#016X}", key);
5790 let mut a_des = DES::new_with_key_u64(key);
5791
5792 let message = "I am OK.";
5793 println!("M =\t{}", message);
5794 let nonce = 0x_FEDCBA0987654321_u64;
5795 println!("Nonce = {}", nonce);
5796 let mut cipher = [0_u8; 8];
5797 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5798 print!("C =\t");
5799 for c in cipher.clone()
5800 { print!("{:02X} ", c); }
5801 println!();
5802 let mut txt = String::new();
5803 for c in cipher.clone()
5804 { write!(txt, "{:02X} ", c); }
5805 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
5806
5807 let mut recovered = vec![0; 16];
5808 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5809 recovered.truncate(len as usize);
5810
5811 print!("Ba =\t");
5812 for b in recovered.clone()
5813 { print!("{:02X} ", b); }
5814 println!();
5815 let mut txt = String::new();
5816 for c in recovered.clone()
5817 { write!(txt, "{:02X} ", c); }
5818 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
5819
5820 let mut converted = String::new();
5821 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5822
5823 println!("Bb =\t{}", converted);
5824 assert_eq!(converted, "I am OK.");
5825 assert_eq!(converted, message);
5826 println!();
5827
5828 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
5829 let key = 0x_1234567890ABCDEF_u64;
5830 println!("K =\t{:#016X}", key);
5831 let mut a_des = DES::new_with_key_u64(key);
5832
5833 let message = "PARK Youngho";
5834 println!("M =\t{}", message);
5835 let nonce = 0x_FEDCBA0987654321_u64;
5836 println!("Nonce = {}", nonce);
5837 let mut cipher = [0_u8; 12];
5838 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5839 print!("C =\t");
5840 for c in cipher.clone()
5841 { print!("{:02X} ", c); }
5842 println!();
5843 let mut txt = String::new();
5844 for c in cipher.clone()
5845 { write!(txt, "{:02X} ", c); }
5846 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
5847
5848 let mut recovered = vec![0; 16];
5849 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5850 recovered.truncate(len as usize);
5851 print!("Ba =\t");
5852 for b in recovered.clone()
5853 { print!("{:02X} ", b); }
5854 println!();
5855 let mut txt = String::new();
5856 for c in recovered.clone()
5857 { write!(txt, "{:02X} ", c); }
5858 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
5859
5860 let mut converted = String::new();
5861 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5862
5863 println!("Bb =\t{}", converted);
5864 assert_eq!(converted, "PARK Youngho");
5865 assert_eq!(converted, message);
5866 println!();
5867
5868 // Normal case for the message of 16 bytes
5869 let key = 0x_1234567890ABCDEF_u64;
5870 println!("K =\t{:#016X}", key);
5871 let mut a_des = DES::new_with_key_u64(key);
5872
5873 let message = "고맙습니다.";
5874 println!("M =\t{}", message);
5875 let nonce = 0x_FEDCBA0987654321_u64;
5876 println!("Nonce = {}", nonce);
5877 let mut cipher = [0_u8; 16];
5878 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5879 print!("C =\t");
5880 for c in cipher.clone()
5881 { print!("{:02X} ", c); }
5882 println!();
5883 let mut txt = String::new();
5884 for c in cipher.clone()
5885 { write!(txt, "{:02X} ", c); }
5886 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
5887
5888 let mut recovered = vec![0; 24];
5889 let len = a_des.decrypt_array(nonce, &cipher, recovered.as_mut_ptr());
5890 recovered.truncate(len as usize);
5891
5892 print!("Ba =\t");
5893 for b in recovered.clone()
5894 { print!("{:02X} ", b); }
5895 println!();
5896 let mut txt = String::new();
5897 for c in recovered.clone()
5898 { write!(txt, "{:02X} ", c); }
5899 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
5900
5901 let mut converted = String::new();
5902 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5903
5904 println!("Bb =\t{}", converted);
5905 assert_eq!(converted, "고맙습니다.");
5906 assert_eq!(converted, message);
5907 println!("-------------------------------");
5908}
5909
5910fn des_decrypt_array_ctr_into_vec()
5911{
5912 println!("des_decrypt_array_ctr_into_vec()");
5913 use std::io::Write;
5914 use std::fmt::Write as _;
5915 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
5916
5917 // Normal case
5918 let key = 0x_1234567890ABCDEF_u64;
5919 println!("K =\t{:#016X}", key);
5920 let mut a_des = DES::new_with_key_u64(key);
5921
5922 let message = "In the beginning God created the heavens and the earth.";
5923 println!("M =\t{}", message);
5924 let nonce = 0x_FEDCBA0987654321_u64;
5925 println!("Nonce = {}", nonce);
5926 let mut cipher = [0_u8; 55];
5927 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5928 print!("C (16 rounds) =\t");
5929 for c in cipher.clone()
5930 { print!("{:02X} ", c); }
5931 println!();
5932 let mut txt = String::new();
5933 for c in cipher.clone()
5934 { write!(txt, "{:02X} ", c); }
5935 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
5936
5937 let mut recovered = Vec::<u8>::new();
5938 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
5939 print!("Ba (16 rounds) =\t");
5940 for b in recovered.clone()
5941 { print!("{:02X} ", b); }
5942 println!();
5943 let mut txt = String::new();
5944 for c in recovered.clone()
5945 { write!(txt, "{:02X} ", c); }
5946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5947
5948 let mut converted = String::new();
5949 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5950
5951 println!("Bb (16 rounds) =\t{}", converted);
5952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5953 assert_eq!(converted, message);
5954 println!();
5955
5956 // Expanded case for 128 rounds
5957 let key = 0x_1234567890ABCDEF_u64;
5958 println!("K =\t{:#016X}", key);
5959 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
5960
5961 let message = "In the beginning God created the heavens and the earth.";
5962 println!("M =\t{}", message);
5963 let nonce = 0x_FEDCBA0987654321_u64;
5964 println!("Nonce = {}", nonce);
5965 let mut cipher = [0_u8; 55];
5966 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
5967 print!("C (128 rounds) =\t");
5968 for c in cipher.clone()
5969 { print!("{:02X} ", c); }
5970 println!();
5971 let mut txt = String::new();
5972 for c in cipher.clone()
5973 { write!(txt, "{:02X} ", c); }
5974 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
5975
5976 let mut recovered = Vec::<u8>::new();
5977 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
5978 print!("Ba (128 rounds) =\t");
5979 for b in recovered.clone()
5980 { print!("{:02X} ", b); }
5981 println!();
5982 let mut txt = String::new();
5983 for c in recovered.clone()
5984 { write!(txt, "{:02X} ", c); }
5985 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
5986
5987 let mut converted = String::new();
5988 unsafe { converted.as_mut_vec() }.append(&mut recovered);
5989
5990 println!("Bb (128 rounds) =\t{}", converted);
5991 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
5992 assert_eq!(converted, message);
5993 println!();
5994
5995 // Expanded case for 0 rounds which means that key is meaningless
5996 let key1 = 0x_1234567890ABCDEF_u64;
5997 let key2 = 0_u64;
5998 println!("K =\t{:#016X}", key);
5999 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6000 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6001
6002 let message = "In the beginning God created the heavens and the earth.";
6003 println!("M =\t{}", message);
6004 let nonce = 0x_FEDCBA0987654321_u64;
6005 println!("Nonce = {}", nonce);
6006 let mut cipher1 = [0_u8; 55];
6007 let mut cipher2 = [0_u8; 55];
6008 c_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
6009 d_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
6010 print!("C (0 rounds) =\t");
6011 for c in cipher1.clone()
6012 { print!("{:02X} ", c); }
6013 println!();
6014 let mut txt = String::new();
6015 for c in cipher1.clone()
6016 { write!(txt, "{:02X} ", c); }
6017 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
6018 print!("D (0 rounds) =\t");
6019 for c in cipher2.clone()
6020 { print!("{:02X} ", c); }
6021 println!();
6022 let mut txt = String::new();
6023 for c in cipher2.clone()
6024 { write!(txt, "{:02X} ", c); }
6025 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
6026
6027 let mut recovered1 = Vec::<u8>::new();
6028 let mut recovered2 = Vec::<u8>::new();
6029 c_des.decrypt_array_into_vec(nonce, &cipher1, &mut recovered1);
6030 d_des.decrypt_array_into_vec(nonce, &cipher2, &mut recovered2);
6031 print!("B1a (0 rounds) =\t");
6032 for b in recovered1.clone()
6033 { print!("{:02X} ", b); }
6034 println!();
6035 let mut txt = String::new();
6036 for c in recovered1.clone()
6037 { write!(txt, "{:02X} ", c); }
6038 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
6039 print!("B2a (0 rounds) =\t");
6040 for b in recovered2.clone()
6041 { print!("{:02X} ", b); }
6042 println!();
6043 let mut txt = String::new();
6044 for c in recovered2.clone()
6045 { write!(txt, "{:02X} ", c); }
6046 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
6047
6048 let mut converted1 = String::new();
6049 let mut converted2 = String::new();
6050 unsafe { converted1.as_mut_vec() }.append(&mut recovered1);
6051 unsafe { converted2.as_mut_vec() }.append(&mut recovered2);
6052
6053 println!("B1b (0 rounds) =\t{}", converted1);
6054 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6055 assert_eq!(converted1, message);
6056 println!("B2b (0 rounds) =\t{}", converted2);
6057 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6058 assert_eq!(converted2, message);
6059 assert_eq!(converted1, converted1);
6060 println!();
6061
6062 // Normal case for the message of 0 bytes
6063 let key = 0x_1234567890ABCDEF_u64;
6064 println!("K =\t{:#016X}", key);
6065 let mut a_des = DES::new_with_key_u64(key);
6066
6067 let message = "";
6068 println!("M =\t{}", message);
6069 let nonce = 0x_FEDCBA0987654321_u64;
6070 println!("Nonce = {}", nonce);
6071 let mut cipher = [0_u8; 0];
6072 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6073 print!("C =\t");
6074 for c in cipher.clone()
6075 { print!("{:02X} ", c); }
6076 println!();
6077 let mut txt = String::new();
6078 for c in cipher.clone()
6079 { write!(txt, "{:02X} ", c); }
6080 assert_eq!(txt, "");
6081
6082 let mut recovered = Vec::<u8>::new();
6083 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
6084 print!("Ba =\t");
6085 for b in recovered.clone()
6086 { print!("{:02X} ", b); }
6087 println!();
6088 let mut txt = String::new();
6089 for c in recovered.clone()
6090 { write!(txt, "{:02X} ", c); }
6091 assert_eq!(txt, "");
6092
6093 let mut converted = String::new();
6094 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6095
6096 println!("Bb =\t{}", converted);
6097 assert_eq!(converted, "");
6098 assert_eq!(converted, message);
6099 println!();
6100
6101 // Normal case for the message shorter than 8 bytes
6102 let key = 0x_1234567890ABCDEF_u64;
6103 println!("K =\t{:#016X}", key);
6104 let mut a_des = DES::new_with_key_u64(key);
6105
6106 let message = "7 bytes";
6107 println!("M =\t{}", message);
6108 let nonce = 0x_FEDCBA0987654321_u64;
6109 println!("Nonce = {}", nonce);
6110 let mut cipher = [0_u8; 7];
6111 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6112 print!("C =\t");
6113 for c in cipher.clone()
6114 { print!("{:02X} ", c); }
6115 println!();
6116 let mut txt = String::new();
6117 for c in cipher.clone()
6118 { write!(txt, "{:02X} ", c); }
6119 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
6120
6121 let mut recovered = Vec::<u8>::new();
6122 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
6123 print!("Ba =\t");
6124 for b in recovered.clone()
6125 { print!("{:02X} ", b); }
6126 println!();
6127 let mut txt = String::new();
6128 for c in recovered.clone()
6129 { write!(txt, "{:02X} ", c); }
6130 assert_eq!(txt, "37 20 62 79 74 65 73 ");
6131
6132 let mut converted = String::new();
6133 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6134
6135 println!("Bb =\t{}", converted);
6136 assert_eq!(converted, "7 bytes");
6137 assert_eq!(converted, message);
6138 println!();
6139
6140 // Normal case for the message of 8 bytes
6141 let key = 0x_1234567890ABCDEF_u64;
6142 println!("K =\t{:#016X}", key);
6143 let mut a_des = DES::new_with_key_u64(key);
6144
6145 let message = "I am OK.";
6146 println!("M =\t{}", message);
6147 let nonce = 0x_FEDCBA0987654321_u64;
6148 println!("Nonce = {}", nonce);
6149 let mut cipher = [0_u8; 8];
6150 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6151 print!("C =\t");
6152 for c in cipher.clone()
6153 { print!("{:02X} ", c); }
6154 println!();
6155 let mut txt = String::new();
6156 for c in cipher.clone()
6157 { write!(txt, "{:02X} ", c); }
6158 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
6159
6160 let mut recovered = Vec::<u8>::new();
6161 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
6162 print!("Ba =\t");
6163 for b in recovered.clone()
6164 { print!("{:02X} ", b); }
6165 println!();
6166 let mut txt = String::new();
6167 for c in recovered.clone()
6168 { write!(txt, "{:02X} ", c); }
6169 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
6170
6171 let mut converted = String::new();
6172 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6173
6174 println!("Bb =\t{}", converted);
6175 assert_eq!(converted, "I am OK.");
6176 assert_eq!(converted, message);
6177 println!();
6178
6179 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6180 let key = 0x_1234567890ABCDEF_u64;
6181 println!("K =\t{:#016X}", key);
6182 let mut a_des = DES::new_with_key_u64(key);
6183
6184 let message = "PARK Youngho";
6185 println!("M =\t{}", message);
6186 let nonce = 0x_FEDCBA0987654321_u64;
6187 println!("Nonce = {}", nonce);
6188 let mut cipher = [0_u8; 12];
6189 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6190 print!("C =\t");
6191 for c in cipher.clone()
6192 { print!("{:02X} ", c); }
6193 println!();
6194 let mut txt = String::new();
6195 for c in cipher.clone()
6196 { write!(txt, "{:02X} ", c); }
6197 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
6198
6199 let mut recovered = Vec::<u8>::new();
6200 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
6201 print!("Ba =\t");
6202 for b in recovered.clone()
6203 { print!("{:02X} ", b); }
6204 println!();
6205 let mut txt = String::new();
6206 for c in recovered.clone()
6207 { write!(txt, "{:02X} ", c); }
6208 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F ");
6209
6210 let mut converted = String::new();
6211 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6212
6213 println!("Bb =\t{}", converted);
6214 assert_eq!(converted, "PARK Youngho");
6215 assert_eq!(converted, message);
6216 println!();
6217
6218 // Normal case for the message of 16 bytes
6219 let key = 0x_1234567890ABCDEF_u64;
6220 println!("K =\t{:#016X}", key);
6221 let mut a_des = DES::new_with_key_u64(key);
6222
6223 let message = "고맙습니다.";
6224 println!("M =\t{}", message);
6225 let nonce = 0x_FEDCBA0987654321_u64;
6226 println!("Nonce = {}", nonce);
6227 let mut cipher = [0_u8; 16];
6228 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6229 print!("C =\t");
6230 for c in cipher.clone()
6231 { print!("{:02X} ", c); }
6232 println!();
6233 let mut txt = String::new();
6234 for c in cipher.clone()
6235 { write!(txt, "{:02X} ", c); }
6236 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
6237
6238 let mut recovered = Vec::<u8>::new();
6239 a_des.decrypt_array_into_vec(nonce, &cipher, &mut recovered);
6240 print!("Ba =\t");
6241 for b in recovered.clone()
6242 { print!("{:02X} ", b); }
6243 println!();
6244 let mut txt = String::new();
6245 for c in recovered.clone()
6246 { write!(txt, "{:02X} ", c); }
6247 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E ");
6248
6249 let mut converted = String::new();
6250 unsafe { converted.as_mut_vec() }.append(&mut recovered);
6251
6252 println!("Bb =\t{}", converted);
6253 assert_eq!(converted, "고맙습니다.");
6254 assert_eq!(converted, message);
6255 println!("-------------------------------");
6256}
6257
6258fn des_decrypt_array_ctr_into_array()
6259{
6260 println!("des_decrypt_array_ctr_into_array()");
6261 use std::io::Write;
6262 use std::fmt::Write as _;
6263 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
6264
6265 // Normal case
6266 let key = 0x_1234567890ABCDEF_u64;
6267 println!("K =\t{:#016X}", key);
6268 let mut a_des = DES::new_with_key_u64(key);
6269
6270 let message = "In the beginning God created the heavens and the earth.";
6271 println!("M =\t{}", message);
6272 let nonce = 0x_FEDCBA0987654321_u64;
6273 println!("Nonce = {}", nonce);
6274 let mut cipher = [0_u8; 55];
6275 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6276 print!("C (16 rounds) =\t");
6277 for c in cipher.clone()
6278 { print!("{:02X} ", c); }
6279 println!();
6280 let mut txt = String::new();
6281 for c in cipher.clone()
6282 { write!(txt, "{:02X} ", c); }
6283 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
6284
6285 let mut recovered = [0u8; 56];
6286 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6287 print!("Ba (16 rounds) =\t");
6288 for b in recovered.clone()
6289 { print!("{:02X} ", b); }
6290 println!();
6291 let mut txt = String::new();
6292 for c in recovered.clone()
6293 { write!(txt, "{:02X} ", c); }
6294 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6295
6296 let mut converted = String::new();
6297 unsafe { converted.as_mut_vec() }.write(&recovered);
6298 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6299 println!("Bb (16 rounds) =\t{}", converted);
6300 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
6301 assert_eq!(converted, message);
6302 println!();
6303
6304 // Expanded case for 128 rounds
6305 let key = 0x_1234567890ABCDEF_u64;
6306 println!("K =\t{:#016X}", key);
6307 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6308
6309 let message = "In the beginning God created the heavens and the earth.";
6310 println!("M =\t{}", message);
6311 let nonce = 0x_FEDCBA0987654321_u64;
6312 println!("Nonce = {}", nonce);
6313 let mut cipher = [0_u8; 55];
6314 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6315 print!("C (128 rounds) =\t");
6316 for c in cipher.clone()
6317 { print!("{:02X} ", c); }
6318 println!();
6319 let mut txt = String::new();
6320 for c in cipher.clone()
6321 { write!(txt, "{:02X} ", c); }
6322 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
6323
6324 let mut recovered = [0u8; 56];
6325 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6326 print!("Ba (16 rounds) =\t");
6327 for b in recovered.clone()
6328 { print!("{:02X} ", b); }
6329 println!();
6330 let mut txt = String::new();
6331 for c in recovered.clone()
6332 { write!(txt, "{:02X} ", c); }
6333 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6334
6335 let mut converted = String::new();
6336 unsafe { converted.as_mut_vec() }.write(&recovered);
6337 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6338 println!("Bb (16 rounds) =\t{}", converted);
6339 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
6340 assert_eq!(converted, message);
6341 println!();
6342
6343 // Expanded case for 0 rounds which means that key is meaningless
6344 let key1 = 0x_1234567890ABCDEF_u64;
6345 let key2 = 0_u64;
6346 println!("K =\t{:#016X}", key);
6347 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6348 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6349
6350 let message = "In the beginning God created the heavens and the earth.";
6351 println!("M =\t{}", message);
6352 let nonce = 0x_FEDCBA0987654321_u64;
6353 println!("Nonce = {}", nonce);
6354 let mut cipher1 = [0_u8; 55];
6355 let mut cipher2 = [0_u8; 55];
6356 c_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
6357 d_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
6358 print!("C (0 rounds) =\t");
6359 for c in cipher1.clone()
6360 { print!("{:02X} ", c); }
6361 println!();
6362 let mut txt = String::new();
6363 for c in cipher1.clone()
6364 { write!(txt, "{:02X} ", c); }
6365 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
6366 print!("D (0 rounds) =\t");
6367 for c in cipher2.clone()
6368 { print!("{:02X} ", c); }
6369 println!();
6370 let mut txt = String::new();
6371 for c in cipher2.clone()
6372 { write!(txt, "{:02X} ", c); }
6373 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
6374
6375 let mut recovered1 = [0u8; 56];
6376 let mut recovered2 = [0u8; 56];
6377 let len1 = c_des.decrypt_array_into_array(nonce, &cipher1, &mut recovered1);
6378 let len2 = d_des.decrypt_array_into_array(nonce, &cipher2, &mut recovered2);
6379 print!("B1a (0 rounds) =\t");
6380 for b in recovered1.clone()
6381 { print!("{:02X} ", b); }
6382 println!();
6383 let mut txt = String::new();
6384 for c in recovered1.clone()
6385 { write!(txt, "{:02X} ", c); }
6386 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6387 print!("B2a (0 rounds) =\t");
6388 for b in recovered2.clone()
6389 { print!("{:02X} ", b); }
6390 println!();
6391 let mut txt = String::new();
6392 for c in recovered.clone()
6393 { write!(txt, "{:02X} ", c); }
6394 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
6395
6396 let mut converted1 = String::new();
6397 let mut converted2 = String::new();
6398 unsafe { converted1.as_mut_vec() }.write(&recovered1);
6399 unsafe { converted2.as_mut_vec() }.write(&recovered2);
6400 unsafe { converted1.as_mut_vec() }.truncate(len1 as usize);
6401 unsafe { converted2.as_mut_vec() }.truncate(len2 as usize);
6402 println!("B1b (0 rounds) =\t{}", converted1);
6403 println!("B2b (0 rounds) =\t{}", converted2);
6404 assert_eq!(converted1, "In the beginning God created the heavens and the earth.");
6405 assert_eq!(converted2, "In the beginning God created the heavens and the earth.");
6406 assert_eq!(converted1, message);
6407 assert_eq!(converted2, message);
6408 assert_eq!(converted1, converted2);
6409 println!();
6410
6411 // Normal case for the message of 0 bytes
6412 let key = 0x_1234567890ABCDEF_u64;
6413 println!("K =\t{:#016X}", key);
6414 let mut a_des = DES::new_with_key_u64(key);
6415
6416 let message = "";
6417 println!("M =\t{}", message);
6418 let nonce = 0x_FEDCBA0987654321_u64;
6419 println!("Nonce = {}", nonce);
6420 let mut cipher = [0_u8; 0];
6421 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6422 print!("C =\t");
6423 for c in cipher.clone()
6424 { print!("{:02X} ", c); }
6425 println!();
6426 let mut txt = String::new();
6427 for c in cipher.clone()
6428 { write!(txt, "{:02X} ", c); }
6429 assert_eq!(txt, "");
6430
6431 let mut recovered = [0u8; 8];
6432 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6433
6434 print!("Ba =\t");
6435 for b in recovered.clone()
6436 { print!("{:02X} ", b); }
6437 println!();
6438 let mut txt = String::new();
6439 for c in recovered.clone()
6440 { write!(txt, "{:02X} ", c); }
6441 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
6442
6443 let mut converted = String::new();
6444 unsafe { converted.as_mut_vec() }.write(&recovered);
6445 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6446 println!("Bb =\t{}", converted);
6447 assert_eq!(converted, "");
6448 assert_eq!(converted, message);
6449 println!();
6450
6451 // Normal case for the message shorter than 8 bytes
6452 let key = 0x_1234567890ABCDEF_u64;
6453 println!("K =\t{:#016X}", key);
6454 let mut a_des = DES::new_with_key_u64(key);
6455
6456 let message = "7 bytes";
6457 println!("M =\t{}", message);
6458 let nonce = 0x_FEDCBA0987654321_u64;
6459 println!("Nonce = {}", nonce);
6460 let mut cipher = [0_u8; 7];
6461 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6462 print!("C =\t");
6463 for c in cipher.clone()
6464 { print!("{:02X} ", c); }
6465 println!();
6466 let mut txt = String::new();
6467 for c in cipher.clone()
6468 { write!(txt, "{:02X} ", c); }
6469 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
6470
6471 let mut recovered = [0u8; 8];
6472 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6473
6474 print!("Ba =\t");
6475 for b in recovered.clone()
6476 { print!("{:02X} ", b); }
6477 println!();
6478 let mut txt = String::new();
6479 for c in recovered.clone()
6480 { write!(txt, "{:02X} ", c); }
6481 assert_eq!(txt, "37 20 62 79 74 65 73 00 ");
6482
6483 let mut converted = String::new();
6484 unsafe { converted.as_mut_vec() }.write(&recovered);
6485 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6486 println!("Bb =\t{}", converted);
6487 assert_eq!(converted, "7 bytes");
6488 assert_eq!(converted, message);
6489 println!();
6490
6491 // Normal case for the message of 8 bytes
6492 let key = 0x_1234567890ABCDEF_u64;
6493 println!("K =\t{:#016X}", key);
6494 let mut a_des = DES::new_with_key_u64(key);
6495
6496 let message = "I am OK.";
6497 println!("M =\t{}", message);
6498 let nonce = 0x_FEDCBA0987654321_u64;
6499 println!("Nonce = {}", nonce);
6500 let mut cipher = [0_u8; 8];
6501 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6502 print!("C =\t");
6503 for c in cipher.clone()
6504 { print!("{:02X} ", c); }
6505 println!();
6506 let mut txt = String::new();
6507 for c in cipher.clone()
6508 { write!(txt, "{:02X} ", c); }
6509 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
6510
6511 let mut recovered = [0u8; 16];
6512 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6513
6514 print!("Ba =\t");
6515 for b in recovered.clone()
6516 { print!("{:02X} ", b); }
6517 println!();
6518 let mut txt = String::new();
6519 for c in recovered.clone()
6520 { write!(txt, "{:02X} ", c); }
6521 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E 00 00 00 00 00 00 00 00 ");
6522
6523 let mut converted = String::new();
6524 unsafe { converted.as_mut_vec() }.write(&recovered);
6525 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6526 println!("Bb =\t{}", converted);
6527 assert_eq!(converted, "I am OK.");
6528 assert_eq!(converted, message);
6529 println!();
6530
6531 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6532 let key = 0x_1234567890ABCDEF_u64;
6533 println!("K =\t{:#016X}", key);
6534 let mut a_des = DES::new_with_key_u64(key);
6535
6536 let message = "PARK Youngho";
6537 println!("M =\t{}", message);
6538 let nonce = 0x_FEDCBA0987654321_u64;
6539 println!("Nonce = {}", nonce);
6540 let mut cipher = [0_u8; 12];
6541 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6542 print!("C =\t");
6543 for c in cipher.clone()
6544 { print!("{:02X} ", c); }
6545 println!();
6546 let mut txt = String::new();
6547 for c in cipher.clone()
6548 { write!(txt, "{:02X} ", c); }
6549 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
6550
6551 let mut recovered = [0u8; 16];
6552 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6553
6554 print!("Ba =\t");
6555 for b in recovered.clone()
6556 { print!("{:02X} ", b); }
6557 println!();
6558 let mut txt = String::new();
6559 for c in recovered.clone()
6560 { write!(txt, "{:02X} ", c); }
6561 assert_eq!(txt, "50 41 52 4B 20 59 6F 75 6E 67 68 6F 00 00 00 00 ");
6562
6563 let mut converted = String::new();
6564 unsafe { converted.as_mut_vec() }.write(&recovered);
6565 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6566 println!("Bb =\t{}", converted);
6567 assert_eq!(converted, "PARK Youngho");
6568 assert_eq!(converted, message);
6569 println!();
6570
6571 // Normal case for the message of 16 bytes
6572 let key = 0x_1234567890ABCDEF_u64;
6573 println!("K =\t{:#016X}", key);
6574 let mut a_des = DES::new_with_key_u64(key);
6575
6576 let message = "고맙습니다.";
6577 println!("M =\t{}", message);
6578 let nonce = 0x_FEDCBA0987654321_u64;
6579 println!("Nonce = {}", nonce);
6580 let mut cipher = [0_u8; 16];
6581 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6582 print!("C =\t");
6583 for c in cipher.clone()
6584 { print!("{:02X} ", c); }
6585 println!();
6586 let mut txt = String::new();
6587 for c in cipher.clone()
6588 { write!(txt, "{:02X} ", c); }
6589 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
6590
6591 let mut recovered = [0u8; 24];
6592 let len = a_des.decrypt_array_into_array(nonce, &cipher, &mut recovered);
6593
6594 print!("Ba =\t");
6595 for b in recovered.clone()
6596 { print!("{:02X} ", b); }
6597 println!();
6598 let mut txt = String::new();
6599 for c in recovered.clone()
6600 { write!(txt, "{:02X} ", c); }
6601 assert_eq!(txt, "EA B3 A0 EB A7 99 EC 8A B5 EB 8B 88 EB 8B A4 2E 00 00 00 00 00 00 00 00 ");
6602
6603 let mut converted = String::new();
6604 unsafe { converted.as_mut_vec() }.write(&recovered);
6605 unsafe { converted.as_mut_vec() }.truncate(len as usize);
6606 println!("Bb =\t{}", converted);
6607 assert_eq!(converted, "고맙습니다.");
6608 assert_eq!(converted, message);
6609 println!("-------------------------------");
6610}
6611
6612fn des_decrypt_array_ctr_into_string()
6613{
6614 println!("des_decrypt_array_ctr_into_string()");
6615 use std::io::Write;
6616 use std::fmt::Write as _;
6617 use cryptocol::symmetric::{ DES, DES_Expanded, CTR };
6618
6619 // Normal case
6620 let key = 0x_1234567890ABCDEF_u64;
6621 println!("K =\t{:#016X}", key);
6622 let mut a_des = DES::new_with_key_u64(key);
6623
6624 let message = "In the beginning God created the heavens and the earth.";
6625 println!("M =\t{}", message);
6626 let nonce = 0x_FEDCBA0987654321_u64;
6627 println!("Nonce = {}", nonce);
6628 let mut cipher = [0_u8; 55];
6629 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6630 print!("C (16 rounds) =\t");
6631 for c in cipher.clone()
6632 { print!("{:02X} ", c); }
6633 println!();
6634 let mut txt = String::new();
6635 for c in cipher.clone()
6636 { write!(txt, "{:02X} ", c); }
6637 assert_eq!(txt, "30 50 6F 31 60 BA 91 7E D0 DE 38 A6 FD 50 DE BC F5 BF CA 3D A4 15 03 C5 2A 8B 35 94 F9 1B 0B 64 FE C4 32 98 5B 3B 20 FC DE B6 88 E4 BD 4E 7D 8E 5A E8 41 79 F0 DC 2E ");
6638
6639 let mut recovered = String::new();
6640 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6641 println!("B (16 rounds) =\t{}", recovered);
6642 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6643 assert_eq!(recovered, message);
6644 println!();
6645
6646 // Expanded case for 128 rounds
6647 let key = 0x_1234567890ABCDEF_u64;
6648 println!("K =\t{:#016X}", key);
6649 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
6650
6651 let message = "In the beginning God created the heavens and the earth.";
6652 println!("M =\t{}", message);
6653 let nonce = 0x_FEDCBA0987654321_u64;
6654 println!("Nonce = {}", nonce);
6655 let mut cipher = [0_u8; 55];
6656 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6657 print!("C (128 rounds) =\t");
6658 for c in cipher.clone()
6659 { print!("{:02X} ", c); }
6660 println!();
6661 let mut txt = String::new();
6662 for c in cipher.clone()
6663 { write!(txt, "{:02X} ", c); }
6664 assert_eq!(txt, "FA 29 57 1F C9 60 9F 98 4C 48 14 62 7B 72 B4 D6 5D 09 1F C8 FB CE 1C 86 92 DF E2 3E 3F 91 75 62 F8 47 77 BB 86 8A 7D F0 BF E9 E4 52 EC 4D 42 F6 D4 7B 41 19 43 C5 5B ");
6665
6666 let mut recovered = String::new();
6667 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6668 println!("B (128 rounds) =\t{}", recovered);
6669 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
6670 assert_eq!(recovered, message);
6671 println!();
6672
6673 // Expanded case for 0 rounds which means that key is meaningless
6674 let key1 = 0x_1234567890ABCDEF_u64;
6675 let key2 = 0_u64;
6676 println!("K =\t{:#016X}", key);
6677 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
6678 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
6679
6680 let message = "In the beginning God created the heavens and the earth.";
6681 println!("M =\t{}", message);
6682 let nonce = 0x_FEDCBA0987654321_u64;
6683 println!("Nonce = {}", nonce);
6684 let mut cipher1 = [0_u8; 55];
6685 let mut cipher2 = [0_u8; 55];
6686 c_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher1);
6687 d_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher2);
6688 print!("C (0 rounds) =\t");
6689 for c in cipher1.clone()
6690 { print!("{:02X} ", c); }
6691 println!();
6692 let mut txt = String::new();
6693 for c in cipher1.clone()
6694 { write!(txt, "{:02X} ", c); }
6695 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
6696 print!("D (0 rounds) =\t");
6697 for c in cipher2.clone()
6698 { print!("{:02X} ", c); }
6699 println!();
6700 let mut txt = String::new();
6701 for c in cipher2.clone()
6702 { write!(txt, "{:02X} ", c); }
6703 assert_eq!(txt, "58 ED BA 3F 6E 10 CC 9F 76 E4 F3 25 68 1C 82 9A 38 C4 F5 2F 26 16 9E 98 7B F7 FF 2F 26 01 84 98 39 EB FF 2A 70 10 82 8E 3B E2 F4 2F 26 01 84 98 34 E6 FB 39 72 1D C2 ");
6704
6705 let mut recovered1 = String::new();
6706 let mut recovered2 = String::new();
6707 c_des.decrypt_array_into_string(nonce, &cipher1, &mut recovered1);
6708 d_des.decrypt_array_into_string(nonce, &cipher2, &mut recovered2);
6709 println!("B1 (0 rounds) =\t{}", recovered1);
6710 println!("B2 (0 rounds) =\t{}", recovered2);
6711 assert_eq!(recovered1, "In the beginning God created the heavens and the earth.");
6712 assert_eq!(recovered2, "In the beginning God created the heavens and the earth.");
6713 assert_eq!(recovered1, message);
6714 assert_eq!(recovered2, message);
6715 assert_eq!(recovered1, recovered2);
6716 println!();
6717
6718 // Normal case for the message of 0 bytes
6719 let key = 0x_1234567890ABCDEF_u64;
6720 println!("K =\t{:#016X}", key);
6721 let mut a_des = DES::new_with_key_u64(key);
6722
6723 let message = "";
6724 println!("M =\t{}", message);
6725 let nonce = 0x_FEDCBA0987654321_u64;
6726 println!("Nonce = {}", nonce);
6727 let mut cipher = [0_u8; 0];
6728 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6729 print!("C =\t");
6730 for c in cipher.clone()
6731 { print!("{:02X} ", c); }
6732 println!();
6733 let mut txt = String::new();
6734 for c in cipher.clone()
6735 { write!(txt, "{:02X} ", c); }
6736 assert_eq!(txt, "");
6737
6738 let mut recovered = String::new();
6739 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6740 println!("B =\t{}", recovered);
6741 assert_eq!(recovered, "");
6742 assert_eq!(recovered, message);
6743 println!();
6744
6745 // Normal case for the message shorter than 8 bytes
6746 let key = 0x_1234567890ABCDEF_u64;
6747 println!("K =\t{:#016X}", key);
6748 let mut a_des = DES::new_with_key_u64(key);
6749
6750 let message = "7 bytes";
6751 println!("M =\t{}", message);
6752 let nonce = 0x_FEDCBA0987654321_u64;
6753 println!("Nonce = {}", nonce);
6754 let mut cipher = [0_u8; 7];
6755 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6756 print!("C =\t");
6757 for c in cipher.clone()
6758 { print!("{:02X} ", c); }
6759 println!();
6760 let mut txt = String::new();
6761 for c in cipher.clone()
6762 { write!(txt, "{:02X} ", c); }
6763 assert_eq!(txt, "4E 1E 2D 3C 7C BA C2 ");
6764
6765 let mut recovered = String::new();
6766 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6767 println!("B =\t{}", recovered);
6768 assert_eq!(recovered, "7 bytes");
6769 assert_eq!(recovered, message);
6770 println!();
6771
6772 // Normal case for the message of 8 bytes
6773 let key = 0x_1234567890ABCDEF_u64;
6774 println!("K =\t{:#016X}", key);
6775 let mut a_des = DES::new_with_key_u64(key);
6776
6777 let message = "I am OK.";
6778 println!("M =\t{}", message);
6779 let nonce = 0x_FEDCBA0987654321_u64;
6780 println!("Nonce = {}", nonce);
6781 let mut cipher = [0_u8; 8];
6782 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6783 print!("C =\t");
6784 for c in cipher.clone()
6785 { print!("{:02X} ", c); }
6786 println!();
6787 let mut txt = String::new();
6788 for c in cipher.clone()
6789 { write!(txt, "{:02X} ", c); }
6790 assert_eq!(txt, "30 1E 2E 28 28 90 FA 32 ");
6791
6792 let mut recovered = String::new();
6793 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6794 println!("B =\t{}", recovered);
6795 assert_eq!(recovered, "I am OK.");
6796 assert_eq!(recovered, message);
6797 println!();
6798
6799 // Normal case for the message longer than 8 bytes and shorter than 16 bytes
6800 let key = 0x_1234567890ABCDEF_u64;
6801 println!("K =\t{:#016X}", key);
6802 let mut a_des = DES::new_with_key_u64(key);
6803
6804 let message = "PARK Youngho";
6805 println!("M =\t{}", message);
6806 let nonce = 0x_FEDCBA0987654321_u64;
6807 println!("Nonce = {}", nonce);
6808 let mut cipher = [0_u8; 12];
6809 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6810 print!("C =\t");
6811 for c in cipher.clone()
6812 { print!("{:02X} ", c); }
6813 println!();
6814 let mut txt = String::new();
6815 for c in cipher.clone()
6816 { write!(txt, "{:02X} ", c); }
6817 assert_eq!(txt, "29 7F 1D 0E 28 86 DE 69 DB DE 39 A7 ");
6818
6819 let mut recovered = String::new();
6820 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6821 println!("B =\t{}", recovered);
6822 assert_eq!(recovered, "PARK Youngho");
6823 assert_eq!(recovered, message);
6824 println!();
6825
6826 // Normal case for the message of 16 bytes
6827 let key = 0x_1234567890ABCDEF_u64;
6828 println!("K =\t{:#016X}", key);
6829 let mut a_des = DES::new_with_key_u64(key);
6830
6831 let message = "고맙습니다.";
6832 println!("M =\t{}", message);
6833 let nonce = 0x_FEDCBA0987654321_u64;
6834 println!("Nonce = {}", nonce);
6835 let mut cipher = [0_u8; 16];
6836 a_des.encrypt_into_array(nonce, message.as_ptr(), message.len() as u64, &mut cipher);
6837 print!("C =\t");
6838 for c in cipher.clone()
6839 { print!("{:02X} ", c); }
6840 println!();
6841 let mut txt = String::new();
6842 for c in cipher.clone()
6843 { write!(txt, "{:02X} ", c); }
6844 assert_eq!(txt, "93 8D EF AE AF 46 5D 96 00 52 DA 40 78 B2 14 F5 ");
6845
6846 let mut recovered = String::new();
6847 a_des.decrypt_array_into_string(nonce, &cipher, &mut recovered);
6848 println!("B =\t{}", recovered);
6849 assert_eq!(recovered, "고맙습니다.");
6850 assert_eq!(recovered, message);
6851 println!("-------------------------------");
6852}Sourcepub fn encryptor_with_key(key: [u8; 8]) -> Self
pub fn encryptor_with_key(key: [u8; 8]) -> Self
Constructs a new object DES_Generic as a positive encryptor (or an encryptor) for the component of BigCryptor64 incluing NDES.
§Arguments
- The argument
keyis the array of u8 that has 8 elements. - Remember that inverted parity bits do not affect the 56-bit real key. So, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00], [0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01], etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
- You won’t use this method unless you use NDES for such as Triple DES.
- This method sets the key to be the given argument
key. - This method constructs the encryptor component of NDES.
§Example 1
use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
= [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
77fn bigcryptor64_set_keys_later()
78{
79 println!("bigcryptor64_instantiation_with_keys()");
80 use cryptocol::symmetric::{ BigCryptor64, DES };
81 let mut tdes = BigCryptor64::new();
82 let des1 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
83 let des2 = DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]);
84 let des3 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
85 tdes.push_small_cryptor(des1);
86 tdes.push_small_cryptor(des2);
87 tdes.push_small_cryptor(des3);
88 println!("-------------------------------");
89}
90
91fn bigcryptor64_cbc_pkcs7()
92{
93 println!("bigcryptor64_cbc_pkcs7()");
94 use std::fmt::Write as _;
95 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
96 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
97 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
98 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
99
100 let iv = 0x_FEDCBA0987654321_u64;
101 println!("IV = {:#018X}", iv);
102 let message = "In the beginning God created the heavens and the earth.";
103 println!("M =\t{}", message);
104 let mut cipher = Vec::<u8>::new();
105 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
106 print!("C =\t");
107 for c in cipher.clone()
108 { print!("{:02X} ", c); }
109 println!();
110 let mut txt = String::new();
111 for c in cipher.clone()
112 { write!(txt, "{:02X} ", c); }
113 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
114
115 let mut recovered = String::new();
116 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
117 println!("B =\t{}", recovered);
118 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
119 assert_eq!(recovered, message);
120 println!("-------------------------------");
121}
122
123fn bigcryptor64_basic_operation_main()
124{
125 bigcryptor64_new();
126 bigcryptor64_new_with_small_cryptor_array();
127 bigcryptor64_new_with_small_cryptor_vec();
128 bigcryptor64_push_small_cryptor();
129 bigcryptor64_push_small_cryptor_array();
130 bigcryptor64_push_small_cryptor_vec();
131 bigcryptor64_turn_inverse();
132 bigcryptor64_turn_encryptor();
133 bigcryptor64_turn_decryptor();
134 bigcryptor64_encrypt_u64();
135 bigcryptor64_decrypt_u64();
136 bigcryptor64_encrypt_array_u64();
137 bigcryptor64_decrypt_array_u64();
138 bigcryptor64_is_successful();
139 bigcryptor64_is_failed();
140}
141
142fn bigcryptor64_new()
143{
144 println!("bigcryptor64_new()");
145 use cryptocol::symmetric::{ BigCryptor64, DES };
146
147 // Case 1
148 let mut tdes = BigCryptor64::new();
149 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
150 tdes.push_small_cryptor(DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]));
151 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
152
153 // Case 2
154 let mut _tdes = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
155 + DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
156 + DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
157 println!("-------------------------------");
158}More examples
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}Sourcepub fn encryptor_with_key_u64(key: u64) -> Self
pub fn encryptor_with_key_u64(key: u64) -> Self
Constructs a new object DES_Generic as a positive encryptor (or an encryptor) for the component of BigCryptor64 incluing NDES.
§Arguments
- The argument
keyis an unsigned integer that is ofu64-type. - Remember that inverted parity bits do not affect the 56-bit real key. So, 0x0000000000000000_u64, 0x0101010101010101_u64, 0x0000000000000001_u64, 0x0000000000000100_u64, 0x0100001000000001, etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
- You won’t use this method unless you use NDES for such as Triple DES.
- This method sets the key to be the given argument
key. - This method constructs the encryptor component of NDES.
§Example 1
use cryptocol::symmetric::{ BigCryptor64, DES };
let mut tdes = BigCryptor64::new_with_small_cryptor_array(
[Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
);
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
43fn bigcryptor64_instantiation_with_keys_u64()
44{
45 println!("bigcryptor64_instantiation_with_keys_u64()");
46 use cryptocol::symmetric::{ BigCryptor64, DES };
47 let mut _tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
48 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
49 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
50 println!("-------------------------------");
51}
52
53fn bigcryptor64_instantiation_with_keys()
54{
55 println!("bigcryptor64_instantiation_with_keys()");
56 use cryptocol::symmetric::{ BigCryptor64, DES };
57 let mut _tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
58 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
59 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
60 println!("-------------------------------");
61}
62
63fn bigcryptor64_set_keys_u64_later()
64{
65 println!("bigcryptor64_instantiation_with_keys_u64()");
66 use cryptocol::symmetric::{ BigCryptor64, DES };
67 let mut tdes = BigCryptor64::new();
68 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
69 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
70 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
71 tdes.push_small_cryptor(des1);
72 tdes.push_small_cryptor(des2);
73 tdes.push_small_cryptor(des3);
74 println!("-------------------------------");
75}
76
77fn bigcryptor64_set_keys_later()
78{
79 println!("bigcryptor64_instantiation_with_keys()");
80 use cryptocol::symmetric::{ BigCryptor64, DES };
81 let mut tdes = BigCryptor64::new();
82 let des1 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
83 let des2 = DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]);
84 let des3 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
85 tdes.push_small_cryptor(des1);
86 tdes.push_small_cryptor(des2);
87 tdes.push_small_cryptor(des3);
88 println!("-------------------------------");
89}
90
91fn bigcryptor64_cbc_pkcs7()
92{
93 println!("bigcryptor64_cbc_pkcs7()");
94 use std::fmt::Write as _;
95 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
96 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
97 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
98 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
99
100 let iv = 0x_FEDCBA0987654321_u64;
101 println!("IV = {:#018X}", iv);
102 let message = "In the beginning God created the heavens and the earth.";
103 println!("M =\t{}", message);
104 let mut cipher = Vec::<u8>::new();
105 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
106 print!("C =\t");
107 for c in cipher.clone()
108 { print!("{:02X} ", c); }
109 println!();
110 let mut txt = String::new();
111 for c in cipher.clone()
112 { write!(txt, "{:02X} ", c); }
113 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
114
115 let mut recovered = String::new();
116 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
117 println!("B =\t{}", recovered);
118 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
119 assert_eq!(recovered, message);
120 println!("-------------------------------");
121}
122
123fn bigcryptor64_basic_operation_main()
124{
125 bigcryptor64_new();
126 bigcryptor64_new_with_small_cryptor_array();
127 bigcryptor64_new_with_small_cryptor_vec();
128 bigcryptor64_push_small_cryptor();
129 bigcryptor64_push_small_cryptor_array();
130 bigcryptor64_push_small_cryptor_vec();
131 bigcryptor64_turn_inverse();
132 bigcryptor64_turn_encryptor();
133 bigcryptor64_turn_decryptor();
134 bigcryptor64_encrypt_u64();
135 bigcryptor64_decrypt_u64();
136 bigcryptor64_encrypt_array_u64();
137 bigcryptor64_decrypt_array_u64();
138 bigcryptor64_is_successful();
139 bigcryptor64_is_failed();
140}
141
142fn bigcryptor64_new()
143{
144 println!("bigcryptor64_new()");
145 use cryptocol::symmetric::{ BigCryptor64, DES };
146
147 // Case 1
148 let mut tdes = BigCryptor64::new();
149 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
150 tdes.push_small_cryptor(DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]));
151 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
152
153 // Case 2
154 let mut _tdes = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
155 + DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
156 + DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
157 println!("-------------------------------");
158}
159
160fn bigcryptor64_new_with_small_cryptor_array()
161{
162 println!("bigcryptor64_new_with_small_cryptor_array()");
163 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
164
165 // Case 1
166 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
167 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
168 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
169 let mut _tdes = BigCryptor64::new_with_small_cryptor_array(cryptors);
170 println!("-------------------------------");
171}
172
173fn bigcryptor64_new_with_small_cryptor_vec()
174{
175 println!("bigcryptor64_new_with_small_cryptor_vec()");
176 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
177
178 // Case 1
179 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
180 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
181 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
182 let mut _tdes = BigCryptor64::new_with_small_cryptor_vec(cryptors);
183 println!("-------------------------------");
184}
185
186fn bigcryptor64_push_small_cryptor()
187{
188 println!("bigcryptor64_new_with_small_cryptor_vec()");
189 use cryptocol::symmetric::{ BigCryptor64, DES };
190
191 // Case 1
192 let mut tdes = BigCryptor64::new();
193 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
195 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
196 tdes.push_small_cryptor(des1);
197 tdes.push_small_cryptor(des2);
198 tdes.push_small_cryptor(des3);
199 println!("-------------------------------");
200}
201
202fn bigcryptor64_push_small_cryptor_array()
203{
204 println!("bigcryptor64_push_small_cryptor_array()");
205 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
206
207 // Case 1
208 let mut tdes = BigCryptor64::new();
209 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
210 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
211 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
212 tdes.push_small_cryptor_array(cryptors);
213 println!("-------------------------------");
214}
215
216fn bigcryptor64_push_small_cryptor_vec()
217{
218 println!("bigcryptor64_push_small_cryptor_vec()");
219 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
220
221 // Case 1
222 let mut tdes = BigCryptor64::new();
223 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
224 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
225 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
226 tdes.push_small_cryptor_vec(cryptors);
227 println!("-------------------------------");
228}More examples
39fn ndes_new_with_keys()
40{
41 println!("ndes_new_with_keys()");
42 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
43
44 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
45 = [ Box::new(DES::encryptor_with_key_u64(0x1234567890ABCDEF_u64)),
46 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
47 Box::new(DES::encryptor_with_key_u64(0x1234567890ABCDEF_u64)) ];
48 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
49 let plaintext = 0x1234567890ABCDEF_u64;
50 let ciphertext = tdes.encrypt_u64(plaintext);
51
52 println!("Plaintext:\t\t{:#016X}", plaintext);
53 println!("Ciphertext:\t\t{:#016X}", ciphertext);
54 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
55
56 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
57 println!("Cipher-ciphertext:\t{:#016X}", cipher_cipher_text);
58 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
59 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
60 println!("-------------------------------");
61}
62
63fn ndes_new_with_keys_u64()
64{
65 println!("ndes_new_with_keys_u64()");
66 use std::fmt::Write as _;
67 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
68
69 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
70 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
71 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
72 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
73 );
74
75 let message = "I am OK.";
76 println!("M =\t{}", message);
77 let mut cipher = [0_u8; 16];
78 tdes.encrypt_str_into_array(&message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "88 89 99 44 30 72 CA 2F 22 4F 7C E0 55 FA 28 C3 ");
87 println!();
88
89 let mut recovered = vec![0; 16];
90 let len = tdes.decrypt_array_into_vec(&cipher, &mut recovered);
91 print!("Ba =\t");
92 for b in recovered.clone()
93 { print!("{:02X} ", b); }
94 println!();
95 let mut txt = String::new();
96 for c in recovered.clone()
97 { write!(txt, "{:02X} ", c); }
98 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
99
100 let mut converted = String::new();
101 unsafe { converted.as_mut_vec() }.append(&mut recovered);
102 converted.truncate(len as usize);
103
104 println!("Bb =\t{}", converted);
105 assert_eq!(converted, "I am OK.");
106 assert_eq!(converted, message);
107 println!("-------------------------------");
108}54fn bigcryptor64_encrypt_with_padding_iso_ecb()
55{
56 println!("bigcryptor64_encrypt_with_padding_iso_ecb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let message = "In the beginning God created the heavens and the earth.";
66 println!("M =\t{}", message);
67 let mut cipher = [0_u8; 56];
68 tdes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
69 print!("C =\t");
70 for c in cipher.clone()
71 { print!("{:02X} ", c); }
72 println!();
73 let mut txt = String::new();
74 for c in cipher.clone()
75 { write!(txt, "{:02X} ", c); }
76 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
77 println!("-------------------------------");
78}
79
80fn bigcryptor64_encrypt_with_padding_iso_ecb_into_vec()
81{
82 println!("bigcryptor64_encrypt_with_padding_iso_ecb_into_vec()");
83 use std::io::Write;
84 use std::fmt::Write as _;
85 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
86
87 // TDES case
88 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
89 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
90 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
91 let message = "In the beginning God created the heavens and the earth.";
92 println!("M =\t{}", message);
93 let mut cipher = Vec::<u8>::new();
94 tdes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
95 print!("C =\t");
96 for c in cipher.clone()
97 { print!("{:02X} ", c); }
98 println!();
99 let mut txt = String::new();
100 for c in cipher.clone()
101 { write!(txt, "{:02X} ", c); }
102 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
103 println!("-------------------------------");
104}
105
106fn bigcryptor64_encrypt_with_padding_iso_ecb_into_array()
107{
108 println!("bigcryptor64_encrypt_with_padding_iso_ecb_into_array()");
109 use std::io::Write;
110 use std::fmt::Write as _;
111 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
112
113 // TDES case
114 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
115 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
116 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
117 let message = "In the beginning God created the heavens and the earth.";
118 println!("M =\t{}", message);
119 let mut cipher = [0_u8; 56];
120 tdes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
121 print!("C =\t");
122 for c in cipher.clone()
123 { print!("{:02X} ", c); }
124 println!();
125 let mut txt = String::new();
126 for c in cipher.clone()
127 { write!(txt, "{:02X} ", c); }
128 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
129 println!("-------------------------------");
130}
131
132fn bigcryptor64_encrypt_str_with_padding_iso_ecb()
133{
134 println!("bigcryptor64_encrypt_str_with_padding_iso_ecb()");
135 use std::io::Write;
136 use std::fmt::Write as _;
137 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
138
139 // TDES case
140 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
141 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
142 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
143 let message = "In the beginning God created the heavens and the earth.";
144 println!("M =\t{}", message);
145 let mut cipher = [0_u8; 56];
146 tdes.encrypt_str(&message, cipher.as_mut_ptr());
147 print!("C =\t");
148 for c in cipher.clone()
149 { print!("{:02X} ", c); }
150 println!();
151 let mut txt = String::new();
152 for c in cipher.clone()
153 { write!(txt, "{:02X} ", c); }
154 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
155 println!("-------------------------------");
156}
157
158fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_vec()
159{
160 println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_vec()");
161 use std::io::Write;
162 use std::fmt::Write as _;
163 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
164
165 // TDES case
166 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
167 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
168 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
169 let message = "In the beginning God created the heavens and the earth.";
170 let mut cipher = Vec::<u8>::new();
171 tdes.encrypt_str_into_vec(&message, &mut cipher);
172 print!("C =\t");
173 for c in cipher.clone()
174 { print!("{:02X} ", c); }
175 println!();
176 let mut txt = String::new();
177 for c in cipher.clone()
178 { write!(txt, "{:02X} ", c); }
179 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
180 println!("-------------------------------");
181}
182
183fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()
184{
185 println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()");
186 use std::io::Write;
187 use std::fmt::Write as _;
188 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
189
190 // TDES case
191 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
192 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
193 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let message = "In the beginning God created the heavens and the earth.";
195 let mut cipher = [0_u8; 56];
196 tdes.encrypt_str_into_array(&message, &mut cipher);
197 print!("C =\t");
198 for c in cipher.clone()
199 { print!("{:02X} ", c); }
200 println!();
201 let mut txt = String::new();
202 for c in cipher.clone()
203 { write!(txt, "{:02X} ", c); }
204 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
205 println!("-------------------------------");
206}
207
208fn bigcryptor64_encrypt_string_with_padding_iso_ecb()
209{
210 println!("bigcryptor64_encrypt_string_with_padding_iso_ecb()");
211 use std::io::Write;
212 use std::fmt::Write as _;
213 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
214
215 // TDES case
216 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219 let message = "In the beginning God created the heavens and the earth.".to_string();
220 let mut cipher = [0_u8; 56];
221 tdes.encrypt_string(&message, cipher.as_mut_ptr());
222 print!("C =\t");
223 for c in cipher.clone()
224 { print!("{:02X} ", c); }
225 println!();
226 let mut txt = String::new();
227 for c in cipher.clone()
228 { write!(txt, "{:02X} ", c); }
229 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230 println!("-------------------------------");
231}
232
233fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()
234{
235 println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()");
236 use std::io::Write;
237 use std::fmt::Write as _;
238 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
239
240 // TDES case
241 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244 let message = "In the beginning God created the heavens and the earth.".to_string();
245 let mut cipher = Vec::<u8>::new();
246 tdes.encrypt_string_into_vec(&message, &mut cipher);
247 print!("C =\t");
248 for c in cipher.clone()
249 { print!("{:02X} ", c); }
250 println!();
251 let mut txt = String::new();
252 for c in cipher.clone()
253 { write!(txt, "{:02X} ", c); }
254 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255 println!("-------------------------------");
256}
257
258fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()
259{
260 println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()");
261 use std::io::Write;
262 use std::fmt::Write as _;
263 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
264
265 // TDES case
266 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269 let message = "In the beginning God created the heavens and the earth.".to_string();
270 let mut cipher = [0_u8; 56];
271 tdes.encrypt_string_into_array(&message, &mut cipher);
272 print!("C =\t");
273 for c in cipher.clone()
274 { print!("{:02X} ", c); }
275 println!();
276 let mut txt = String::new();
277 for c in cipher.clone()
278 { write!(txt, "{:02X} ", c); }
279 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280 println!("-------------------------------");
281}
282
283fn bigcryptor64_encrypt_vec_with_padding_iso_ecb()
284{
285 println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb()");
286 use std::io::Write;
287 use std::fmt::Write as _;
288 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
289
290 // TDES case
291 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294 let message = "In the beginning God created the heavens and the earth.";
295 println!("M =\t{}", message);
296 let message = unsafe { message.to_string().as_mut_vec().clone() };
297 let mut cipher = [0_u8; 56];
298 tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299 print!("C =\t");
300 for c in cipher.clone()
301 { print!("{:02X} ", c); }
302 println!();
303 let mut txt = String::new();
304 for c in cipher.clone()
305 { write!(txt, "{:02X} ", c); }
306 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307 println!("-------------------------------");
308}
309
310fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()
311{
312 println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()");
313 use std::io::Write;
314 use std::fmt::Write as _;
315 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
316
317 // TDES case
318 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321 let message = "In the beginning God created the heavens and the earth.";
322 println!("M =\t{}", message);
323 let message = unsafe { message.to_string().as_mut_vec().clone() };
324 let mut cipher = Vec::<u8>::new();
325 tdes.encrypt_vec_into_vec(&message, &mut cipher);
326 print!("C =\t");
327 for c in cipher.clone()
328 { print!("{:02X} ", c); }
329 println!();
330 let mut txt = String::new();
331 for c in cipher.clone()
332 { write!(txt, "{:02X} ", c); }
333 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334 println!("-------------------------------");
335}
336
337fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()
338{
339 println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()");
340 use std::io::Write;
341 use std::fmt::Write as _;
342 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
343
344 // TDES case
345 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348 let message = "In the beginning God created the heavens and the earth.";
349 println!("M =\t{}", message);
350 let message = unsafe { message.to_string().as_mut_vec().clone() };
351 let mut cipher = [0_u8; 56];
352 tdes.encrypt_vec_into_array(&message, &mut cipher);
353 print!("C =\t");
354 for c in cipher.clone()
355 { print!("{:02X} ", c); }
356 println!();
357 let mut txt = String::new();
358 for c in cipher.clone()
359 { write!(txt, "{:02X} ", c); }
360 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361 println!("-------------------------------");
362}
363
364fn bigcryptor64_encrypt_array_with_padding_iso_ecb()
365{
366 println!("bigcryptor64_encrypt_array_with_padding_iso_ecb()");
367 use std::io::Write;
368 use std::fmt::Write as _;
369 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
370
371 // TDES case
372 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375 let mes = "In the beginning God created the heavens and the earth.";
376 println!("M =\t{}", mes);
377 let mut message = [0_u8; 55];
378 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379 let mut cipher = [0_u8; 56];
380 tdes.encrypt_array(&message, cipher.as_mut_ptr());
381 print!("C =\t");
382 for c in cipher.clone()
383 { print!("{:02X} ", c); }
384 println!();
385 let mut txt = String::new();
386 for c in cipher.clone()
387 { write!(txt, "{:02X} ", c); }
388 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389 println!("-------------------------------");
390}
391
392fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()
393{
394 println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()");
395 use std::io::Write;
396 use std::fmt::Write as _;
397 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
398
399 // TDES case
400 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403 let mes = "In the beginning God created the heavens and the earth.";
404 println!("M =\t{}", mes);
405 let mut message = [0_u8; 55];
406 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407 let mut cipher = Vec::<u8>::new();
408 tdes.encrypt_array_into_vec(&message, &mut cipher);
409 print!("C =\t");
410 for c in cipher.clone()
411 { print!("{:02X} ", c); }
412 println!();
413 let mut txt = String::new();
414 for c in cipher.clone()
415 { write!(txt, "{:02X} ", c); }
416 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417 println!("-------------------------------");
418}
419
420fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()
421{
422 println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()");
423 use std::io::Write;
424 use std::fmt::Write as _;
425 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
426
427 // TDES case
428 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = [0_u8; 56];
436 tdes.encrypt_array_into_array(&message, &mut cipher);
437 for c in cipher.clone()
438 { print!("{:02X} ", c); }
439 println!();
440 let mut txt = String::new();
441 for c in cipher.clone()
442 { write!(txt, "{:02X} ", c); }
443 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444 println!("-------------------------------");
445}
446
447fn bigcryptor64_decrypt_with_padding_iso_ecb()
448{
449 println!("bigcryptor64_decrypt_with_padding_iso_ecb()");
450 use std::io::Write;
451 use std::fmt::Write as _;
452 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
453
454 // TDES case
455 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
456 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
457 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
458 let message = "In the beginning God created the heavens and the earth.";
459 println!("M =\t{}", message);
460 let mut cipher = Vec::<u8>::new();
461 tdes.encrypt_str_into_vec(&message, &mut cipher);
462 print!("C =\t");
463 for c in cipher.clone()
464 { print!("{:02X} ", c); }
465 println!();
466 let mut txt = String::new();
467 for c in cipher.clone()
468 { write!(txt, "{:02X} ", c); }
469 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
470
471 let mut recovered = vec![0; 55];
472 tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
473 print!("Ba =\t");
474 for b in recovered.clone()
475 { print!("{:02X} ", b); }
476 println!();
477 let mut txt = String::new();
478 for c in recovered.clone()
479 { write!(txt, "{:02X} ", c); }
480 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
481
482 let mut converted = String::new();
483 unsafe { converted.as_mut_vec() }.append(&mut recovered);
484
485 println!("Bb =\t{}", converted);
486 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
487 assert_eq!(converted, message);
488 println!("-------------------------------");
489}
490
491fn bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()
492{
493 println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()");
494 use std::io::Write;
495 use std::fmt::Write as _;
496 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
497
498 // TDES case
499 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502 let message = "In the beginning God created the heavens and the earth.";
503 println!("M =\t{}", message);
504 let mut cipher = Vec::<u8>::new();
505 tdes.encrypt_str_into_vec(&message, &mut cipher);
506 print!("C =\t");
507 for c in cipher.clone()
508 { print!("{:02X} ", c); }
509 println!();
510 let mut txt = String::new();
511 for c in cipher.clone()
512 { write!(txt, "{:02X} ", c); }
513 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515 let mut recovered = Vec::<u8>::new();
516 tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517 print!("Ba =\t");
518 for b in recovered.clone()
519 { print!("{:02X} ", b); }
520 println!();
521 let mut txt = String::new();
522 for c in recovered.clone()
523 { write!(txt, "{:02X} ", c); }
524 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526 let mut converted = String::new();
527 unsafe { converted.as_mut_vec() }.append(&mut recovered);
528
529 println!("Bb =\t{}", converted);
530 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531 assert_eq!(converted, message);
532 println!("-------------------------------");
533}
534
535fn bigcryptor64_decrypt_with_padding_iso_ecb_into_array()
536{
537 println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_array()");
538 use std::io::Write;
539 use std::fmt::Write as _;
540 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
541
542 // TDES case
543 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
544 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
545 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
546 let message = "In the beginning God created the heavens and the earth.";
547 println!("M =\t{}", message);
548 let mut cipher = Vec::<u8>::new();
549 tdes.encrypt_str_into_vec(&message, &mut cipher);
550 print!("C =\t");
551 for c in cipher.clone()
552 { print!("{:02X} ", c); }
553 println!();
554 let mut txt = String::new();
555 for c in cipher.clone()
556 { write!(txt, "{:02X} ", c); }
557 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
558
559 let mut recovered = [0u8; 56];
560 let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
561 print!("Ba =\t");
562 for b in recovered.clone()
563 { print!("{:02X} ", b); }
564 println!();
565 let mut txt = String::new();
566 for c in recovered.clone()
567 { write!(txt, "{:02X} ", c); }
568 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
569
570 let mut converted = String::new();
571 unsafe { converted.as_mut_vec() }.write(&recovered);
572 unsafe { converted.as_mut_vec() }.truncate(len as usize);
573 println!("Bb =\t{}", converted);
574 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
575 assert_eq!(converted, message);
576 println!("-------------------------------");
577}
578
579fn bigcryptor64_decrypt_with_padding_iso_ecb_into_string()
580{
581 println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_string()");
582 use std::io::Write;
583 use std::fmt::Write as _;
584 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
585
586 // TDES case
587 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590 let message = "In the beginning God created the heavens and the earth.";
591 println!("M =\t{}", message);
592 let mut cipher = Vec::<u8>::new();
593 tdes.encrypt_str_into_vec(&message, &mut cipher);
594 print!("C =\t");
595 for c in cipher.clone()
596 { print!("{:02X} ", c); }
597 println!();
598 let mut txt = String::new();
599 for c in cipher.clone()
600 { write!(txt, "{:02X} ", c); }
601 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603 let mut recovered = String::new();
604 tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605 println!("B =\t{}", recovered);
606 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607 assert_eq!(recovered, message);
608 println!("-------------------------------");
609}
610
611fn bigcryptor64_decrypt_vec_with_padding_iso_ecb()
612{
613 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb()");
614 use std::io::Write;
615 use std::fmt::Write as _;
616 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
617
618 // TDES case
619 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622 let message = "In the beginning God created the heavens and the earth.";
623 println!("M =\t{}", message);
624 let mut cipher = Vec::<u8>::new();
625 tdes.encrypt_str_into_vec(&message, &mut cipher);
626 print!("C =\t");
627 for c in cipher.clone()
628 { print!("{:02X} ", c); }
629 println!();
630 let mut txt = String::new();
631 for c in cipher.clone()
632 { write!(txt, "{:02X} ", c); }
633 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635 let mut recovered = vec![0; 55];
636 tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637 print!("Ba =\t");
638 for b in recovered.clone()
639 { print!("{:02X} ", b); }
640 println!();
641 let mut txt = String::new();
642 for c in recovered.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646 let mut converted = String::new();
647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
648
649 println!("Bb =\t{}", converted);
650 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651 assert_eq!(converted, message);
652 println!("-------------------------------");
653}
654
655fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()
656{
657 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()");
658 use std::io::Write;
659 use std::fmt::Write as _;
660 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
661
662 // TDES case
663 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666 let message = "In the beginning God created the heavens and the earth.";
667 println!("M =\t{}", message);
668 let mut cipher = Vec::<u8>::new();
669 tdes.encrypt_str_into_vec(&message, &mut cipher);
670 print!("C =\t");
671 for c in cipher.clone()
672 { print!("{:02X} ", c); }
673 println!();
674 let mut txt = String::new();
675 for c in cipher.clone()
676 { write!(txt, "{:02X} ", c); }
677 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679 let mut recovered = Vec::<u8>::new();
680 tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681 print!("Ba =\t");
682 for b in recovered.clone()
683 { print!("{:02X} ", b); }
684 println!();
685 let mut txt = String::new();
686 for c in recovered.clone()
687 { write!(txt, "{:02X} ", c); }
688 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690 let mut converted = String::new();
691 unsafe { converted.as_mut_vec() }.append(&mut recovered);
692
693 println!("Bb =\t{}", converted);
694 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695 assert_eq!(converted, message);
696 println!("-------------------------------");
697}
698
699fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()
700{
701 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()");
702 use std::io::Write;
703 use std::fmt::Write as _;
704 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
705
706 // TDES case
707 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710 let message = "In the beginning God created the heavens and the earth.";
711 println!("M =\t{}", message);
712 let mut cipher = Vec::<u8>::new();
713 tdes.encrypt_str_into_vec(&message, &mut cipher);
714 print!("C =\t");
715 for c in cipher.clone()
716 { print!("{:02X} ", c); }
717 println!();
718 let mut txt = String::new();
719 for c in cipher.clone()
720 { write!(txt, "{:02X} ", c); }
721 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723 let mut recovered = [0u8; 56];
724 let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725 print!("Ba =\t");
726 for b in recovered.clone()
727 { print!("{:02X} ", b); }
728 println!();
729 let mut txt = String::new();
730 for c in recovered.clone()
731 { write!(txt, "{:02X} ", c); }
732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734 let mut converted = String::new();
735 unsafe { converted.as_mut_vec() }.write(&recovered);
736 unsafe { converted.as_mut_vec() }.truncate(len as usize);
737 println!("Bb =\t{}", converted);
738 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739 assert_eq!(converted, message);
740 println!("-------------------------------");
741}
742
743fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()
744{
745 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()");
746 use std::io::Write;
747 use std::fmt::Write as _;
748 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
749
750 // TDES case
751 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(&message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767 let mut recovered = String::new();
768 tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769 println!("B =\t{}", recovered);
770 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771 assert_eq!(recovered, message);
772 println!("-------------------------------");
773}
774
775fn bigcryptor64_decrypt_array_with_padding_iso_ecb()
776{
777 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb()");
778 use std::io::Write;
779 use std::fmt::Write as _;
780 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
781
782 // TDES case
783 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
784 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
785 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
786 let message = "In the beginning God created the heavens and the earth.";
787 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
788 tdes.encrypt_str_into_array(&message, &mut cipher);
789 print!("C =\t");
790 for c in cipher.clone()
791 { print!("{:02X} ", c); }
792 println!();
793 let mut txt = String::new();
794 for c in cipher.clone()
795 { write!(txt, "{:02X} ", c); }
796 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
797
798 let mut recovered = vec![0; 55];
799 let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
800 recovered.truncate(len as usize);
801 print!("Ba =\t");
802 for b in recovered.clone()
803 { print!("{:02X} ", b); }
804 println!();
805 let mut txt = String::new();
806 for c in recovered.clone()
807 { write!(txt, "{:02X} ", c); }
808 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
809
810 let mut converted = String::new();
811 unsafe { converted.as_mut_vec() }.append(&mut recovered);
812
813 println!("Bb =\t{}", converted);
814 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
815 assert_eq!(converted, message);
816 println!("-------------------------------");
817}
818
819fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()
820{
821 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()");
822 use std::io::Write;
823 use std::fmt::Write as _;
824 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
825
826 // TDES case
827 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
828 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
829 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
830 let message = "In the beginning God created the heavens and the earth.";
831 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
832 tdes.encrypt_str_into_array(&message, &mut cipher);
833 print!("C =\t");
834 for c in cipher.clone()
835 { print!("{:02X} ", c); }
836 println!();
837 let mut txt = String::new();
838 for c in cipher.clone()
839 { write!(txt, "{:02X} ", c); }
840 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
841
842 let mut recovered = Vec::<u8>::new();
843 tdes.decrypt_array_into_vec(&cipher, &mut recovered);
844 print!("Ba =\t");
845 for b in recovered.clone()
846 { print!("{:02X} ", b); }
847 println!();
848 let mut txt = String::new();
849 for c in recovered.clone()
850 { write!(txt, "{:02X} ", c); }
851 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
852
853 let mut converted = String::new();
854 unsafe { converted.as_mut_vec() }.append(&mut recovered);
855
856 println!("Bb =\t{}", converted);
857 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
858 assert_eq!(converted, message);
859 println!("-------------------------------");
860}
861
862fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()
863{
864 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()");
865 use std::io::Write;
866 use std::fmt::Write as _;
867 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
868
869 // TDES case
870 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
871 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
872 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
873 let message = "In the beginning God created the heavens and the earth.";
874 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
875 tdes.encrypt_str_into_array(&message, &mut cipher);
876 print!("C =\t");
877 for c in cipher.clone()
878 { print!("{:02X} ", c); }
879 println!();
880 let mut txt = String::new();
881 for c in cipher.clone()
882 { write!(txt, "{:02X} ", c); }
883 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
884
885 let mut recovered = [0u8; 56];
886 let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
887 print!("Ba =\t");
888 for b in recovered.clone()
889 { print!("{:02X} ", b); }
890 println!();
891 let mut txt = String::new();
892 for c in recovered.clone()
893 { write!(txt, "{:02X} ", c); }
894 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
895
896 let mut converted = String::new();
897 unsafe { converted.as_mut_vec() }.write(&recovered);
898 unsafe { converted.as_mut_vec() }.truncate(len as usize);
899 println!("Bb =\t{}", converted);
900 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
901 assert_eq!(converted, message);
902 println!("-------------------------------");
903}
904
905fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()
906{
907 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()");
908 use std::io::Write;
909 use std::fmt::Write as _;
910 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
911
912 // TDES case
913 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
914 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
915 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
916 let message = "In the beginning God created the heavens and the earth.";
917 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
918 tdes.encrypt_str_into_array(&message, &mut cipher);
919 print!("C =\t");
920 for c in cipher.clone()
921 { print!("{:02X} ", c); }
922 println!();
923 let mut txt = String::new();
924 for c in cipher.clone()
925 { write!(txt, "{:02X} ", c); }
926 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
927
928 let mut recovered = String::new();
929 tdes.decrypt_array_into_string(&cipher, &mut recovered);
930 println!("B =\t{}", recovered);
931 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
932 assert_eq!(recovered, message);
933 println!("-------------------------------");
934}54fn bigcryptor64_encrypt_with_padding_pkcs7_ecb()
55{
56 println!("bigcryptor64_encrypt_with_padding_pkcs7_ecb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let message = "In the beginning God created the heavens and the earth.";
66 println!("M =\t{}", message);
67 let mut cipher = [0_u8; 56];
68 tdes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
69 print!("C =\t");
70 for c in cipher.clone()
71 { print!("{:02X} ", c); }
72 println!();
73 let mut txt = String::new();
74 for c in cipher.clone()
75 { write!(txt, "{:02X} ", c); }
76 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
77 println!("-------------------------------");
78}
79
80fn bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_vec()
81{
82 println!("bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_vec()");
83 use std::io::Write;
84 use std::fmt::Write as _;
85 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
86
87 // TDES case
88 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
89 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
90 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
91 let message = "In the beginning God created the heavens and the earth.";
92 println!("M =\t{}", message);
93 let mut cipher = Vec::<u8>::new();
94 tdes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
95 print!("C =\t");
96 for c in cipher.clone()
97 { print!("{:02X} ", c); }
98 println!();
99 let mut txt = String::new();
100 for c in cipher.clone()
101 { write!(txt, "{:02X} ", c); }
102 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
103 println!("-------------------------------");
104}
105
106fn bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_array()
107{
108 println!("bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_array()");
109 use std::io::Write;
110 use std::fmt::Write as _;
111 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
112
113 // TDES case
114 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
115 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
116 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
117 let message = "In the beginning God created the heavens and the earth.";
118 println!("M =\t{}", message);
119 let mut cipher = [0_u8; 56];
120 tdes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
121 print!("C =\t");
122 for c in cipher.clone()
123 { print!("{:02X} ", c); }
124 println!();
125 let mut txt = String::new();
126 for c in cipher.clone()
127 { write!(txt, "{:02X} ", c); }
128 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
129 println!("-------------------------------");
130}
131
132fn bigcryptor64_encrypt_str_with_padding_pkcs7_ecb()
133{
134 println!("bigcryptor64_encrypt_str_with_padding_pkcs7_ecb()");
135 use std::io::Write;
136 use std::fmt::Write as _;
137 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
138
139 // TDES case
140 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
141 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
142 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
143 let message = "In the beginning God created the heavens and the earth.";
144 println!("M =\t{}", message);
145 let mut cipher = [0_u8; 56];
146 tdes.encrypt_str(&message, cipher.as_mut_ptr());
147 print!("C =\t");
148 for c in cipher.clone()
149 { print!("{:02X} ", c); }
150 println!();
151 let mut txt = String::new();
152 for c in cipher.clone()
153 { write!(txt, "{:02X} ", c); }
154 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
155 println!("-------------------------------");
156}
157
158fn bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_vec()
159{
160 println!("bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_vec()");
161 use std::io::Write;
162 use std::fmt::Write as _;
163 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
164
165 // TDES case
166 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
167 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
168 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
169 let message = "In the beginning God created the heavens and the earth.";
170 let mut cipher = Vec::<u8>::new();
171 tdes.encrypt_str_into_vec(&message, &mut cipher);
172 print!("C =\t");
173 for c in cipher.clone()
174 { print!("{:02X} ", c); }
175 println!();
176 let mut txt = String::new();
177 for c in cipher.clone()
178 { write!(txt, "{:02X} ", c); }
179 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
180 println!("-------------------------------");
181}
182
183fn bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_array()
184{
185 println!("bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_array()");
186 use std::io::Write;
187 use std::fmt::Write as _;
188 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
189
190 // TDES case
191 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
192 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
193 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let message = "In the beginning God created the heavens and the earth.";
195 let mut cipher = [0_u8; 56];
196 tdes.encrypt_str_into_array(&message, &mut cipher);
197 print!("C =\t");
198 for c in cipher.clone()
199 { print!("{:02X} ", c); }
200 println!();
201 let mut txt = String::new();
202 for c in cipher.clone()
203 { write!(txt, "{:02X} ", c); }
204 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
205 println!("-------------------------------");
206}
207
208fn bigcryptor64_encrypt_string_with_padding_pkcs7_ecb()
209{
210 println!("bigcryptor64_encrypt_string_with_padding_pkcs7_ecb()");
211 use std::io::Write;
212 use std::fmt::Write as _;
213 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
214
215 // TDES case
216 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219 let message = "In the beginning God created the heavens and the earth.".to_string();
220 let mut cipher = [0_u8; 56];
221 tdes.encrypt_string(&message, cipher.as_mut_ptr());
222 print!("C =\t");
223 for c in cipher.clone()
224 { print!("{:02X} ", c); }
225 println!();
226 let mut txt = String::new();
227 for c in cipher.clone()
228 { write!(txt, "{:02X} ", c); }
229 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230 println!("-------------------------------");
231}
232
233fn bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_vec()
234{
235 println!("bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_vec()");
236 use std::io::Write;
237 use std::fmt::Write as _;
238 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
239
240 // TDES case
241 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244 let message = "In the beginning God created the heavens and the earth.".to_string();
245 let mut cipher = Vec::<u8>::new();
246 tdes.encrypt_string_into_vec(&message, &mut cipher);
247 print!("C =\t");
248 for c in cipher.clone()
249 { print!("{:02X} ", c); }
250 println!();
251 let mut txt = String::new();
252 for c in cipher.clone()
253 { write!(txt, "{:02X} ", c); }
254 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255 println!("-------------------------------");
256}
257
258fn bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_array()
259{
260 println!("bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_array()");
261 use std::io::Write;
262 use std::fmt::Write as _;
263 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
264
265 // TDES case
266 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269 let message = "In the beginning God created the heavens and the earth.".to_string();
270 let mut cipher = [0_u8; 56];
271 tdes.encrypt_string_into_array(&message, &mut cipher);
272 print!("C =\t");
273 for c in cipher.clone()
274 { print!("{:02X} ", c); }
275 println!();
276 let mut txt = String::new();
277 for c in cipher.clone()
278 { write!(txt, "{:02X} ", c); }
279 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280 println!("-------------------------------");
281}
282
283fn bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb()
284{
285 println!("bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb()");
286 use std::io::Write;
287 use std::fmt::Write as _;
288 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
289
290 // TDES case
291 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294 let message = "In the beginning God created the heavens and the earth.";
295 println!("M =\t{}", message);
296 let message = unsafe { message.to_string().as_mut_vec().clone() };
297 let mut cipher = [0_u8; 56];
298 tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299 print!("C =\t");
300 for c in cipher.clone()
301 { print!("{:02X} ", c); }
302 println!();
303 let mut txt = String::new();
304 for c in cipher.clone()
305 { write!(txt, "{:02X} ", c); }
306 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307 println!("-------------------------------");
308}
309
310fn bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_vec()
311{
312 println!("bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_vec()");
313 use std::io::Write;
314 use std::fmt::Write as _;
315 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
316
317 // TDES case
318 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321 let message = "In the beginning God created the heavens and the earth.";
322 println!("M =\t{}", message);
323 let message = unsafe { message.to_string().as_mut_vec().clone() };
324 let mut cipher = Vec::<u8>::new();
325 tdes.encrypt_vec_into_vec(&message, &mut cipher);
326 print!("C =\t");
327 for c in cipher.clone()
328 { print!("{:02X} ", c); }
329 println!();
330 let mut txt = String::new();
331 for c in cipher.clone()
332 { write!(txt, "{:02X} ", c); }
333 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334 println!("-------------------------------");
335}
336
337fn bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_array()
338{
339 println!("bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_array()");
340 use std::io::Write;
341 use std::fmt::Write as _;
342 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
343
344 // TDES case
345 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348 let message = "In the beginning God created the heavens and the earth.";
349 println!("M =\t{}", message);
350 let message = unsafe { message.to_string().as_mut_vec().clone() };
351 let mut cipher = [0_u8; 56];
352 tdes.encrypt_vec_into_array(&message, &mut cipher);
353 print!("C =\t");
354 for c in cipher.clone()
355 { print!("{:02X} ", c); }
356 println!();
357 let mut txt = String::new();
358 for c in cipher.clone()
359 { write!(txt, "{:02X} ", c); }
360 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361 println!("-------------------------------");
362}
363
364fn bigcryptor64_encrypt_array_with_padding_pkcs7_ecb()
365{
366 println!("bigcryptor64_encrypt_array_with_padding_pkcs7_ecb()");
367 use std::io::Write;
368 use std::fmt::Write as _;
369 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
370
371 // TDES case
372 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375 let mes = "In the beginning God created the heavens and the earth.";
376 println!("M =\t{}", mes);
377 let mut message = [0_u8; 55];
378 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379 let mut cipher = [0_u8; 56];
380 tdes.encrypt_array(&message, cipher.as_mut_ptr());
381 print!("C =\t");
382 for c in cipher.clone()
383 { print!("{:02X} ", c); }
384 println!();
385 let mut txt = String::new();
386 for c in cipher.clone()
387 { write!(txt, "{:02X} ", c); }
388 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389 println!("-------------------------------");
390}
391
392fn bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_vec()
393{
394 println!("bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_vec()");
395 use std::io::Write;
396 use std::fmt::Write as _;
397 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
398
399 // TDES case
400 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403 let mes = "In the beginning God created the heavens and the earth.";
404 println!("M =\t{}", mes);
405 let mut message = [0_u8; 55];
406 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407 let mut cipher = Vec::<u8>::new();
408 tdes.encrypt_array_into_vec(&message, &mut cipher);
409 print!("C =\t");
410 for c in cipher.clone()
411 { print!("{:02X} ", c); }
412 println!();
413 let mut txt = String::new();
414 for c in cipher.clone()
415 { write!(txt, "{:02X} ", c); }
416 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417 println!("-------------------------------");
418}
419
420fn bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_array()
421{
422 println!("bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_array()");
423 use std::io::Write;
424 use std::fmt::Write as _;
425 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
426
427 // TDES case
428 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = [0_u8; 56];
436 tdes.encrypt_array_into_array(&message, &mut cipher);
437 for c in cipher.clone()
438 { print!("{:02X} ", c); }
439 println!();
440 let mut txt = String::new();
441 for c in cipher.clone()
442 { write!(txt, "{:02X} ", c); }
443 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444 println!("-------------------------------");
445}
446
447fn bigcryptor64_decrypt_with_padding_pkcs7_ecb()
448{
449 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb()");
450 use std::io::Write;
451 use std::fmt::Write as _;
452 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
453
454 // TDES case
455 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
456 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
457 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
458 let message = "In the beginning God created the heavens and the earth.";
459 println!("M =\t{}", message);
460 let mut cipher = Vec::<u8>::new();
461 tdes.encrypt_str_into_vec(&message, &mut cipher);
462 print!("C =\t");
463 for c in cipher.clone()
464 { print!("{:02X} ", c); }
465 println!();
466 let mut txt = String::new();
467 for c in cipher.clone()
468 { write!(txt, "{:02X} ", c); }
469 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
470
471 let mut recovered = vec![0; 55];
472 tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
473 print!("Ba =\t");
474 for b in recovered.clone()
475 { print!("{:02X} ", b); }
476 println!();
477 let mut txt = String::new();
478 for c in recovered.clone()
479 { write!(txt, "{:02X} ", c); }
480 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
481
482 let mut converted = String::new();
483 unsafe { converted.as_mut_vec() }.append(&mut recovered);
484
485 println!("Bb =\t{}", converted);
486 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
487 assert_eq!(converted, message);
488 println!("-------------------------------");
489}
490
491fn bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_vec()
492{
493 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_vec()");
494 use std::io::Write;
495 use std::fmt::Write as _;
496 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
497
498 // TDES case
499 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502 let message = "In the beginning God created the heavens and the earth.";
503 println!("M =\t{}", message);
504 let mut cipher = Vec::<u8>::new();
505 tdes.encrypt_str_into_vec(&message, &mut cipher);
506 print!("C =\t");
507 for c in cipher.clone()
508 { print!("{:02X} ", c); }
509 println!();
510 let mut txt = String::new();
511 for c in cipher.clone()
512 { write!(txt, "{:02X} ", c); }
513 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515 let mut recovered = Vec::<u8>::new();
516 tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517 print!("Ba =\t");
518 for b in recovered.clone()
519 { print!("{:02X} ", b); }
520 println!();
521 let mut txt = String::new();
522 for c in recovered.clone()
523 { write!(txt, "{:02X} ", c); }
524 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526 let mut converted = String::new();
527 unsafe { converted.as_mut_vec() }.append(&mut recovered);
528
529 println!("Bb =\t{}", converted);
530 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531 assert_eq!(converted, message);
532 println!("-------------------------------");
533}
534
535fn bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_array()
536{
537 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_array()");
538 use std::io::Write;
539 use std::fmt::Write as _;
540 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
541
542 // TDES case
543 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
544 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
545 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
546 let message = "In the beginning God created the heavens and the earth.";
547 println!("M =\t{}", message);
548 let mut cipher = Vec::<u8>::new();
549 tdes.encrypt_str_into_vec(&message, &mut cipher);
550 print!("C =\t");
551 for c in cipher.clone()
552 { print!("{:02X} ", c); }
553 println!();
554 let mut txt = String::new();
555 for c in cipher.clone()
556 { write!(txt, "{:02X} ", c); }
557 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
558
559 let mut recovered = [0u8; 56];
560 let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
561 print!("Ba =\t");
562 for b in recovered.clone()
563 { print!("{:02X} ", b); }
564 println!();
565 let mut txt = String::new();
566 for c in recovered.clone()
567 { write!(txt, "{:02X} ", c); }
568 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
569
570 let mut converted = String::new();
571 unsafe { converted.as_mut_vec() }.write(&recovered);
572 unsafe { converted.as_mut_vec() }.truncate(len as usize);
573 println!("Bb =\t{}", converted);
574 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
575 assert_eq!(converted, message);
576 println!("-------------------------------");
577}
578
579fn bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_string()
580{
581 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_string()");
582 use std::io::Write;
583 use std::fmt::Write as _;
584 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
585
586 // TDES case
587 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590 let message = "In the beginning God created the heavens and the earth.";
591 println!("M =\t{}", message);
592 let mut cipher = Vec::<u8>::new();
593 tdes.encrypt_str_into_vec(&message, &mut cipher);
594 print!("C =\t");
595 for c in cipher.clone()
596 { print!("{:02X} ", c); }
597 println!();
598 let mut txt = String::new();
599 for c in cipher.clone()
600 { write!(txt, "{:02X} ", c); }
601 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603 let mut recovered = String::new();
604 tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605 println!("B =\t{}", recovered);
606 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607 assert_eq!(recovered, message);
608 println!("-------------------------------");
609}
610
611fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb()
612{
613 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb()");
614 use std::io::Write;
615 use std::fmt::Write as _;
616 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
617
618 // TDES case
619 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622 let message = "In the beginning God created the heavens and the earth.";
623 println!("M =\t{}", message);
624 let mut cipher = Vec::<u8>::new();
625 tdes.encrypt_str_into_vec(&message, &mut cipher);
626 print!("C =\t");
627 for c in cipher.clone()
628 { print!("{:02X} ", c); }
629 println!();
630 let mut txt = String::new();
631 for c in cipher.clone()
632 { write!(txt, "{:02X} ", c); }
633 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635 let mut recovered = vec![0; 55];
636 tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637 print!("Ba =\t");
638 for b in recovered.clone()
639 { print!("{:02X} ", b); }
640 println!();
641 let mut txt = String::new();
642 for c in recovered.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646 let mut converted = String::new();
647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
648
649 println!("Bb =\t{}", converted);
650 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651 assert_eq!(converted, message);
652 println!("-------------------------------");
653}
654
655fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_vec()
656{
657 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_vec()");
658 use std::io::Write;
659 use std::fmt::Write as _;
660 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
661
662 // TDES case
663 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666 let message = "In the beginning God created the heavens and the earth.";
667 println!("M =\t{}", message);
668 let mut cipher = Vec::<u8>::new();
669 tdes.encrypt_str_into_vec(&message, &mut cipher);
670 print!("C =\t");
671 for c in cipher.clone()
672 { print!("{:02X} ", c); }
673 println!();
674 let mut txt = String::new();
675 for c in cipher.clone()
676 { write!(txt, "{:02X} ", c); }
677 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679 let mut recovered = Vec::<u8>::new();
680 tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681 print!("Ba =\t");
682 for b in recovered.clone()
683 { print!("{:02X} ", b); }
684 println!();
685 let mut txt = String::new();
686 for c in recovered.clone()
687 { write!(txt, "{:02X} ", c); }
688 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690 let mut converted = String::new();
691 unsafe { converted.as_mut_vec() }.append(&mut recovered);
692
693 println!("Bb =\t{}", converted);
694 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695 assert_eq!(converted, message);
696 println!("-------------------------------");
697}
698
699fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_array()
700{
701 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_array()");
702 use std::io::Write;
703 use std::fmt::Write as _;
704 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
705
706 // TDES case
707 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710 let message = "In the beginning God created the heavens and the earth.";
711 println!("M =\t{}", message);
712 let mut cipher = Vec::<u8>::new();
713 tdes.encrypt_str_into_vec(&message, &mut cipher);
714 print!("C =\t");
715 for c in cipher.clone()
716 { print!("{:02X} ", c); }
717 println!();
718 let mut txt = String::new();
719 for c in cipher.clone()
720 { write!(txt, "{:02X} ", c); }
721 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723 let mut recovered = [0u8; 56];
724 let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725 print!("Ba =\t");
726 for b in recovered.clone()
727 { print!("{:02X} ", b); }
728 println!();
729 let mut txt = String::new();
730 for c in recovered.clone()
731 { write!(txt, "{:02X} ", c); }
732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734 let mut converted = String::new();
735 unsafe { converted.as_mut_vec() }.write(&recovered);
736 unsafe { converted.as_mut_vec() }.truncate(len as usize);
737 println!("Bb =\t{}", converted);
738 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739 assert_eq!(converted, message);
740 println!("-------------------------------");
741}
742
743fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_string()
744{
745 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_string()");
746 use std::io::Write;
747 use std::fmt::Write as _;
748 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
749
750 // TDES case
751 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(&message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767 let mut recovered = String::new();
768 tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769 println!("B =\t{}", recovered);
770 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771 assert_eq!(recovered, message);
772 println!("-------------------------------");
773}
774
775fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb()
776{
777 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb()");
778 use std::io::Write;
779 use std::fmt::Write as _;
780 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
781
782 // TDES case
783 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
784 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
785 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
786 let message = "In the beginning God created the heavens and the earth.";
787 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
788 tdes.encrypt_str_into_array(&message, &mut cipher);
789 print!("C =\t");
790 for c in cipher.clone()
791 { print!("{:02X} ", c); }
792 println!();
793 let mut txt = String::new();
794 for c in cipher.clone()
795 { write!(txt, "{:02X} ", c); }
796 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
797
798 let mut recovered = vec![0; 55];
799 let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
800 recovered.truncate(len as usize);
801 print!("Ba =\t");
802 for b in recovered.clone()
803 { print!("{:02X} ", b); }
804 println!();
805 let mut txt = String::new();
806 for c in recovered.clone()
807 { write!(txt, "{:02X} ", c); }
808 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
809
810 let mut converted = String::new();
811 unsafe { converted.as_mut_vec() }.append(&mut recovered);
812
813 println!("Bb =\t{}", converted);
814 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
815 assert_eq!(converted, message);
816 println!("-------------------------------");
817}
818
819fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_vec()
820{
821 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_vec()");
822 use std::io::Write;
823 use std::fmt::Write as _;
824 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
825
826 // TDES case
827 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
828 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
829 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
830 let message = "In the beginning God created the heavens and the earth.";
831 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
832 tdes.encrypt_str_into_array(&message, &mut cipher);
833 print!("C =\t");
834 for c in cipher.clone()
835 { print!("{:02X} ", c); }
836 println!();
837 let mut txt = String::new();
838 for c in cipher.clone()
839 { write!(txt, "{:02X} ", c); }
840 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
841
842 let mut recovered = Vec::<u8>::new();
843 tdes.decrypt_array_into_vec(&cipher, &mut recovered);
844 print!("Ba =\t");
845 for b in recovered.clone()
846 { print!("{:02X} ", b); }
847 println!();
848 let mut txt = String::new();
849 for c in recovered.clone()
850 { write!(txt, "{:02X} ", c); }
851 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
852
853 let mut converted = String::new();
854 unsafe { converted.as_mut_vec() }.append(&mut recovered);
855
856 println!("Bb =\t{}", converted);
857 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
858 assert_eq!(converted, message);
859 println!("-------------------------------");
860}
861
862fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_array()
863{
864 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_array()");
865 use std::io::Write;
866 use std::fmt::Write as _;
867 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
868
869 // TDES case
870 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
871 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
872 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
873 let message = "In the beginning God created the heavens and the earth.";
874 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
875 tdes.encrypt_str_into_array(&message, &mut cipher);
876 print!("C =\t");
877 for c in cipher.clone()
878 { print!("{:02X} ", c); }
879 println!();
880 let mut txt = String::new();
881 for c in cipher.clone()
882 { write!(txt, "{:02X} ", c); }
883 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
884
885 let mut recovered = [0u8; 56];
886 let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
887 print!("Ba =\t");
888 for b in recovered.clone()
889 { print!("{:02X} ", b); }
890 println!();
891 let mut txt = String::new();
892 for c in recovered.clone()
893 { write!(txt, "{:02X} ", c); }
894 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
895
896 let mut converted = String::new();
897 unsafe { converted.as_mut_vec() }.write(&recovered);
898 unsafe { converted.as_mut_vec() }.truncate(len as usize);
899 println!("Bb =\t{}", converted);
900 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
901 assert_eq!(converted, message);
902 println!("-------------------------------");
903}
904
905fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_string()
906{
907 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_string()");
908 use std::io::Write;
909 use std::fmt::Write as _;
910 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
911
912 // TDES case
913 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
914 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
915 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
916 let message = "In the beginning God created the heavens and the earth.";
917 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
918 tdes.encrypt_str_into_array(&message, &mut cipher);
919 print!("C =\t");
920 for c in cipher.clone()
921 { print!("{:02X} ", c); }
922 println!();
923 let mut txt = String::new();
924 for c in cipher.clone()
925 { write!(txt, "{:02X} ", c); }
926 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
927
928 let mut recovered = String::new();
929 tdes.decrypt_array_into_string(&cipher, &mut recovered);
930 println!("B =\t{}", recovered);
931 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
932 assert_eq!(recovered, message);
933 println!("-------------------------------");
934}54fn bigcryptor64_encrypt_cfb()
55{
56 println!("bigcryptor64_encrypt_cfb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let iv = 0x_FEDCBA0987654321_u64;
66 println!("IV = {:#018X}", iv);
67 let message = "In the beginning God created the heavens and the earth.";
68 println!("M =\t{}", message);
69 let mut cipher = [0_u8; 55];
70 tdes.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
71 print!("C =\t");
72 for c in cipher.clone()
73 { print!("{:02X} ", c); }
74 println!();
75 let mut txt = String::new();
76 for c in cipher.clone()
77 { write!(txt, "{:02X} ", c); }
78 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
79 println!("-------------------------------");
80}
81
82fn bigcryptor64_encrypt_cfb_into_vec()
83{
84 println!("bigcryptor64_encrypt_cfb_into_vec()");
85 use std::io::Write;
86 use std::fmt::Write as _;
87 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
88
89 // TDES case
90 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
91 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
92 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
93 let iv = 0x_FEDCBA0987654321_u64;
94 println!("IV = {:#018X}", iv);
95 let message = "In the beginning God created the heavens and the earth.";
96 println!("M =\t{}", message);
97 let mut cipher = Vec::<u8>::new();
98 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
99 print!("C =\t");
100 for c in cipher.clone()
101 { print!("{:02X} ", c); }
102 println!();
103 let mut txt = String::new();
104 for c in cipher.clone()
105 { write!(txt, "{:02X} ", c); }
106 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
107 println!("-------------------------------");
108}
109
110fn bigcryptor64_encrypt_cfb_into_array()
111{
112 println!("bigcryptor64_encrypt_cfb_into_array()");
113 use std::io::Write;
114 use std::fmt::Write as _;
115 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
116
117 // TDES case
118 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
119 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
120 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
121 let iv = 0x_FEDCBA0987654321_u64;
122 println!("IV = {:#018X}", iv);
123 let message = "In the beginning God created the heavens and the earth.";
124 println!("M =\t{}", message);
125 let mut cipher = [0_u8; 55];
126 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
127 print!("C =\t");
128 for c in cipher.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
135 println!("-------------------------------");
136}
137
138fn bigcryptor64_encrypt_str_cfb()
139{
140 println!("bigcryptor64_encrypt_str_cfb()");
141 use std::io::Write;
142 use std::fmt::Write as _;
143 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
144
145 // TDES case
146 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
147 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
148 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
149 let iv = 0x_FEDCBA0987654321_u64;
150 println!("IV = {:#018X}", iv);
151 let message = "In the beginning God created the heavens and the earth.";
152 println!("M =\t{}", message);
153 let mut cipher = [0_u8; 55];
154 tdes.encrypt_str(iv, &message, cipher.as_mut_ptr());
155 print!("C =\t");
156 for c in cipher.clone()
157 { print!("{:02X} ", c); }
158 println!();
159 let mut txt = String::new();
160 for c in cipher.clone()
161 { write!(txt, "{:02X} ", c); }
162 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
163 println!("-------------------------------");
164}
165
166fn bigcryptor64_encrypt_str_cfb_into_vec()
167{
168 println!("bigcryptor64_encrypt_str_cfb_into_vec()");
169 use std::io::Write;
170 use std::fmt::Write as _;
171 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
172
173 // TDES case
174 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
175 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
176 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
177 let iv = 0x_FEDCBA0987654321_u64;
178 println!("IV = {:#018X}", iv);
179 let message = "In the beginning God created the heavens and the earth.";
180 let mut cipher = Vec::<u8>::new();
181 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
182 print!("C =\t");
183 for c in cipher.clone()
184 { print!("{:02X} ", c); }
185 println!();
186 let mut txt = String::new();
187 for c in cipher.clone()
188 { write!(txt, "{:02X} ", c); }
189 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
190 println!("-------------------------------");
191}
192
193fn bigcryptor64_encrypt_str_cfb_into_array()
194{
195 println!("bigcryptor64_encrypt_str_cfb_into_array()");
196 use std::io::Write;
197 use std::fmt::Write as _;
198 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
199
200 // TDES case
201 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
202 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
203 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
204 let iv = 0x_FEDCBA0987654321_u64;
205 println!("IV = {:#018X}", iv);
206 let message = "In the beginning God created the heavens and the earth.";
207 let mut cipher = [0_u8; 55];
208 tdes.encrypt_str_into_array(iv, &message, &mut cipher);
209 print!("C =\t");
210 for c in cipher.clone()
211 { print!("{:02X} ", c); }
212 println!();
213 let mut txt = String::new();
214 for c in cipher.clone()
215 { write!(txt, "{:02X} ", c); }
216 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
217 println!("-------------------------------");
218}
219
220fn bigcryptor64_encrypt_string_cfb()
221{
222 println!("bigcryptor64_encrypt_string_cfb()");
223 use std::io::Write;
224 use std::fmt::Write as _;
225 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
226
227 // TDES case
228 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
229 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
230 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
231 let iv = 0x_FEDCBA0987654321_u64;
232 println!("IV = {:#018X}", iv);
233 let message = "In the beginning God created the heavens and the earth.".to_string();
234 let mut cipher = [0_u8; 55];
235 tdes.encrypt_string(iv, &message, cipher.as_mut_ptr());
236 print!("C =\t");
237 for c in cipher.clone()
238 { print!("{:02X} ", c); }
239 println!();
240 let mut txt = String::new();
241 for c in cipher.clone()
242 { write!(txt, "{:02X} ", c); }
243 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
244 println!("-------------------------------");
245}
246
247fn bigcryptor64_encrypt_string_cfb_into_vec()
248{
249 println!("bigcryptor64_encrypt_string_cfb_into_vec()");
250 use std::io::Write;
251 use std::fmt::Write as _;
252 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
253
254 // TDES case
255 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
256 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
257 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
258 let iv = 0x_FEDCBA0987654321_u64;
259 println!("IV = {:#018X}", iv);
260 let message = "In the beginning God created the heavens and the earth.".to_string();
261 let mut cipher = Vec::<u8>::new();
262 tdes.encrypt_string_into_vec(iv, &message, &mut cipher);
263 print!("C =\t");
264 for c in cipher.clone()
265 { print!("{:02X} ", c); }
266 println!();
267 let mut txt = String::new();
268 for c in cipher.clone()
269 { write!(txt, "{:02X} ", c); }
270 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
271 println!("-------------------------------");
272}
273
274fn bigcryptor64_encrypt_string_cfb_into_array()
275{
276 println!("bigcryptor64_encrypt_string_cfb_into_array()");
277 use std::io::Write;
278 use std::fmt::Write as _;
279 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
280
281 // TDES case
282 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
283 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
284 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
285 let iv = 0x_FEDCBA0987654321_u64;
286 println!("IV = {:#018X}", iv);
287 let message = "In the beginning God created the heavens and the earth.".to_string();
288 let mut cipher = [0_u8; 55];
289 tdes.encrypt_string_into_array(iv, &message, &mut cipher);
290 print!("C =\t");
291 for c in cipher.clone()
292 { print!("{:02X} ", c); }
293 println!();
294 let mut txt = String::new();
295 for c in cipher.clone()
296 { write!(txt, "{:02X} ", c); }
297 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
298 println!("-------------------------------");
299}
300
301fn bigcryptor64_encrypt_vec_cfb()
302{
303 println!("bigcryptor64_encrypt_vec_cfb()");
304 use std::io::Write;
305 use std::fmt::Write as _;
306 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
307
308 // TDES case
309 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
310 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
311 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
312 let iv = 0x_FEDCBA0987654321_u64;
313 println!("IV = {:#018X}", iv);
314 let message = "In the beginning God created the heavens and the earth.";
315 println!("M =\t{}", message);
316 let message = unsafe { message.to_string().as_mut_vec().clone() };
317 let mut cipher = [0_u8; 55];
318 tdes.encrypt_vec(iv, &message, cipher.as_mut_ptr());
319 print!("C =\t");
320 for c in cipher.clone()
321 { print!("{:02X} ", c); }
322 println!();
323 let mut txt = String::new();
324 for c in cipher.clone()
325 { write!(txt, "{:02X} ", c); }
326 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
327 println!("-------------------------------");
328}
329
330fn bigcryptor64_encrypt_vec_cfb_into_vec()
331{
332 println!("bigcryptor64_encrypt_vec_cfb_into_vec()");
333 use std::io::Write;
334 use std::fmt::Write as _;
335 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
336
337 // TDES case
338 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
339 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
340 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
341 let iv = 0x_FEDCBA0987654321_u64;
342 println!("IV = {:#018X}", iv);
343 let message = "In the beginning God created the heavens and the earth.";
344 println!("M =\t{}", message);
345 let message = unsafe { message.to_string().as_mut_vec().clone() };
346 let mut cipher = Vec::<u8>::new();
347 tdes.encrypt_vec_into_vec(iv, &message, &mut cipher);
348 print!("C =\t");
349 for c in cipher.clone()
350 { print!("{:02X} ", c); }
351 println!();
352 let mut txt = String::new();
353 for c in cipher.clone()
354 { write!(txt, "{:02X} ", c); }
355 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
356 println!("-------------------------------");
357}
358
359fn bigcryptor64_encrypt_vec_cfb_into_array()
360{
361 println!("bigcryptor64_encrypt_vec_cfb_into_array()");
362 use std::io::Write;
363 use std::fmt::Write as _;
364 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
365
366 // TDES case
367 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
368 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
369 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
370 let iv = 0x_FEDCBA0987654321_u64;
371 println!("IV = {:#018X}", iv);
372 let message = "In the beginning God created the heavens and the earth.";
373 println!("M =\t{}", message);
374 let message = unsafe { message.to_string().as_mut_vec().clone() };
375 let mut cipher = [0_u8; 55];
376 tdes.encrypt_vec_into_array(iv, &message, &mut cipher);
377 print!("C =\t");
378 for c in cipher.clone()
379 { print!("{:02X} ", c); }
380 println!();
381 let mut txt = String::new();
382 for c in cipher.clone()
383 { write!(txt, "{:02X} ", c); }
384 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
385 println!("-------------------------------");
386}
387
388fn bigcryptor64_encrypt_array_cfb()
389{
390 println!("bigcryptor64_encrypt_array_cfb()");
391 use std::io::Write;
392 use std::fmt::Write as _;
393 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
394
395 // TDES case
396 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
397 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
398 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
399 let iv = 0x_FEDCBA0987654321_u64;
400 println!("IV = {:#018X}", iv);
401 let mes = "In the beginning God created the heavens and the earth.";
402 println!("M =\t{}", mes);
403 let mut message = [0_u8; 55];
404 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405 let mut cipher = [0_u8; 55];
406 tdes.encrypt_array(iv, &message, cipher.as_mut_ptr());
407 print!("C =\t");
408 for c in cipher.clone()
409 { print!("{:02X} ", c); }
410 println!();
411 let mut txt = String::new();
412 for c in cipher.clone()
413 { write!(txt, "{:02X} ", c); }
414 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
415 println!("-------------------------------");
416}
417
418fn bigcryptor64_encrypt_array_cfb_into_vec()
419{
420 println!("bigcryptor64_encrypt_array_cfb_into_vec()");
421 use std::io::Write;
422 use std::fmt::Write as _;
423 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
424
425 // TDES case
426 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
427 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
428 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
429 let iv = 0x_FEDCBA0987654321_u64;
430 println!("IV = {:#018X}", iv);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = Vec::<u8>::new();
436 tdes.encrypt_array_into_vec(iv, &message, &mut cipher);
437 print!("C =\t");
438 for c in cipher.clone()
439 { print!("{:02X} ", c); }
440 println!();
441 let mut txt = String::new();
442 for c in cipher.clone()
443 { write!(txt, "{:02X} ", c); }
444 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
445 println!("-------------------------------");
446}
447
448fn bigcryptor64_encrypt_array_cfb_into_array()
449{
450 println!("bigcryptor64_encrypt_array_cfb_into_array()");
451 use std::io::Write;
452 use std::fmt::Write as _;
453 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
454
455 // TDES case
456 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
457 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
458 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
459 let iv = 0x_FEDCBA0987654321_u64;
460 println!("IV = {:#018X}", iv);
461 let mes = "In the beginning God created the heavens and the earth.";
462 println!("M =\t{}", mes);
463 let mut message = [0_u8; 55];
464 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465 let mut cipher = [0_u8; 55];
466 tdes.encrypt_array_into_array(iv, &message, &mut cipher);
467 for c in cipher.clone()
468 { print!("{:02X} ", c); }
469 println!();
470 let mut txt = String::new();
471 for c in cipher.clone()
472 { write!(txt, "{:02X} ", c); }
473 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
474 println!("-------------------------------");
475}
476
477fn bigcryptor64_decrypt_cfb()
478{
479 println!("bigcryptor64_decrypt_cfb()");
480 use std::io::Write;
481 use std::fmt::Write as _;
482 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
483
484 // TDES case
485 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
486 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
487 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
488 let iv = 0x_FEDCBA0987654321_u64;
489 println!("IV = {:#018X}", iv);
490 let message = "In the beginning God created the heavens and the earth.";
491 println!("M =\t{}", message);
492 let mut cipher = Vec::<u8>::new();
493 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
494 print!("C =\t");
495 for c in cipher.clone()
496 { print!("{:02X} ", c); }
497 println!();
498 let mut txt = String::new();
499 for c in cipher.clone()
500 { write!(txt, "{:02X} ", c); }
501 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
502
503 let mut recovered = vec![0; 55];
504 tdes.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
505 print!("Ba =\t");
506 for b in recovered.clone()
507 { print!("{:02X} ", b); }
508 println!();
509 let mut txt = String::new();
510 for c in recovered.clone()
511 { write!(txt, "{:02X} ", c); }
512 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
513
514 let mut converted = String::new();
515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
516
517 println!("Bb =\t{}", converted);
518 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
519 assert_eq!(converted, message);
520 println!("-------------------------------");
521}
522
523fn bigcryptor64_decrypt_cfb_into_vec()
524{
525 println!("bigcryptor64_decrypt_cfb_into_vec()");
526 use std::io::Write;
527 use std::fmt::Write as _;
528 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
529
530 // TDES case
531 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
532 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
533 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
534 let iv = 0x_FEDCBA0987654321_u64;
535 println!("IV = {:#018X}", iv);
536 let message = "In the beginning God created the heavens and the earth.";
537 println!("M =\t{}", message);
538 let mut cipher = Vec::<u8>::new();
539 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
540 print!("C =\t");
541 for c in cipher.clone()
542 { print!("{:02X} ", c); }
543 println!();
544 let mut txt = String::new();
545 for c in cipher.clone()
546 { write!(txt, "{:02X} ", c); }
547 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
548
549 let mut recovered = Vec::<u8>::new();
550 tdes.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551 print!("Ba =\t");
552 for b in recovered.clone()
553 { print!("{:02X} ", b); }
554 println!();
555 let mut txt = String::new();
556 for c in recovered.clone()
557 { write!(txt, "{:02X} ", c); }
558 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560 let mut converted = String::new();
561 unsafe { converted.as_mut_vec() }.append(&mut recovered);
562
563 println!("Bb =\t{}", converted);
564 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565 assert_eq!(converted, message);
566 println!("-------------------------------");
567}
568
569fn bigcryptor64_decrypt_cfb_into_array()
570{
571 println!("bigcryptor64_decrypt_cfb_into_array()");
572 use std::io::Write;
573 use std::fmt::Write as _;
574 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
575
576 // TDES case
577 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
578 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
579 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
580 let iv = 0x_FEDCBA0987654321_u64;
581 println!("IV = {:#018X}", iv);
582 let message = "In the beginning God created the heavens and the earth.";
583 println!("M =\t{}", message);
584 let mut cipher = Vec::<u8>::new();
585 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
586 print!("C =\t");
587 for c in cipher.clone()
588 { print!("{:02X} ", c); }
589 println!();
590 let mut txt = String::new();
591 for c in cipher.clone()
592 { write!(txt, "{:02X} ", c); }
593 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
594
595 let mut recovered = [0u8; 56];
596 let len = tdes.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
597 print!("Ba =\t");
598 for b in recovered.clone()
599 { print!("{:02X} ", b); }
600 println!();
601 let mut txt = String::new();
602 for c in recovered.clone()
603 { write!(txt, "{:02X} ", c); }
604 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
605
606 let mut converted = String::new();
607 unsafe { converted.as_mut_vec() }.write(&recovered);
608 unsafe { converted.as_mut_vec() }.truncate(len as usize);
609 println!("Bb =\t{}", converted);
610 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
611 assert_eq!(converted, message);
612 println!("-------------------------------");
613}
614
615fn bigcryptor64_decrypt_cfb_into_string()
616{
617 println!("bigcryptor64_decrypt_cfb_into_string()");
618 use std::io::Write;
619 use std::fmt::Write as _;
620 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
621
622 // TDES case
623 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
624 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
625 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
626 let iv = 0x_FEDCBA0987654321_u64;
627 println!("IV = {:#018X}", iv);
628 let message = "In the beginning God created the heavens and the earth.";
629 println!("M =\t{}", message);
630 let mut cipher = Vec::<u8>::new();
631 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
632 print!("C =\t");
633 for c in cipher.clone()
634 { print!("{:02X} ", c); }
635 println!();
636 let mut txt = String::new();
637 for c in cipher.clone()
638 { write!(txt, "{:02X} ", c); }
639 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
640
641 let mut recovered = String::new();
642 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643 println!("B =\t{}", recovered);
644 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645 assert_eq!(recovered, message);
646 println!("-------------------------------");
647}
648
649fn bigcryptor64_decrypt_vec_cfb()
650{
651 println!("bigcryptor64_decrypt_vec_cfb()");
652 use std::io::Write;
653 use std::fmt::Write as _;
654 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
655
656 // TDES case
657 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
658 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
659 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
660 let iv = 0x_FEDCBA0987654321_u64;
661 println!("IV = {:#018X}", iv);
662 let message = "In the beginning God created the heavens and the earth.";
663 println!("M =\t{}", message);
664 let mut cipher = Vec::<u8>::new();
665 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
666 print!("C =\t");
667 for c in cipher.clone()
668 { print!("{:02X} ", c); }
669 println!();
670 let mut txt = String::new();
671 for c in cipher.clone()
672 { write!(txt, "{:02X} ", c); }
673 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
674
675 let mut recovered = vec![0; 55];
676 tdes.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
677 print!("Ba =\t");
678 for b in recovered.clone()
679 { print!("{:02X} ", b); }
680 println!();
681 let mut txt = String::new();
682 for c in recovered.clone()
683 { write!(txt, "{:02X} ", c); }
684 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686 let mut converted = String::new();
687 unsafe { converted.as_mut_vec() }.append(&mut recovered);
688
689 println!("Bb =\t{}", converted);
690 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691 assert_eq!(converted, message);
692 println!("-------------------------------");
693}
694
695fn bigcryptor64_decrypt_vec_cfb_into_vec()
696{
697 println!("bigcryptor64_decrypt_vec_cfb_into_vec()");
698 use std::io::Write;
699 use std::fmt::Write as _;
700 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
701
702 // TDES case
703 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
704 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
705 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
706 let iv = 0x_FEDCBA0987654321_u64;
707 println!("IV = {:#018X}", iv);
708 let message = "In the beginning God created the heavens and the earth.";
709 println!("M =\t{}", message);
710 let mut cipher = Vec::<u8>::new();
711 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
720
721 let mut recovered = Vec::<u8>::new();
722 tdes.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
723 print!("Ba =\t");
724 for b in recovered.clone()
725 { print!("{:02X} ", b); }
726 println!();
727 let mut txt = String::new();
728 for c in recovered.clone()
729 { write!(txt, "{:02X} ", c); }
730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732 let mut converted = String::new();
733 unsafe { converted.as_mut_vec() }.append(&mut recovered);
734
735 println!("Bb =\t{}", converted);
736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737 assert_eq!(converted, message);
738 println!("-------------------------------");
739}
740
741fn bigcryptor64_decrypt_vec_cfb_into_array()
742{
743 println!("bigcryptor64_decrypt_vec_cfb_into_array()");
744 use std::io::Write;
745 use std::fmt::Write as _;
746 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
747
748 // TDES case
749 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
750 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
751 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
752 let iv = 0x_FEDCBA0987654321_u64;
753 println!("IV = {:#018X}", iv);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
766
767 let mut recovered = [0u8; 56];
768 let len = tdes.decrypt_vec_into_array(iv, &cipher, &mut recovered);
769 print!("Ba =\t");
770 for b in recovered.clone()
771 { print!("{:02X} ", b); }
772 println!();
773 let mut txt = String::new();
774 for c in recovered.clone()
775 { write!(txt, "{:02X} ", c); }
776 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
777
778 let mut converted = String::new();
779 unsafe { converted.as_mut_vec() }.write(&recovered);
780 unsafe { converted.as_mut_vec() }.truncate(len as usize);
781 println!("Bb =\t{}", converted);
782 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783 assert_eq!(converted, message);
784 println!("-------------------------------");
785}
786
787fn bigcryptor64_decrypt_vec_cfb_into_string()
788{
789 println!("bigcryptor64_decrypt_vec_cfb_into_string()");
790 use std::io::Write;
791 use std::fmt::Write as _;
792 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
793
794 // TDES case
795 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
796 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
797 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
798 let iv = 0x_FEDCBA0987654321_u64;
799 println!("IV = {:#018X}", iv);
800 let message = "In the beginning God created the heavens and the earth.";
801 println!("M =\t{}", message);
802 let mut cipher = Vec::<u8>::new();
803 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
804 print!("C =\t");
805 for c in cipher.clone()
806 { print!("{:02X} ", c); }
807 println!();
808 let mut txt = String::new();
809 for c in cipher.clone()
810 { write!(txt, "{:02X} ", c); }
811 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
812
813 let mut recovered = String::new();
814 tdes.decrypt_vec_into_string(iv, &cipher, &mut recovered);
815 println!("B =\t{}", recovered);
816 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817 assert_eq!(recovered, message);
818 println!("-------------------------------");
819}
820
821fn bigcryptor64_decrypt_array_cfb()
822{
823 println!("bigcryptor64_decrypt_array_cfb()");
824 use std::io::Write;
825 use std::fmt::Write as _;
826 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
827
828 // TDES case
829 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
830 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
831 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
832 let iv = 0x_FEDCBA0987654321_u64;
833 println!("IV = {:#018X}", iv);
834 let message = "In the beginning God created the heavens and the earth.";
835 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
836 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
837 print!("C =\t");
838 for c in cipher.clone()
839 { print!("{:02X} ", c); }
840 println!();
841 let mut txt = String::new();
842 for c in cipher.clone()
843 { write!(txt, "{:02X} ", c); }
844 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
845
846 let mut recovered = vec![0; 55];
847 let len = tdes.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
848 recovered.truncate(len as usize);
849 print!("Ba =\t");
850 for b in recovered.clone()
851 { print!("{:02X} ", b); }
852 println!();
853 let mut txt = String::new();
854 for c in recovered.clone()
855 { write!(txt, "{:02X} ", c); }
856 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
857
858 let mut converted = String::new();
859 unsafe { converted.as_mut_vec() }.append(&mut recovered);
860
861 println!("Bb =\t{}", converted);
862 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
863 assert_eq!(converted, message);
864 println!("-------------------------------");
865}
866
867fn bigcryptor64_decrypt_array_cfb_into_vec()
868{
869 println!("bigcryptor64_decrypt_array_cfb_into_vec()");
870 use std::io::Write;
871 use std::fmt::Write as _;
872 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
873
874 // TDES case
875 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
876 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
877 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
878 let iv = 0x_FEDCBA0987654321_u64;
879 println!("IV = {:#018X}", iv);
880 let message = "In the beginning God created the heavens and the earth.";
881 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
882 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
883 print!("C =\t");
884 for c in cipher.clone()
885 { print!("{:02X} ", c); }
886 println!();
887 let mut txt = String::new();
888 for c in cipher.clone()
889 { write!(txt, "{:02X} ", c); }
890 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
891
892 let mut recovered = Vec::<u8>::new();
893 tdes.decrypt_array_into_vec(iv, &cipher, &mut recovered);
894 print!("Ba =\t");
895 for b in recovered.clone()
896 { print!("{:02X} ", b); }
897 println!();
898 let mut txt = String::new();
899 for c in recovered.clone()
900 { write!(txt, "{:02X} ", c); }
901 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
902
903 let mut converted = String::new();
904 unsafe { converted.as_mut_vec() }.append(&mut recovered);
905
906 println!("Bb =\t{}", converted);
907 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
908 assert_eq!(converted, message);
909 println!("-------------------------------");
910}
911
912fn bigcryptor64_decrypt_array_cfb_into_array()
913{
914 println!("bigcryptor64_decrypt_array_cfb_into_array()");
915 use std::io::Write;
916 use std::fmt::Write as _;
917 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
918
919 // TDES case
920 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
921 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
922 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
923 let iv = 0x_FEDCBA0987654321_u64;
924 println!("IV = {:#018X}", iv);
925 let message = "In the beginning God created the heavens and the earth.";
926 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
927 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
928 print!("C =\t");
929 for c in cipher.clone()
930 { print!("{:02X} ", c); }
931 println!();
932 let mut txt = String::new();
933 for c in cipher.clone()
934 { write!(txt, "{:02X} ", c); }
935 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
936
937 let mut recovered = [0u8; 56];
938 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
939 print!("Ba =\t");
940 for b in recovered.clone()
941 { print!("{:02X} ", b); }
942 println!();
943 let mut txt = String::new();
944 for c in recovered.clone()
945 { write!(txt, "{:02X} ", c); }
946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
947
948 let mut converted = String::new();
949 unsafe { converted.as_mut_vec() }.write(&recovered);
950 unsafe { converted.as_mut_vec() }.truncate(len as usize);
951 println!("Bb =\t{}", converted);
952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
953 assert_eq!(converted, message);
954 println!("-------------------------------");
955}
956
957fn bigcryptor64_decrypt_array_cfb_into_string()
958{
959 println!("bigcryptor64_decrypt_array_cfb_into_string()");
960 use std::io::Write;
961 use std::fmt::Write as _;
962 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
963
964 // TDES case
965 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
966 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
967 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
968 let iv = 0x_FEDCBA0987654321_u64;
969 println!("IV = {:#018X}", iv);
970 let message = "In the beginning God created the heavens and the earth.";
971 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
972 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
973 print!("C =\t");
974 for c in cipher.clone()
975 { print!("{:02X} ", c); }
976 println!();
977 let mut txt = String::new();
978 for c in cipher.clone()
979 { write!(txt, "{:02X} ", c); }
980 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
981
982 let mut recovered = String::new();
983 tdes.decrypt_array_into_string(iv, &cipher, &mut recovered);
984 println!("B =\t{}", recovered);
985 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
986 assert_eq!(recovered, message);
987 println!("-------------------------------");
988}54fn bigcryptor64_encrypt_ofb()
55{
56 println!("bigcryptor64_encrypt_ofb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let iv = 0x_FEDCBA0987654321_u64;
66 println!("IV = {:#018X}", iv);
67 let message = "In the beginning God created the heavens and the earth.";
68 println!("M =\t{}", message);
69 let mut cipher = [0_u8; 55];
70 tdes.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
71 print!("C =\t");
72 for c in cipher.clone()
73 { print!("{:02X} ", c); }
74 println!();
75 let mut txt = String::new();
76 for c in cipher.clone()
77 { write!(txt, "{:02X} ", c); }
78 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
79 println!("-------------------------------");
80}
81
82fn bigcryptor64_encrypt_ofb_into_vec()
83{
84 println!("bigcryptor64_encrypt_ofb_into_vec()");
85 use std::io::Write;
86 use std::fmt::Write as _;
87 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
88
89 // TDES case
90 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
91 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
92 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
93 let iv = 0x_FEDCBA0987654321_u64;
94 println!("IV = {:#018X}", iv);
95 let message = "In the beginning God created the heavens and the earth.";
96 println!("M =\t{}", message);
97 let mut cipher = Vec::<u8>::new();
98 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
99 print!("C =\t");
100 for c in cipher.clone()
101 { print!("{:02X} ", c); }
102 println!();
103 let mut txt = String::new();
104 for c in cipher.clone()
105 { write!(txt, "{:02X} ", c); }
106 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
107 println!("-------------------------------");
108}
109
110fn bigcryptor64_encrypt_ofb_into_array()
111{
112 println!("bigcryptor64_encrypt_ofb_into_array()");
113 use std::io::Write;
114 use std::fmt::Write as _;
115 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
116
117 // TDES case
118 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
119 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
120 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
121 let iv = 0x_FEDCBA0987654321_u64;
122 println!("IV = {:#018X}", iv);
123 let message = "In the beginning God created the heavens and the earth.";
124 println!("M =\t{}", message);
125 let mut cipher = [0_u8; 55];
126 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
127 print!("C =\t");
128 for c in cipher.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
135 println!("-------------------------------");
136}
137
138fn bigcryptor64_encrypt_str_ofb()
139{
140 println!("bigcryptor64_encrypt_str_ofb()");
141 use std::io::Write;
142 use std::fmt::Write as _;
143 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
144
145 // TDES case
146 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
147 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
148 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
149 let iv = 0x_FEDCBA0987654321_u64;
150 println!("IV = {:#018X}", iv);
151 let message = "In the beginning God created the heavens and the earth.";
152 println!("M =\t{}", message);
153 let mut cipher = [0_u8; 55];
154 tdes.encrypt_str(iv, &message, cipher.as_mut_ptr());
155 print!("C =\t");
156 for c in cipher.clone()
157 { print!("{:02X} ", c); }
158 println!();
159 let mut txt = String::new();
160 for c in cipher.clone()
161 { write!(txt, "{:02X} ", c); }
162 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
163 println!("-------------------------------");
164}
165
166fn bigcryptor64_encrypt_str_ofb_into_vec()
167{
168 println!("bigcryptor64_encrypt_str_ofb_into_vec()");
169 use std::io::Write;
170 use std::fmt::Write as _;
171 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
172
173 // TDES case
174 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
175 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
176 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
177 let iv = 0x_FEDCBA0987654321_u64;
178 println!("IV = {:#018X}", iv);
179 let message = "In the beginning God created the heavens and the earth.";
180 let mut cipher = Vec::<u8>::new();
181 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
182 print!("C =\t");
183 for c in cipher.clone()
184 { print!("{:02X} ", c); }
185 println!();
186 let mut txt = String::new();
187 for c in cipher.clone()
188 { write!(txt, "{:02X} ", c); }
189 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
190 println!("-------------------------------");
191}
192
193fn bigcryptor64_encrypt_str_ofb_into_array()
194{
195 println!("bigcryptor64_encrypt_str_ofb_into_array()");
196 use std::io::Write;
197 use std::fmt::Write as _;
198 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
199
200 // TDES case
201 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
202 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
203 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
204 let iv = 0x_FEDCBA0987654321_u64;
205 println!("IV = {:#018X}", iv);
206 let message = "In the beginning God created the heavens and the earth.";
207 let mut cipher = [0_u8; 55];
208 tdes.encrypt_str_into_array(iv, &message, &mut cipher);
209 print!("C =\t");
210 for c in cipher.clone()
211 { print!("{:02X} ", c); }
212 println!();
213 let mut txt = String::new();
214 for c in cipher.clone()
215 { write!(txt, "{:02X} ", c); }
216 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
217 println!("-------------------------------");
218}
219
220fn bigcryptor64_encrypt_string_ofb()
221{
222 println!("bigcryptor64_encrypt_string_ofb()");
223 use std::io::Write;
224 use std::fmt::Write as _;
225 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
226
227 // TDES case
228 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
229 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
230 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
231 let iv = 0x_FEDCBA0987654321_u64;
232 println!("IV = {:#018X}", iv);
233 let message = "In the beginning God created the heavens and the earth.".to_string();
234 let mut cipher = [0_u8; 55];
235 tdes.encrypt_string(iv, &message, cipher.as_mut_ptr());
236 print!("C =\t");
237 for c in cipher.clone()
238 { print!("{:02X} ", c); }
239 println!();
240 let mut txt = String::new();
241 for c in cipher.clone()
242 { write!(txt, "{:02X} ", c); }
243 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
244 println!("-------------------------------");
245}
246
247fn bigcryptor64_encrypt_string_ofb_into_vec()
248{
249 println!("bigcryptor64_encrypt_string_ofb_into_vec()");
250 use std::io::Write;
251 use std::fmt::Write as _;
252 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
253
254 // TDES case
255 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
256 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
257 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
258 let iv = 0x_FEDCBA0987654321_u64;
259 println!("IV = {:#018X}", iv);
260 let message = "In the beginning God created the heavens and the earth.".to_string();
261 let mut cipher = Vec::<u8>::new();
262 tdes.encrypt_string_into_vec(iv, &message, &mut cipher);
263 print!("C =\t");
264 for c in cipher.clone()
265 { print!("{:02X} ", c); }
266 println!();
267 let mut txt = String::new();
268 for c in cipher.clone()
269 { write!(txt, "{:02X} ", c); }
270 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
271 println!("-------------------------------");
272}
273
274fn bigcryptor64_encrypt_string_ofb_into_array()
275{
276 println!("bigcryptor64_encrypt_string_ofb_into_array()");
277 use std::io::Write;
278 use std::fmt::Write as _;
279 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
280
281 // TDES case
282 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
283 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
284 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
285 let iv = 0x_FEDCBA0987654321_u64;
286 println!("IV = {:#018X}", iv);
287 let message = "In the beginning God created the heavens and the earth.".to_string();
288 let mut cipher = [0_u8; 55];
289 tdes.encrypt_string_into_array(iv, &message, &mut cipher);
290 print!("C =\t");
291 for c in cipher.clone()
292 { print!("{:02X} ", c); }
293 println!();
294 let mut txt = String::new();
295 for c in cipher.clone()
296 { write!(txt, "{:02X} ", c); }
297 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
298 println!("-------------------------------");
299}
300
301fn bigcryptor64_encrypt_vec_ofb()
302{
303 println!("bigcryptor64_encrypt_vec_ofb()");
304 use std::io::Write;
305 use std::fmt::Write as _;
306 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
307
308 // TDES case
309 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
310 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
311 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
312 let iv = 0x_FEDCBA0987654321_u64;
313 println!("IV = {:#018X}", iv);
314 let message = "In the beginning God created the heavens and the earth.";
315 println!("M =\t{}", message);
316 let message = unsafe { message.to_string().as_mut_vec().clone() };
317 let mut cipher = [0_u8; 55];
318 tdes.encrypt_vec(iv, &message, cipher.as_mut_ptr());
319 print!("C =\t");
320 for c in cipher.clone()
321 { print!("{:02X} ", c); }
322 println!();
323 let mut txt = String::new();
324 for c in cipher.clone()
325 { write!(txt, "{:02X} ", c); }
326 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
327 println!("-------------------------------");
328}
329
330fn bigcryptor64_encrypt_vec_ofb_into_vec()
331{
332 println!("bigcryptor64_encrypt_vec_ofb_into_vec()");
333 use std::io::Write;
334 use std::fmt::Write as _;
335 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
336
337 // TDES case
338 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
339 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
340 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
341 let iv = 0x_FEDCBA0987654321_u64;
342 println!("IV = {:#018X}", iv);
343 let message = "In the beginning God created the heavens and the earth.";
344 println!("M =\t{}", message);
345 let message = unsafe { message.to_string().as_mut_vec().clone() };
346 let mut cipher = Vec::<u8>::new();
347 tdes.encrypt_vec_into_vec(iv, &message, &mut cipher);
348 print!("C =\t");
349 for c in cipher.clone()
350 { print!("{:02X} ", c); }
351 println!();
352 let mut txt = String::new();
353 for c in cipher.clone()
354 { write!(txt, "{:02X} ", c); }
355 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
356 println!("-------------------------------");
357}
358
359fn bigcryptor64_encrypt_vec_ofb_into_array()
360{
361 println!("bigcryptor64_encrypt_vec_ofb_into_array()");
362 use std::io::Write;
363 use std::fmt::Write as _;
364 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
365
366 // TDES case
367 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
368 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
369 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
370 let iv = 0x_FEDCBA0987654321_u64;
371 println!("IV = {:#018X}", iv);
372 let message = "In the beginning God created the heavens and the earth.";
373 println!("M =\t{}", message);
374 let message = unsafe { message.to_string().as_mut_vec().clone() };
375 let mut cipher = [0_u8; 55];
376 tdes.encrypt_vec_into_array(iv, &message, &mut cipher);
377 print!("C =\t");
378 for c in cipher.clone()
379 { print!("{:02X} ", c); }
380 println!();
381 let mut txt = String::new();
382 for c in cipher.clone()
383 { write!(txt, "{:02X} ", c); }
384 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
385 println!("-------------------------------");
386}
387
388fn bigcryptor64_encrypt_array_ofb()
389{
390 println!("bigcryptor64_encrypt_array_ofb()");
391 use std::io::Write;
392 use std::fmt::Write as _;
393 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
394
395 // TDES case
396 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
397 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
398 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
399 let iv = 0x_FEDCBA0987654321_u64;
400 println!("IV = {:#018X}", iv);
401 let mes = "In the beginning God created the heavens and the earth.";
402 println!("M =\t{}", mes);
403 let mut message = [0_u8; 55];
404 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405 let mut cipher = [0_u8; 55];
406 tdes.encrypt_array(iv, &message, cipher.as_mut_ptr());
407 print!("C =\t");
408 for c in cipher.clone()
409 { print!("{:02X} ", c); }
410 println!();
411 let mut txt = String::new();
412 for c in cipher.clone()
413 { write!(txt, "{:02X} ", c); }
414 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
415 println!("-------------------------------");
416}
417
418fn bigcryptor64_encrypt_array_ofb_into_vec()
419{
420 println!("bigcryptor64_encrypt_array_ofb_into_vec()");
421 use std::io::Write;
422 use std::fmt::Write as _;
423 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
424
425 // TDES case
426 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
427 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
428 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
429 let iv = 0x_FEDCBA0987654321_u64;
430 println!("IV = {:#018X}", iv);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = Vec::<u8>::new();
436 tdes.encrypt_array_into_vec(iv, &message, &mut cipher);
437 print!("C =\t");
438 for c in cipher.clone()
439 { print!("{:02X} ", c); }
440 println!();
441 let mut txt = String::new();
442 for c in cipher.clone()
443 { write!(txt, "{:02X} ", c); }
444 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
445 println!("-------------------------------");
446}
447
448fn bigcryptor64_encrypt_array_ofb_into_array()
449{
450 println!("bigcryptor64_encrypt_array_ofb_into_array()");
451 use std::io::Write;
452 use std::fmt::Write as _;
453 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
454
455 // TDES case
456 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
457 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
458 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
459 let iv = 0x_FEDCBA0987654321_u64;
460 println!("IV = {:#018X}", iv);
461 let mes = "In the beginning God created the heavens and the earth.";
462 println!("M =\t{}", mes);
463 let mut message = [0_u8; 55];
464 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465 let mut cipher = [0_u8; 55];
466 tdes.encrypt_array_into_array(iv, &message, &mut cipher);
467 for c in cipher.clone()
468 { print!("{:02X} ", c); }
469 println!();
470 let mut txt = String::new();
471 for c in cipher.clone()
472 { write!(txt, "{:02X} ", c); }
473 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
474 println!("-------------------------------");
475}
476
477fn bigcryptor64_decrypt_ofb()
478{
479 println!("bigcryptor64_decrypt_ofb()");
480 use std::io::Write;
481 use std::fmt::Write as _;
482 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
483
484 // TDES case
485 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
486 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
487 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
488 let iv = 0x_FEDCBA0987654321_u64;
489 println!("IV = {:#018X}", iv);
490 let message = "In the beginning God created the heavens and the earth.";
491 println!("M =\t{}", message);
492 let mut cipher = Vec::<u8>::new();
493 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
494 print!("C =\t");
495 for c in cipher.clone()
496 { print!("{:02X} ", c); }
497 println!();
498 let mut txt = String::new();
499 for c in cipher.clone()
500 { write!(txt, "{:02X} ", c); }
501 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
502
503 let mut recovered = vec![0; 55];
504 tdes.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
505 print!("Ba =\t");
506 for b in recovered.clone()
507 { print!("{:02X} ", b); }
508 println!();
509 let mut txt = String::new();
510 for c in recovered.clone()
511 { write!(txt, "{:02X} ", c); }
512 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
513
514 let mut converted = String::new();
515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
516
517 println!("Bb =\t{}", converted);
518 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
519 assert_eq!(converted, message);
520 println!("-------------------------------");
521}
522
523fn bigcryptor64_decrypt_ofb_into_vec()
524{
525 println!("bigcryptor64_decrypt_ofb_into_vec()");
526 use std::io::Write;
527 use std::fmt::Write as _;
528 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
529
530 // TDES case
531 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
532 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
533 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
534 let iv = 0x_FEDCBA0987654321_u64;
535 println!("IV = {:#018X}", iv);
536 let message = "In the beginning God created the heavens and the earth.";
537 println!("M =\t{}", message);
538 let mut cipher = Vec::<u8>::new();
539 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
540 print!("C =\t");
541 for c in cipher.clone()
542 { print!("{:02X} ", c); }
543 println!();
544 let mut txt = String::new();
545 for c in cipher.clone()
546 { write!(txt, "{:02X} ", c); }
547 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
548
549 let mut recovered = Vec::<u8>::new();
550 tdes.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551 print!("Ba =\t");
552 for b in recovered.clone()
553 { print!("{:02X} ", b); }
554 println!();
555 let mut txt = String::new();
556 for c in recovered.clone()
557 { write!(txt, "{:02X} ", c); }
558 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560 let mut converted = String::new();
561 unsafe { converted.as_mut_vec() }.append(&mut recovered);
562
563 println!("Bb =\t{}", converted);
564 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565 assert_eq!(converted, message);
566 println!("-------------------------------");
567}
568
569fn bigcryptor64_decrypt_ofb_into_array()
570{
571 println!("bigcryptor64_decrypt_ofb_into_array()");
572 use std::io::Write;
573 use std::fmt::Write as _;
574 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
575
576 // TDES case
577 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
578 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
579 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
580 let iv = 0x_FEDCBA0987654321_u64;
581 println!("IV = {:#018X}", iv);
582 let message = "In the beginning God created the heavens and the earth.";
583 println!("M =\t{}", message);
584 let mut cipher = Vec::<u8>::new();
585 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
586 print!("C =\t");
587 for c in cipher.clone()
588 { print!("{:02X} ", c); }
589 println!();
590 let mut txt = String::new();
591 for c in cipher.clone()
592 { write!(txt, "{:02X} ", c); }
593 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
594
595 let mut recovered = [0u8; 56];
596 let len = tdes.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
597 print!("Ba =\t");
598 for b in recovered.clone()
599 { print!("{:02X} ", b); }
600 println!();
601 let mut txt = String::new();
602 for c in recovered.clone()
603 { write!(txt, "{:02X} ", c); }
604 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
605
606 let mut converted = String::new();
607 unsafe { converted.as_mut_vec() }.write(&recovered);
608 unsafe { converted.as_mut_vec() }.truncate(len as usize);
609 println!("Bb =\t{}", converted);
610 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
611 assert_eq!(converted, message);
612 println!("-------------------------------");
613}
614
615fn bigcryptor64_decrypt_ofb_into_string()
616{
617 println!("bigcryptor64_decrypt_ofb_into_string()");
618 use std::io::Write;
619 use std::fmt::Write as _;
620 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
621
622 // TDES case
623 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
624 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
625 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
626 let iv = 0x_FEDCBA0987654321_u64;
627 println!("IV = {:#018X}", iv);
628 let message = "In the beginning God created the heavens and the earth.";
629 println!("M =\t{}", message);
630 let mut cipher = Vec::<u8>::new();
631 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
632 print!("C =\t");
633 for c in cipher.clone()
634 { print!("{:02X} ", c); }
635 println!();
636 let mut txt = String::new();
637 for c in cipher.clone()
638 { write!(txt, "{:02X} ", c); }
639 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
640
641 let mut recovered = String::new();
642 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643 println!("B =\t{}", recovered);
644 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645 assert_eq!(recovered, message);
646 println!("-------------------------------");
647}
648
649fn bigcryptor64_decrypt_vec_ofb()
650{
651 println!("bigcryptor64_decrypt_vec_ofb()");
652 use std::io::Write;
653 use std::fmt::Write as _;
654 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
655
656 // TDES case
657 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
658 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
659 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
660 let iv = 0x_FEDCBA0987654321_u64;
661 println!("IV = {:#018X}", iv);
662 let message = "In the beginning God created the heavens and the earth.";
663 println!("M =\t{}", message);
664 let mut cipher = Vec::<u8>::new();
665 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
666 print!("C =\t");
667 for c in cipher.clone()
668 { print!("{:02X} ", c); }
669 println!();
670 let mut txt = String::new();
671 for c in cipher.clone()
672 { write!(txt, "{:02X} ", c); }
673 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
674
675 let mut recovered = vec![0; 55];
676 tdes.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
677 print!("Ba =\t");
678 for b in recovered.clone()
679 { print!("{:02X} ", b); }
680 println!();
681 let mut txt = String::new();
682 for c in recovered.clone()
683 { write!(txt, "{:02X} ", c); }
684 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686 let mut converted = String::new();
687 unsafe { converted.as_mut_vec() }.append(&mut recovered);
688
689 println!("Bb =\t{}", converted);
690 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691 assert_eq!(converted, message);
692 println!("-------------------------------");
693}
694
695fn bigcryptor64_decrypt_vec_ofb_into_vec()
696{
697 println!("bigcryptor64_decrypt_vec_ofb_into_vec()");
698 use std::io::Write;
699 use std::fmt::Write as _;
700 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
701
702 // TDES case
703 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
704 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
705 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
706 let iv = 0x_FEDCBA0987654321_u64;
707 println!("IV = {:#018X}", iv);
708 let message = "In the beginning God created the heavens and the earth.";
709 println!("M =\t{}", message);
710 let mut cipher = Vec::<u8>::new();
711 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
720
721 let mut recovered = Vec::<u8>::new();
722 tdes.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
723 print!("Ba =\t");
724 for b in recovered.clone()
725 { print!("{:02X} ", b); }
726 println!();
727 let mut txt = String::new();
728 for c in recovered.clone()
729 { write!(txt, "{:02X} ", c); }
730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732 let mut converted = String::new();
733 unsafe { converted.as_mut_vec() }.append(&mut recovered);
734
735 println!("Bb =\t{}", converted);
736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737 assert_eq!(converted, message);
738 println!("-------------------------------");
739}
740
741fn bigcryptor64_decrypt_vec_ofb_into_array()
742{
743 println!("bigcryptor64_decrypt_vec_ofb_into_array()");
744 use std::io::Write;
745 use std::fmt::Write as _;
746 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
747
748 // TDES case
749 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
750 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
751 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
752 let iv = 0x_FEDCBA0987654321_u64;
753 println!("IV = {:#018X}", iv);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
766
767 let mut recovered = [0u8; 56];
768 let len = tdes.decrypt_vec_into_array(iv, &cipher, &mut recovered);
769 print!("Ba =\t");
770 for b in recovered.clone()
771 { print!("{:02X} ", b); }
772 println!();
773 let mut txt = String::new();
774 for c in recovered.clone()
775 { write!(txt, "{:02X} ", c); }
776 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
777
778 let mut converted = String::new();
779 unsafe { converted.as_mut_vec() }.write(&recovered);
780 unsafe { converted.as_mut_vec() }.truncate(len as usize);
781 println!("Bb =\t{}", converted);
782 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783 assert_eq!(converted, message);
784 println!("-------------------------------");
785}
786
787fn bigcryptor64_decrypt_vec_ofb_into_string()
788{
789 println!("bigcryptor64_decrypt_vec_ofb_into_string()");
790 use std::io::Write;
791 use std::fmt::Write as _;
792 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
793
794 // TDES case
795 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
796 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
797 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
798 let iv = 0x_FEDCBA0987654321_u64;
799 println!("IV = {:#018X}", iv);
800 let message = "In the beginning God created the heavens and the earth.";
801 println!("M =\t{}", message);
802 let mut cipher = Vec::<u8>::new();
803 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
804 print!("C =\t");
805 for c in cipher.clone()
806 { print!("{:02X} ", c); }
807 println!();
808 let mut txt = String::new();
809 for c in cipher.clone()
810 { write!(txt, "{:02X} ", c); }
811 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
812
813 let mut recovered = String::new();
814 tdes.decrypt_vec_into_string(iv, &cipher, &mut recovered);
815 println!("B =\t{}", recovered);
816 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817 assert_eq!(recovered, message);
818 println!("-------------------------------");
819}
820
821fn bigcryptor64_decrypt_array_ofb()
822{
823 println!("bigcryptor64_decrypt_array_ofb()");
824 use std::io::Write;
825 use std::fmt::Write as _;
826 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
827
828 // TDES case
829 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
830 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
831 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
832 let iv = 0x_FEDCBA0987654321_u64;
833 println!("IV = {:#018X}", iv);
834 let message = "In the beginning God created the heavens and the earth.";
835 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
836 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
837 print!("C =\t");
838 for c in cipher.clone()
839 { print!("{:02X} ", c); }
840 println!();
841 let mut txt = String::new();
842 for c in cipher.clone()
843 { write!(txt, "{:02X} ", c); }
844 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
845
846 let mut recovered = vec![0; 55];
847 let len = tdes.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
848 recovered.truncate(len as usize);
849 print!("Ba =\t");
850 for b in recovered.clone()
851 { print!("{:02X} ", b); }
852 println!();
853 let mut txt = String::new();
854 for c in recovered.clone()
855 { write!(txt, "{:02X} ", c); }
856 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
857
858 let mut converted = String::new();
859 unsafe { converted.as_mut_vec() }.append(&mut recovered);
860
861 println!("Bb =\t{}", converted);
862 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
863 assert_eq!(converted, message);
864 println!("-------------------------------");
865}
866
867fn bigcryptor64_decrypt_array_ofb_into_vec()
868{
869 println!("bigcryptor64_decrypt_array_ofb_into_vec()");
870 use std::io::Write;
871 use std::fmt::Write as _;
872 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
873
874 // TDES case
875 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
876 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
877 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
878 let iv = 0x_FEDCBA0987654321_u64;
879 println!("IV = {:#018X}", iv);
880 let message = "In the beginning God created the heavens and the earth.";
881 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
882 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
883 print!("C =\t");
884 for c in cipher.clone()
885 { print!("{:02X} ", c); }
886 println!();
887 let mut txt = String::new();
888 for c in cipher.clone()
889 { write!(txt, "{:02X} ", c); }
890 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
891
892 let mut recovered = Vec::<u8>::new();
893 tdes.decrypt_array_into_vec(iv, &cipher, &mut recovered);
894 print!("Ba =\t");
895 for b in recovered.clone()
896 { print!("{:02X} ", b); }
897 println!();
898 let mut txt = String::new();
899 for c in recovered.clone()
900 { write!(txt, "{:02X} ", c); }
901 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
902
903 let mut converted = String::new();
904 unsafe { converted.as_mut_vec() }.append(&mut recovered);
905
906 println!("Bb =\t{}", converted);
907 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
908 assert_eq!(converted, message);
909 println!("-------------------------------");
910}
911
912fn bigcryptor64_decrypt_array_ofb_into_array()
913{
914 println!("bigcryptor64_decrypt_array_ofb_into_array()");
915 use std::io::Write;
916 use std::fmt::Write as _;
917 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
918
919 // TDES case
920 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
921 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
922 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
923 let iv = 0x_FEDCBA0987654321_u64;
924 println!("IV = {:#018X}", iv);
925 let message = "In the beginning God created the heavens and the earth.";
926 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
927 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
928 print!("C =\t");
929 for c in cipher.clone()
930 { print!("{:02X} ", c); }
931 println!();
932 let mut txt = String::new();
933 for c in cipher.clone()
934 { write!(txt, "{:02X} ", c); }
935 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
936
937 let mut recovered = [0u8; 56];
938 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
939 print!("Ba =\t");
940 for b in recovered.clone()
941 { print!("{:02X} ", b); }
942 println!();
943 let mut txt = String::new();
944 for c in recovered.clone()
945 { write!(txt, "{:02X} ", c); }
946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
947
948 let mut converted = String::new();
949 unsafe { converted.as_mut_vec() }.write(&recovered);
950 unsafe { converted.as_mut_vec() }.truncate(len as usize);
951 println!("Bb =\t{}", converted);
952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
953 assert_eq!(converted, message);
954 println!("-------------------------------");
955}
956
957fn bigcryptor64_decrypt_array_ofb_into_string()
958{
959 println!("bigcryptor64_decrypt_array_ofb_into_string()");
960 use std::io::Write;
961 use std::fmt::Write as _;
962 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
963
964 // TDES case
965 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
966 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
967 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
968 let iv = 0x_FEDCBA0987654321_u64;
969 println!("IV = {:#018X}", iv);
970 let message = "In the beginning God created the heavens and the earth.";
971 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
972 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
973 print!("C =\t");
974 for c in cipher.clone()
975 { print!("{:02X} ", c); }
976 println!();
977 let mut txt = String::new();
978 for c in cipher.clone()
979 { write!(txt, "{:02X} ", c); }
980 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
981
982 let mut recovered = String::new();
983 tdes.decrypt_array_into_string(iv, &cipher, &mut recovered);
984 println!("B =\t{}", recovered);
985 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
986 assert_eq!(recovered, message);
987 println!("-------------------------------");
988}Sourcepub fn decryptor_with_key(key: [u8; 8]) -> Self
pub fn decryptor_with_key(key: [u8; 8]) -> Self
Constructs a new object DES_Generic as a negative encryptor (or a decryptor) for the component of BigCryptor64 incluing NDES.
§Arguments
- The argument
keyis the array of u8 that has 8 elements. - Remember that inverted parity bits do not affect the 56-bit real key. So, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00], [0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01], etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
- You won’t use this method unless you use NDES for such as Triple DES.
- This method sets the key to be the given argument
key. - This method constructs the decryptor component of NDES.
§Example 1
use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
= [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
77fn bigcryptor64_set_keys_later()
78{
79 println!("bigcryptor64_instantiation_with_keys()");
80 use cryptocol::symmetric::{ BigCryptor64, DES };
81 let mut tdes = BigCryptor64::new();
82 let des1 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
83 let des2 = DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]);
84 let des3 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
85 tdes.push_small_cryptor(des1);
86 tdes.push_small_cryptor(des2);
87 tdes.push_small_cryptor(des3);
88 println!("-------------------------------");
89}
90
91fn bigcryptor64_cbc_pkcs7()
92{
93 println!("bigcryptor64_cbc_pkcs7()");
94 use std::fmt::Write as _;
95 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
96 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
97 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
98 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
99
100 let iv = 0x_FEDCBA0987654321_u64;
101 println!("IV = {:#018X}", iv);
102 let message = "In the beginning God created the heavens and the earth.";
103 println!("M =\t{}", message);
104 let mut cipher = Vec::<u8>::new();
105 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
106 print!("C =\t");
107 for c in cipher.clone()
108 { print!("{:02X} ", c); }
109 println!();
110 let mut txt = String::new();
111 for c in cipher.clone()
112 { write!(txt, "{:02X} ", c); }
113 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
114
115 let mut recovered = String::new();
116 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
117 println!("B =\t{}", recovered);
118 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
119 assert_eq!(recovered, message);
120 println!("-------------------------------");
121}
122
123fn bigcryptor64_basic_operation_main()
124{
125 bigcryptor64_new();
126 bigcryptor64_new_with_small_cryptor_array();
127 bigcryptor64_new_with_small_cryptor_vec();
128 bigcryptor64_push_small_cryptor();
129 bigcryptor64_push_small_cryptor_array();
130 bigcryptor64_push_small_cryptor_vec();
131 bigcryptor64_turn_inverse();
132 bigcryptor64_turn_encryptor();
133 bigcryptor64_turn_decryptor();
134 bigcryptor64_encrypt_u64();
135 bigcryptor64_decrypt_u64();
136 bigcryptor64_encrypt_array_u64();
137 bigcryptor64_decrypt_array_u64();
138 bigcryptor64_is_successful();
139 bigcryptor64_is_failed();
140}
141
142fn bigcryptor64_new()
143{
144 println!("bigcryptor64_new()");
145 use cryptocol::symmetric::{ BigCryptor64, DES };
146
147 // Case 1
148 let mut tdes = BigCryptor64::new();
149 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
150 tdes.push_small_cryptor(DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]));
151 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
152
153 // Case 2
154 let mut _tdes = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
155 + DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
156 + DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
157 println!("-------------------------------");
158}More examples
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}Sourcepub fn decryptor_with_key_u64(key: u64) -> Self
pub fn decryptor_with_key_u64(key: u64) -> Self
Constructs a new object DES_Generic as a negative encryptor (or a decryptor) for the component of BigCryptor64 incluing NDES.
§Arguments
- The argument
keyis an unsigned integer that is ofu64-type. - Remember that inverted parity bits do not affect the 56-bit real key. So, 0x0000000000000000_u64, 0x0101010101010101_u64, 0x0000000000000001_u64, 0x0000000000000100_u64, 0x0100001000000001, etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
- You won’t use this method unless you use NDES for such as Triple DES.
- This method sets the key to be the given argument
key. - This method constructs the decryptor component of NDES.
§Example 1
use cryptocol::symmetric::{ BigCryptor64, DES };
let mut tdes = BigCryptor64::new_with_small_cryptor_array(
[ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ] );
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
43fn bigcryptor64_instantiation_with_keys_u64()
44{
45 println!("bigcryptor64_instantiation_with_keys_u64()");
46 use cryptocol::symmetric::{ BigCryptor64, DES };
47 let mut _tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
48 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
49 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
50 println!("-------------------------------");
51}
52
53fn bigcryptor64_instantiation_with_keys()
54{
55 println!("bigcryptor64_instantiation_with_keys()");
56 use cryptocol::symmetric::{ BigCryptor64, DES };
57 let mut _tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
58 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
59 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
60 println!("-------------------------------");
61}
62
63fn bigcryptor64_set_keys_u64_later()
64{
65 println!("bigcryptor64_instantiation_with_keys_u64()");
66 use cryptocol::symmetric::{ BigCryptor64, DES };
67 let mut tdes = BigCryptor64::new();
68 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
69 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
70 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
71 tdes.push_small_cryptor(des1);
72 tdes.push_small_cryptor(des2);
73 tdes.push_small_cryptor(des3);
74 println!("-------------------------------");
75}
76
77fn bigcryptor64_set_keys_later()
78{
79 println!("bigcryptor64_instantiation_with_keys()");
80 use cryptocol::symmetric::{ BigCryptor64, DES };
81 let mut tdes = BigCryptor64::new();
82 let des1 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
83 let des2 = DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]);
84 let des3 = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
85 tdes.push_small_cryptor(des1);
86 tdes.push_small_cryptor(des2);
87 tdes.push_small_cryptor(des3);
88 println!("-------------------------------");
89}
90
91fn bigcryptor64_cbc_pkcs7()
92{
93 println!("bigcryptor64_cbc_pkcs7()");
94 use std::fmt::Write as _;
95 use cryptocol::symmetric::{ BigCryptor64, DES, CBC_PKCS7 };
96 let mut tdes = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
97 - DES::new_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
98 + DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
99
100 let iv = 0x_FEDCBA0987654321_u64;
101 println!("IV = {:#018X}", iv);
102 let message = "In the beginning God created the heavens and the earth.";
103 println!("M =\t{}", message);
104 let mut cipher = Vec::<u8>::new();
105 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
106 print!("C =\t");
107 for c in cipher.clone()
108 { print!("{:02X} ", c); }
109 println!();
110 let mut txt = String::new();
111 for c in cipher.clone()
112 { write!(txt, "{:02X} ", c); }
113 assert_eq!(txt, "86 2B D7 BF 00 2E CD 70 ED 0C E3 8D 75 18 CE 0F BD A7 AE AF E5 19 46 F8 15 7A 24 0E CB 20 91 C0 03 B9 56 C5 77 01 33 E8 8E 84 CA B9 F2 99 63 AC 3A 3D 1F EF CA CA CB 67 ");
114
115 let mut recovered = String::new();
116 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
117 println!("B =\t{}", recovered);
118 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
119 assert_eq!(recovered, message);
120 println!("-------------------------------");
121}
122
123fn bigcryptor64_basic_operation_main()
124{
125 bigcryptor64_new();
126 bigcryptor64_new_with_small_cryptor_array();
127 bigcryptor64_new_with_small_cryptor_vec();
128 bigcryptor64_push_small_cryptor();
129 bigcryptor64_push_small_cryptor_array();
130 bigcryptor64_push_small_cryptor_vec();
131 bigcryptor64_turn_inverse();
132 bigcryptor64_turn_encryptor();
133 bigcryptor64_turn_decryptor();
134 bigcryptor64_encrypt_u64();
135 bigcryptor64_decrypt_u64();
136 bigcryptor64_encrypt_array_u64();
137 bigcryptor64_decrypt_array_u64();
138 bigcryptor64_is_successful();
139 bigcryptor64_is_failed();
140}
141
142fn bigcryptor64_new()
143{
144 println!("bigcryptor64_new()");
145 use cryptocol::symmetric::{ BigCryptor64, DES };
146
147 // Case 1
148 let mut tdes = BigCryptor64::new();
149 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
150 tdes.push_small_cryptor(DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21]));
151 tdes.push_small_cryptor(DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]));
152
153 // Case 2
154 let mut _tdes = DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF])
155 + DES::decryptor_with_key([0xFE, 0xDC, 0xBA, 0x09, 0x87, 0x65, 0x43, 0x21])
156 + DES::encryptor_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
157 println!("-------------------------------");
158}
159
160fn bigcryptor64_new_with_small_cryptor_array()
161{
162 println!("bigcryptor64_new_with_small_cryptor_array()");
163 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
164
165 // Case 1
166 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
167 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
168 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
169 let mut _tdes = BigCryptor64::new_with_small_cryptor_array(cryptors);
170 println!("-------------------------------");
171}
172
173fn bigcryptor64_new_with_small_cryptor_vec()
174{
175 println!("bigcryptor64_new_with_small_cryptor_vec()");
176 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
177
178 // Case 1
179 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
180 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
181 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
182 let mut _tdes = BigCryptor64::new_with_small_cryptor_vec(cryptors);
183 println!("-------------------------------");
184}
185
186fn bigcryptor64_push_small_cryptor()
187{
188 println!("bigcryptor64_new_with_small_cryptor_vec()");
189 use cryptocol::symmetric::{ BigCryptor64, DES };
190
191 // Case 1
192 let mut tdes = BigCryptor64::new();
193 let des1 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let des2 = DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64);
195 let des3 = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
196 tdes.push_small_cryptor(des1);
197 tdes.push_small_cryptor(des2);
198 tdes.push_small_cryptor(des3);
199 println!("-------------------------------");
200}
201
202fn bigcryptor64_push_small_cryptor_array()
203{
204 println!("bigcryptor64_push_small_cryptor_array()");
205 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
206
207 // Case 1
208 let mut tdes = BigCryptor64::new();
209 let cryptors: [Box<dyn SmallCryptor<u64, 8>>; 3] = [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
210 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
211 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
212 tdes.push_small_cryptor_array(cryptors);
213 println!("-------------------------------");
214}
215
216fn bigcryptor64_push_small_cryptor_vec()
217{
218 println!("bigcryptor64_push_small_cryptor_vec()");
219 use cryptocol::symmetric::{ BigCryptor64, SmallCryptor, DES };
220
221 // Case 1
222 let mut tdes = BigCryptor64::new();
223 let cryptors: Vec<Box<dyn SmallCryptor<u64, 8>>> = vec![ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
224 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
225 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ];
226 tdes.push_small_cryptor_vec(cryptors);
227 println!("-------------------------------");
228}More examples
39fn ndes_new_with_keys()
40{
41 println!("ndes_new_with_keys()");
42 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
43
44 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
45 = [ Box::new(DES::encryptor_with_key_u64(0x1234567890ABCDEF_u64)),
46 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
47 Box::new(DES::encryptor_with_key_u64(0x1234567890ABCDEF_u64)) ];
48 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
49 let plaintext = 0x1234567890ABCDEF_u64;
50 let ciphertext = tdes.encrypt_u64(plaintext);
51
52 println!("Plaintext:\t\t{:#016X}", plaintext);
53 println!("Ciphertext:\t\t{:#016X}", ciphertext);
54 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
55
56 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
57 println!("Cipher-ciphertext:\t{:#016X}", cipher_cipher_text);
58 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
59 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
60 println!("-------------------------------");
61}
62
63fn ndes_new_with_keys_u64()
64{
65 println!("ndes_new_with_keys_u64()");
66 use std::fmt::Write as _;
67 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
68
69 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
70 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
71 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
72 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
73 );
74
75 let message = "I am OK.";
76 println!("M =\t{}", message);
77 let mut cipher = [0_u8; 16];
78 tdes.encrypt_str_into_array(&message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "88 89 99 44 30 72 CA 2F 22 4F 7C E0 55 FA 28 C3 ");
87 println!();
88
89 let mut recovered = vec![0; 16];
90 let len = tdes.decrypt_array_into_vec(&cipher, &mut recovered);
91 print!("Ba =\t");
92 for b in recovered.clone()
93 { print!("{:02X} ", b); }
94 println!();
95 let mut txt = String::new();
96 for c in recovered.clone()
97 { write!(txt, "{:02X} ", c); }
98 assert_eq!(txt, "49 20 61 6D 20 4F 4B 2E ");
99
100 let mut converted = String::new();
101 unsafe { converted.as_mut_vec() }.append(&mut recovered);
102 converted.truncate(len as usize);
103
104 println!("Bb =\t{}", converted);
105 assert_eq!(converted, "I am OK.");
106 assert_eq!(converted, message);
107 println!("-------------------------------");
108}54fn bigcryptor64_encrypt_with_padding_iso_ecb()
55{
56 println!("bigcryptor64_encrypt_with_padding_iso_ecb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let message = "In the beginning God created the heavens and the earth.";
66 println!("M =\t{}", message);
67 let mut cipher = [0_u8; 56];
68 tdes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
69 print!("C =\t");
70 for c in cipher.clone()
71 { print!("{:02X} ", c); }
72 println!();
73 let mut txt = String::new();
74 for c in cipher.clone()
75 { write!(txt, "{:02X} ", c); }
76 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
77 println!("-------------------------------");
78}
79
80fn bigcryptor64_encrypt_with_padding_iso_ecb_into_vec()
81{
82 println!("bigcryptor64_encrypt_with_padding_iso_ecb_into_vec()");
83 use std::io::Write;
84 use std::fmt::Write as _;
85 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
86
87 // TDES case
88 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
89 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
90 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
91 let message = "In the beginning God created the heavens and the earth.";
92 println!("M =\t{}", message);
93 let mut cipher = Vec::<u8>::new();
94 tdes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
95 print!("C =\t");
96 for c in cipher.clone()
97 { print!("{:02X} ", c); }
98 println!();
99 let mut txt = String::new();
100 for c in cipher.clone()
101 { write!(txt, "{:02X} ", c); }
102 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
103 println!("-------------------------------");
104}
105
106fn bigcryptor64_encrypt_with_padding_iso_ecb_into_array()
107{
108 println!("bigcryptor64_encrypt_with_padding_iso_ecb_into_array()");
109 use std::io::Write;
110 use std::fmt::Write as _;
111 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
112
113 // TDES case
114 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
115 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
116 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
117 let message = "In the beginning God created the heavens and the earth.";
118 println!("M =\t{}", message);
119 let mut cipher = [0_u8; 56];
120 tdes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
121 print!("C =\t");
122 for c in cipher.clone()
123 { print!("{:02X} ", c); }
124 println!();
125 let mut txt = String::new();
126 for c in cipher.clone()
127 { write!(txt, "{:02X} ", c); }
128 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
129 println!("-------------------------------");
130}
131
132fn bigcryptor64_encrypt_str_with_padding_iso_ecb()
133{
134 println!("bigcryptor64_encrypt_str_with_padding_iso_ecb()");
135 use std::io::Write;
136 use std::fmt::Write as _;
137 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
138
139 // TDES case
140 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
141 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
142 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
143 let message = "In the beginning God created the heavens and the earth.";
144 println!("M =\t{}", message);
145 let mut cipher = [0_u8; 56];
146 tdes.encrypt_str(&message, cipher.as_mut_ptr());
147 print!("C =\t");
148 for c in cipher.clone()
149 { print!("{:02X} ", c); }
150 println!();
151 let mut txt = String::new();
152 for c in cipher.clone()
153 { write!(txt, "{:02X} ", c); }
154 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
155 println!("-------------------------------");
156}
157
158fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_vec()
159{
160 println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_vec()");
161 use std::io::Write;
162 use std::fmt::Write as _;
163 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
164
165 // TDES case
166 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
167 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
168 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
169 let message = "In the beginning God created the heavens and the earth.";
170 let mut cipher = Vec::<u8>::new();
171 tdes.encrypt_str_into_vec(&message, &mut cipher);
172 print!("C =\t");
173 for c in cipher.clone()
174 { print!("{:02X} ", c); }
175 println!();
176 let mut txt = String::new();
177 for c in cipher.clone()
178 { write!(txt, "{:02X} ", c); }
179 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
180 println!("-------------------------------");
181}
182
183fn bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()
184{
185 println!("bigcryptor64_encrypt_str_with_padding_iso_ecb_into_array()");
186 use std::io::Write;
187 use std::fmt::Write as _;
188 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
189
190 // TDES case
191 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
192 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
193 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let message = "In the beginning God created the heavens and the earth.";
195 let mut cipher = [0_u8; 56];
196 tdes.encrypt_str_into_array(&message, &mut cipher);
197 print!("C =\t");
198 for c in cipher.clone()
199 { print!("{:02X} ", c); }
200 println!();
201 let mut txt = String::new();
202 for c in cipher.clone()
203 { write!(txt, "{:02X} ", c); }
204 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
205 println!("-------------------------------");
206}
207
208fn bigcryptor64_encrypt_string_with_padding_iso_ecb()
209{
210 println!("bigcryptor64_encrypt_string_with_padding_iso_ecb()");
211 use std::io::Write;
212 use std::fmt::Write as _;
213 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
214
215 // TDES case
216 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219 let message = "In the beginning God created the heavens and the earth.".to_string();
220 let mut cipher = [0_u8; 56];
221 tdes.encrypt_string(&message, cipher.as_mut_ptr());
222 print!("C =\t");
223 for c in cipher.clone()
224 { print!("{:02X} ", c); }
225 println!();
226 let mut txt = String::new();
227 for c in cipher.clone()
228 { write!(txt, "{:02X} ", c); }
229 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230 println!("-------------------------------");
231}
232
233fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()
234{
235 println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_vec()");
236 use std::io::Write;
237 use std::fmt::Write as _;
238 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
239
240 // TDES case
241 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244 let message = "In the beginning God created the heavens and the earth.".to_string();
245 let mut cipher = Vec::<u8>::new();
246 tdes.encrypt_string_into_vec(&message, &mut cipher);
247 print!("C =\t");
248 for c in cipher.clone()
249 { print!("{:02X} ", c); }
250 println!();
251 let mut txt = String::new();
252 for c in cipher.clone()
253 { write!(txt, "{:02X} ", c); }
254 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255 println!("-------------------------------");
256}
257
258fn bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()
259{
260 println!("bigcryptor64_encrypt_string_with_padding_iso_ecb_into_array()");
261 use std::io::Write;
262 use std::fmt::Write as _;
263 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
264
265 // TDES case
266 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269 let message = "In the beginning God created the heavens and the earth.".to_string();
270 let mut cipher = [0_u8; 56];
271 tdes.encrypt_string_into_array(&message, &mut cipher);
272 print!("C =\t");
273 for c in cipher.clone()
274 { print!("{:02X} ", c); }
275 println!();
276 let mut txt = String::new();
277 for c in cipher.clone()
278 { write!(txt, "{:02X} ", c); }
279 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280 println!("-------------------------------");
281}
282
283fn bigcryptor64_encrypt_vec_with_padding_iso_ecb()
284{
285 println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb()");
286 use std::io::Write;
287 use std::fmt::Write as _;
288 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
289
290 // TDES case
291 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294 let message = "In the beginning God created the heavens and the earth.";
295 println!("M =\t{}", message);
296 let message = unsafe { message.to_string().as_mut_vec().clone() };
297 let mut cipher = [0_u8; 56];
298 tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299 print!("C =\t");
300 for c in cipher.clone()
301 { print!("{:02X} ", c); }
302 println!();
303 let mut txt = String::new();
304 for c in cipher.clone()
305 { write!(txt, "{:02X} ", c); }
306 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307 println!("-------------------------------");
308}
309
310fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()
311{
312 println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_vec()");
313 use std::io::Write;
314 use std::fmt::Write as _;
315 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
316
317 // TDES case
318 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321 let message = "In the beginning God created the heavens and the earth.";
322 println!("M =\t{}", message);
323 let message = unsafe { message.to_string().as_mut_vec().clone() };
324 let mut cipher = Vec::<u8>::new();
325 tdes.encrypt_vec_into_vec(&message, &mut cipher);
326 print!("C =\t");
327 for c in cipher.clone()
328 { print!("{:02X} ", c); }
329 println!();
330 let mut txt = String::new();
331 for c in cipher.clone()
332 { write!(txt, "{:02X} ", c); }
333 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334 println!("-------------------------------");
335}
336
337fn bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()
338{
339 println!("bigcryptor64_encrypt_vec_with_padding_iso_ecb_into_array()");
340 use std::io::Write;
341 use std::fmt::Write as _;
342 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
343
344 // TDES case
345 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348 let message = "In the beginning God created the heavens and the earth.";
349 println!("M =\t{}", message);
350 let message = unsafe { message.to_string().as_mut_vec().clone() };
351 let mut cipher = [0_u8; 56];
352 tdes.encrypt_vec_into_array(&message, &mut cipher);
353 print!("C =\t");
354 for c in cipher.clone()
355 { print!("{:02X} ", c); }
356 println!();
357 let mut txt = String::new();
358 for c in cipher.clone()
359 { write!(txt, "{:02X} ", c); }
360 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361 println!("-------------------------------");
362}
363
364fn bigcryptor64_encrypt_array_with_padding_iso_ecb()
365{
366 println!("bigcryptor64_encrypt_array_with_padding_iso_ecb()");
367 use std::io::Write;
368 use std::fmt::Write as _;
369 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
370
371 // TDES case
372 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375 let mes = "In the beginning God created the heavens and the earth.";
376 println!("M =\t{}", mes);
377 let mut message = [0_u8; 55];
378 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379 let mut cipher = [0_u8; 56];
380 tdes.encrypt_array(&message, cipher.as_mut_ptr());
381 print!("C =\t");
382 for c in cipher.clone()
383 { print!("{:02X} ", c); }
384 println!();
385 let mut txt = String::new();
386 for c in cipher.clone()
387 { write!(txt, "{:02X} ", c); }
388 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389 println!("-------------------------------");
390}
391
392fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()
393{
394 println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_vec()");
395 use std::io::Write;
396 use std::fmt::Write as _;
397 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
398
399 // TDES case
400 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403 let mes = "In the beginning God created the heavens and the earth.";
404 println!("M =\t{}", mes);
405 let mut message = [0_u8; 55];
406 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407 let mut cipher = Vec::<u8>::new();
408 tdes.encrypt_array_into_vec(&message, &mut cipher);
409 print!("C =\t");
410 for c in cipher.clone()
411 { print!("{:02X} ", c); }
412 println!();
413 let mut txt = String::new();
414 for c in cipher.clone()
415 { write!(txt, "{:02X} ", c); }
416 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417 println!("-------------------------------");
418}
419
420fn bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()
421{
422 println!("bigcryptor64_encrypt_array_with_padding_iso_ecb_into_array()");
423 use std::io::Write;
424 use std::fmt::Write as _;
425 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
426
427 // TDES case
428 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = [0_u8; 56];
436 tdes.encrypt_array_into_array(&message, &mut cipher);
437 for c in cipher.clone()
438 { print!("{:02X} ", c); }
439 println!();
440 let mut txt = String::new();
441 for c in cipher.clone()
442 { write!(txt, "{:02X} ", c); }
443 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444 println!("-------------------------------");
445}
446
447fn bigcryptor64_decrypt_with_padding_iso_ecb()
448{
449 println!("bigcryptor64_decrypt_with_padding_iso_ecb()");
450 use std::io::Write;
451 use std::fmt::Write as _;
452 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
453
454 // TDES case
455 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
456 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
457 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
458 let message = "In the beginning God created the heavens and the earth.";
459 println!("M =\t{}", message);
460 let mut cipher = Vec::<u8>::new();
461 tdes.encrypt_str_into_vec(&message, &mut cipher);
462 print!("C =\t");
463 for c in cipher.clone()
464 { print!("{:02X} ", c); }
465 println!();
466 let mut txt = String::new();
467 for c in cipher.clone()
468 { write!(txt, "{:02X} ", c); }
469 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
470
471 let mut recovered = vec![0; 55];
472 tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
473 print!("Ba =\t");
474 for b in recovered.clone()
475 { print!("{:02X} ", b); }
476 println!();
477 let mut txt = String::new();
478 for c in recovered.clone()
479 { write!(txt, "{:02X} ", c); }
480 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
481
482 let mut converted = String::new();
483 unsafe { converted.as_mut_vec() }.append(&mut recovered);
484
485 println!("Bb =\t{}", converted);
486 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
487 assert_eq!(converted, message);
488 println!("-------------------------------");
489}
490
491fn bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()
492{
493 println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_vec()");
494 use std::io::Write;
495 use std::fmt::Write as _;
496 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
497
498 // TDES case
499 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502 let message = "In the beginning God created the heavens and the earth.";
503 println!("M =\t{}", message);
504 let mut cipher = Vec::<u8>::new();
505 tdes.encrypt_str_into_vec(&message, &mut cipher);
506 print!("C =\t");
507 for c in cipher.clone()
508 { print!("{:02X} ", c); }
509 println!();
510 let mut txt = String::new();
511 for c in cipher.clone()
512 { write!(txt, "{:02X} ", c); }
513 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515 let mut recovered = Vec::<u8>::new();
516 tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517 print!("Ba =\t");
518 for b in recovered.clone()
519 { print!("{:02X} ", b); }
520 println!();
521 let mut txt = String::new();
522 for c in recovered.clone()
523 { write!(txt, "{:02X} ", c); }
524 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526 let mut converted = String::new();
527 unsafe { converted.as_mut_vec() }.append(&mut recovered);
528
529 println!("Bb =\t{}", converted);
530 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531 assert_eq!(converted, message);
532 println!("-------------------------------");
533}
534
535fn bigcryptor64_decrypt_with_padding_iso_ecb_into_array()
536{
537 println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_array()");
538 use std::io::Write;
539 use std::fmt::Write as _;
540 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
541
542 // TDES case
543 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
544 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
545 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
546 let message = "In the beginning God created the heavens and the earth.";
547 println!("M =\t{}", message);
548 let mut cipher = Vec::<u8>::new();
549 tdes.encrypt_str_into_vec(&message, &mut cipher);
550 print!("C =\t");
551 for c in cipher.clone()
552 { print!("{:02X} ", c); }
553 println!();
554 let mut txt = String::new();
555 for c in cipher.clone()
556 { write!(txt, "{:02X} ", c); }
557 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
558
559 let mut recovered = [0u8; 56];
560 let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
561 print!("Ba =\t");
562 for b in recovered.clone()
563 { print!("{:02X} ", b); }
564 println!();
565 let mut txt = String::new();
566 for c in recovered.clone()
567 { write!(txt, "{:02X} ", c); }
568 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
569
570 let mut converted = String::new();
571 unsafe { converted.as_mut_vec() }.write(&recovered);
572 unsafe { converted.as_mut_vec() }.truncate(len as usize);
573 println!("Bb =\t{}", converted);
574 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
575 assert_eq!(converted, message);
576 println!("-------------------------------");
577}
578
579fn bigcryptor64_decrypt_with_padding_iso_ecb_into_string()
580{
581 println!("bigcryptor64_decrypt_with_padding_iso_ecb_into_string()");
582 use std::io::Write;
583 use std::fmt::Write as _;
584 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
585
586 // TDES case
587 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590 let message = "In the beginning God created the heavens and the earth.";
591 println!("M =\t{}", message);
592 let mut cipher = Vec::<u8>::new();
593 tdes.encrypt_str_into_vec(&message, &mut cipher);
594 print!("C =\t");
595 for c in cipher.clone()
596 { print!("{:02X} ", c); }
597 println!();
598 let mut txt = String::new();
599 for c in cipher.clone()
600 { write!(txt, "{:02X} ", c); }
601 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603 let mut recovered = String::new();
604 tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605 println!("B =\t{}", recovered);
606 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607 assert_eq!(recovered, message);
608 println!("-------------------------------");
609}
610
611fn bigcryptor64_decrypt_vec_with_padding_iso_ecb()
612{
613 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb()");
614 use std::io::Write;
615 use std::fmt::Write as _;
616 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
617
618 // TDES case
619 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622 let message = "In the beginning God created the heavens and the earth.";
623 println!("M =\t{}", message);
624 let mut cipher = Vec::<u8>::new();
625 tdes.encrypt_str_into_vec(&message, &mut cipher);
626 print!("C =\t");
627 for c in cipher.clone()
628 { print!("{:02X} ", c); }
629 println!();
630 let mut txt = String::new();
631 for c in cipher.clone()
632 { write!(txt, "{:02X} ", c); }
633 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635 let mut recovered = vec![0; 55];
636 tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637 print!("Ba =\t");
638 for b in recovered.clone()
639 { print!("{:02X} ", b); }
640 println!();
641 let mut txt = String::new();
642 for c in recovered.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646 let mut converted = String::new();
647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
648
649 println!("Bb =\t{}", converted);
650 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651 assert_eq!(converted, message);
652 println!("-------------------------------");
653}
654
655fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()
656{
657 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_vec()");
658 use std::io::Write;
659 use std::fmt::Write as _;
660 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
661
662 // TDES case
663 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666 let message = "In the beginning God created the heavens and the earth.";
667 println!("M =\t{}", message);
668 let mut cipher = Vec::<u8>::new();
669 tdes.encrypt_str_into_vec(&message, &mut cipher);
670 print!("C =\t");
671 for c in cipher.clone()
672 { print!("{:02X} ", c); }
673 println!();
674 let mut txt = String::new();
675 for c in cipher.clone()
676 { write!(txt, "{:02X} ", c); }
677 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679 let mut recovered = Vec::<u8>::new();
680 tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681 print!("Ba =\t");
682 for b in recovered.clone()
683 { print!("{:02X} ", b); }
684 println!();
685 let mut txt = String::new();
686 for c in recovered.clone()
687 { write!(txt, "{:02X} ", c); }
688 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690 let mut converted = String::new();
691 unsafe { converted.as_mut_vec() }.append(&mut recovered);
692
693 println!("Bb =\t{}", converted);
694 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695 assert_eq!(converted, message);
696 println!("-------------------------------");
697}
698
699fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()
700{
701 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_array()");
702 use std::io::Write;
703 use std::fmt::Write as _;
704 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
705
706 // TDES case
707 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710 let message = "In the beginning God created the heavens and the earth.";
711 println!("M =\t{}", message);
712 let mut cipher = Vec::<u8>::new();
713 tdes.encrypt_str_into_vec(&message, &mut cipher);
714 print!("C =\t");
715 for c in cipher.clone()
716 { print!("{:02X} ", c); }
717 println!();
718 let mut txt = String::new();
719 for c in cipher.clone()
720 { write!(txt, "{:02X} ", c); }
721 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723 let mut recovered = [0u8; 56];
724 let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725 print!("Ba =\t");
726 for b in recovered.clone()
727 { print!("{:02X} ", b); }
728 println!();
729 let mut txt = String::new();
730 for c in recovered.clone()
731 { write!(txt, "{:02X} ", c); }
732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734 let mut converted = String::new();
735 unsafe { converted.as_mut_vec() }.write(&recovered);
736 unsafe { converted.as_mut_vec() }.truncate(len as usize);
737 println!("Bb =\t{}", converted);
738 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739 assert_eq!(converted, message);
740 println!("-------------------------------");
741}
742
743fn bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()
744{
745 println!("bigcryptor64_decrypt_vec_with_padding_iso_ecb_into_string()");
746 use std::io::Write;
747 use std::fmt::Write as _;
748 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
749
750 // TDES case
751 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(&message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767 let mut recovered = String::new();
768 tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769 println!("B =\t{}", recovered);
770 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771 assert_eq!(recovered, message);
772 println!("-------------------------------");
773}
774
775fn bigcryptor64_decrypt_array_with_padding_iso_ecb()
776{
777 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb()");
778 use std::io::Write;
779 use std::fmt::Write as _;
780 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
781
782 // TDES case
783 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
784 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
785 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
786 let message = "In the beginning God created the heavens and the earth.";
787 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
788 tdes.encrypt_str_into_array(&message, &mut cipher);
789 print!("C =\t");
790 for c in cipher.clone()
791 { print!("{:02X} ", c); }
792 println!();
793 let mut txt = String::new();
794 for c in cipher.clone()
795 { write!(txt, "{:02X} ", c); }
796 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
797
798 let mut recovered = vec![0; 55];
799 let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
800 recovered.truncate(len as usize);
801 print!("Ba =\t");
802 for b in recovered.clone()
803 { print!("{:02X} ", b); }
804 println!();
805 let mut txt = String::new();
806 for c in recovered.clone()
807 { write!(txt, "{:02X} ", c); }
808 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
809
810 let mut converted = String::new();
811 unsafe { converted.as_mut_vec() }.append(&mut recovered);
812
813 println!("Bb =\t{}", converted);
814 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
815 assert_eq!(converted, message);
816 println!("-------------------------------");
817}
818
819fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()
820{
821 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_vec()");
822 use std::io::Write;
823 use std::fmt::Write as _;
824 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
825
826 // TDES case
827 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
828 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
829 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
830 let message = "In the beginning God created the heavens and the earth.";
831 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
832 tdes.encrypt_str_into_array(&message, &mut cipher);
833 print!("C =\t");
834 for c in cipher.clone()
835 { print!("{:02X} ", c); }
836 println!();
837 let mut txt = String::new();
838 for c in cipher.clone()
839 { write!(txt, "{:02X} ", c); }
840 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
841
842 let mut recovered = Vec::<u8>::new();
843 tdes.decrypt_array_into_vec(&cipher, &mut recovered);
844 print!("Ba =\t");
845 for b in recovered.clone()
846 { print!("{:02X} ", b); }
847 println!();
848 let mut txt = String::new();
849 for c in recovered.clone()
850 { write!(txt, "{:02X} ", c); }
851 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
852
853 let mut converted = String::new();
854 unsafe { converted.as_mut_vec() }.append(&mut recovered);
855
856 println!("Bb =\t{}", converted);
857 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
858 assert_eq!(converted, message);
859 println!("-------------------------------");
860}
861
862fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()
863{
864 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_array()");
865 use std::io::Write;
866 use std::fmt::Write as _;
867 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
868
869 // TDES case
870 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
871 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
872 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
873 let message = "In the beginning God created the heavens and the earth.";
874 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
875 tdes.encrypt_str_into_array(&message, &mut cipher);
876 print!("C =\t");
877 for c in cipher.clone()
878 { print!("{:02X} ", c); }
879 println!();
880 let mut txt = String::new();
881 for c in cipher.clone()
882 { write!(txt, "{:02X} ", c); }
883 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
884
885 let mut recovered = [0u8; 56];
886 let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
887 print!("Ba =\t");
888 for b in recovered.clone()
889 { print!("{:02X} ", b); }
890 println!();
891 let mut txt = String::new();
892 for c in recovered.clone()
893 { write!(txt, "{:02X} ", c); }
894 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
895
896 let mut converted = String::new();
897 unsafe { converted.as_mut_vec() }.write(&recovered);
898 unsafe { converted.as_mut_vec() }.truncate(len as usize);
899 println!("Bb =\t{}", converted);
900 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
901 assert_eq!(converted, message);
902 println!("-------------------------------");
903}
904
905fn bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()
906{
907 println!("bigcryptor64_decrypt_array_with_padding_iso_ecb_into_string()");
908 use std::io::Write;
909 use std::fmt::Write as _;
910 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_ISO };
911
912 // TDES case
913 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
914 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
915 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
916 let message = "In the beginning God created the heavens and the earth.";
917 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
918 tdes.encrypt_str_into_array(&message, &mut cipher);
919 print!("C =\t");
920 for c in cipher.clone()
921 { print!("{:02X} ", c); }
922 println!();
923 let mut txt = String::new();
924 for c in cipher.clone()
925 { write!(txt, "{:02X} ", c); }
926 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
927
928 let mut recovered = String::new();
929 tdes.decrypt_array_into_string(&cipher, &mut recovered);
930 println!("B =\t{}", recovered);
931 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
932 assert_eq!(recovered, message);
933 println!("-------------------------------");
934}54fn bigcryptor64_encrypt_with_padding_pkcs7_ecb()
55{
56 println!("bigcryptor64_encrypt_with_padding_pkcs7_ecb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let message = "In the beginning God created the heavens and the earth.";
66 println!("M =\t{}", message);
67 let mut cipher = [0_u8; 56];
68 tdes.encrypt(message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
69 print!("C =\t");
70 for c in cipher.clone()
71 { print!("{:02X} ", c); }
72 println!();
73 let mut txt = String::new();
74 for c in cipher.clone()
75 { write!(txt, "{:02X} ", c); }
76 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
77 println!("-------------------------------");
78}
79
80fn bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_vec()
81{
82 println!("bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_vec()");
83 use std::io::Write;
84 use std::fmt::Write as _;
85 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
86
87 // TDES case
88 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
89 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
90 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
91 let message = "In the beginning God created the heavens and the earth.";
92 println!("M =\t{}", message);
93 let mut cipher = Vec::<u8>::new();
94 tdes.encrypt_into_vec(message.as_ptr(), message.len() as u64, &mut cipher);
95 print!("C =\t");
96 for c in cipher.clone()
97 { print!("{:02X} ", c); }
98 println!();
99 let mut txt = String::new();
100 for c in cipher.clone()
101 { write!(txt, "{:02X} ", c); }
102 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
103 println!("-------------------------------");
104}
105
106fn bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_array()
107{
108 println!("bigcryptor64_encrypt_with_padding_pkcs7_ecb_into_array()");
109 use std::io::Write;
110 use std::fmt::Write as _;
111 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
112
113 // TDES case
114 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
115 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
116 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
117 let message = "In the beginning God created the heavens and the earth.";
118 println!("M =\t{}", message);
119 let mut cipher = [0_u8; 56];
120 tdes.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
121 print!("C =\t");
122 for c in cipher.clone()
123 { print!("{:02X} ", c); }
124 println!();
125 let mut txt = String::new();
126 for c in cipher.clone()
127 { write!(txt, "{:02X} ", c); }
128 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
129 println!("-------------------------------");
130}
131
132fn bigcryptor64_encrypt_str_with_padding_pkcs7_ecb()
133{
134 println!("bigcryptor64_encrypt_str_with_padding_pkcs7_ecb()");
135 use std::io::Write;
136 use std::fmt::Write as _;
137 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
138
139 // TDES case
140 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
141 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
142 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
143 let message = "In the beginning God created the heavens and the earth.";
144 println!("M =\t{}", message);
145 let mut cipher = [0_u8; 56];
146 tdes.encrypt_str(&message, cipher.as_mut_ptr());
147 print!("C =\t");
148 for c in cipher.clone()
149 { print!("{:02X} ", c); }
150 println!();
151 let mut txt = String::new();
152 for c in cipher.clone()
153 { write!(txt, "{:02X} ", c); }
154 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
155 println!("-------------------------------");
156}
157
158fn bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_vec()
159{
160 println!("bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_vec()");
161 use std::io::Write;
162 use std::fmt::Write as _;
163 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
164
165 // TDES case
166 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
167 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
168 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
169 let message = "In the beginning God created the heavens and the earth.";
170 let mut cipher = Vec::<u8>::new();
171 tdes.encrypt_str_into_vec(&message, &mut cipher);
172 print!("C =\t");
173 for c in cipher.clone()
174 { print!("{:02X} ", c); }
175 println!();
176 let mut txt = String::new();
177 for c in cipher.clone()
178 { write!(txt, "{:02X} ", c); }
179 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
180 println!("-------------------------------");
181}
182
183fn bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_array()
184{
185 println!("bigcryptor64_encrypt_str_with_padding_pkcs7_ecb_into_array()");
186 use std::io::Write;
187 use std::fmt::Write as _;
188 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
189
190 // TDES case
191 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
192 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
193 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
194 let message = "In the beginning God created the heavens and the earth.";
195 let mut cipher = [0_u8; 56];
196 tdes.encrypt_str_into_array(&message, &mut cipher);
197 print!("C =\t");
198 for c in cipher.clone()
199 { print!("{:02X} ", c); }
200 println!();
201 let mut txt = String::new();
202 for c in cipher.clone()
203 { write!(txt, "{:02X} ", c); }
204 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
205 println!("-------------------------------");
206}
207
208fn bigcryptor64_encrypt_string_with_padding_pkcs7_ecb()
209{
210 println!("bigcryptor64_encrypt_string_with_padding_pkcs7_ecb()");
211 use std::io::Write;
212 use std::fmt::Write as _;
213 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
214
215 // TDES case
216 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
217 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
218 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
219 let message = "In the beginning God created the heavens and the earth.".to_string();
220 let mut cipher = [0_u8; 56];
221 tdes.encrypt_string(&message, cipher.as_mut_ptr());
222 print!("C =\t");
223 for c in cipher.clone()
224 { print!("{:02X} ", c); }
225 println!();
226 let mut txt = String::new();
227 for c in cipher.clone()
228 { write!(txt, "{:02X} ", c); }
229 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
230 println!("-------------------------------");
231}
232
233fn bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_vec()
234{
235 println!("bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_vec()");
236 use std::io::Write;
237 use std::fmt::Write as _;
238 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
239
240 // TDES case
241 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
242 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
243 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
244 let message = "In the beginning God created the heavens and the earth.".to_string();
245 let mut cipher = Vec::<u8>::new();
246 tdes.encrypt_string_into_vec(&message, &mut cipher);
247 print!("C =\t");
248 for c in cipher.clone()
249 { print!("{:02X} ", c); }
250 println!();
251 let mut txt = String::new();
252 for c in cipher.clone()
253 { write!(txt, "{:02X} ", c); }
254 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
255 println!("-------------------------------");
256}
257
258fn bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_array()
259{
260 println!("bigcryptor64_encrypt_string_with_padding_pkcs7_ecb_into_array()");
261 use std::io::Write;
262 use std::fmt::Write as _;
263 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
264
265 // TDES case
266 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
267 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
268 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
269 let message = "In the beginning God created the heavens and the earth.".to_string();
270 let mut cipher = [0_u8; 56];
271 tdes.encrypt_string_into_array(&message, &mut cipher);
272 print!("C =\t");
273 for c in cipher.clone()
274 { print!("{:02X} ", c); }
275 println!();
276 let mut txt = String::new();
277 for c in cipher.clone()
278 { write!(txt, "{:02X} ", c); }
279 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
280 println!("-------------------------------");
281}
282
283fn bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb()
284{
285 println!("bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb()");
286 use std::io::Write;
287 use std::fmt::Write as _;
288 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
289
290 // TDES case
291 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
292 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
293 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
294 let message = "In the beginning God created the heavens and the earth.";
295 println!("M =\t{}", message);
296 let message = unsafe { message.to_string().as_mut_vec().clone() };
297 let mut cipher = [0_u8; 56];
298 tdes.encrypt_vec(&message, cipher.as_mut_ptr());
299 print!("C =\t");
300 for c in cipher.clone()
301 { print!("{:02X} ", c); }
302 println!();
303 let mut txt = String::new();
304 for c in cipher.clone()
305 { write!(txt, "{:02X} ", c); }
306 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
307 println!("-------------------------------");
308}
309
310fn bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_vec()
311{
312 println!("bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_vec()");
313 use std::io::Write;
314 use std::fmt::Write as _;
315 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
316
317 // TDES case
318 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
319 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
320 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
321 let message = "In the beginning God created the heavens and the earth.";
322 println!("M =\t{}", message);
323 let message = unsafe { message.to_string().as_mut_vec().clone() };
324 let mut cipher = Vec::<u8>::new();
325 tdes.encrypt_vec_into_vec(&message, &mut cipher);
326 print!("C =\t");
327 for c in cipher.clone()
328 { print!("{:02X} ", c); }
329 println!();
330 let mut txt = String::new();
331 for c in cipher.clone()
332 { write!(txt, "{:02X} ", c); }
333 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
334 println!("-------------------------------");
335}
336
337fn bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_array()
338{
339 println!("bigcryptor64_encrypt_vec_with_padding_pkcs7_ecb_into_array()");
340 use std::io::Write;
341 use std::fmt::Write as _;
342 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
343
344 // TDES case
345 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
346 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
347 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
348 let message = "In the beginning God created the heavens and the earth.";
349 println!("M =\t{}", message);
350 let message = unsafe { message.to_string().as_mut_vec().clone() };
351 let mut cipher = [0_u8; 56];
352 tdes.encrypt_vec_into_array(&message, &mut cipher);
353 print!("C =\t");
354 for c in cipher.clone()
355 { print!("{:02X} ", c); }
356 println!();
357 let mut txt = String::new();
358 for c in cipher.clone()
359 { write!(txt, "{:02X} ", c); }
360 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
361 println!("-------------------------------");
362}
363
364fn bigcryptor64_encrypt_array_with_padding_pkcs7_ecb()
365{
366 println!("bigcryptor64_encrypt_array_with_padding_pkcs7_ecb()");
367 use std::io::Write;
368 use std::fmt::Write as _;
369 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
370
371 // TDES case
372 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
373 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
374 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
375 let mes = "In the beginning God created the heavens and the earth.";
376 println!("M =\t{}", mes);
377 let mut message = [0_u8; 55];
378 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
379 let mut cipher = [0_u8; 56];
380 tdes.encrypt_array(&message, cipher.as_mut_ptr());
381 print!("C =\t");
382 for c in cipher.clone()
383 { print!("{:02X} ", c); }
384 println!();
385 let mut txt = String::new();
386 for c in cipher.clone()
387 { write!(txt, "{:02X} ", c); }
388 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
389 println!("-------------------------------");
390}
391
392fn bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_vec()
393{
394 println!("bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_vec()");
395 use std::io::Write;
396 use std::fmt::Write as _;
397 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
398
399 // TDES case
400 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
401 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
402 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
403 let mes = "In the beginning God created the heavens and the earth.";
404 println!("M =\t{}", mes);
405 let mut message = [0_u8; 55];
406 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
407 let mut cipher = Vec::<u8>::new();
408 tdes.encrypt_array_into_vec(&message, &mut cipher);
409 print!("C =\t");
410 for c in cipher.clone()
411 { print!("{:02X} ", c); }
412 println!();
413 let mut txt = String::new();
414 for c in cipher.clone()
415 { write!(txt, "{:02X} ", c); }
416 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
417 println!("-------------------------------");
418}
419
420fn bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_array()
421{
422 println!("bigcryptor64_encrypt_array_with_padding_pkcs7_ecb_into_array()");
423 use std::io::Write;
424 use std::fmt::Write as _;
425 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
426
427 // TDES case
428 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
429 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
430 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = [0_u8; 56];
436 tdes.encrypt_array_into_array(&message, &mut cipher);
437 for c in cipher.clone()
438 { print!("{:02X} ", c); }
439 println!();
440 let mut txt = String::new();
441 for c in cipher.clone()
442 { write!(txt, "{:02X} ", c); }
443 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
444 println!("-------------------------------");
445}
446
447fn bigcryptor64_decrypt_with_padding_pkcs7_ecb()
448{
449 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb()");
450 use std::io::Write;
451 use std::fmt::Write as _;
452 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
453
454 // TDES case
455 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
456 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
457 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
458 let message = "In the beginning God created the heavens and the earth.";
459 println!("M =\t{}", message);
460 let mut cipher = Vec::<u8>::new();
461 tdes.encrypt_str_into_vec(&message, &mut cipher);
462 print!("C =\t");
463 for c in cipher.clone()
464 { print!("{:02X} ", c); }
465 println!();
466 let mut txt = String::new();
467 for c in cipher.clone()
468 { write!(txt, "{:02X} ", c); }
469 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
470
471 let mut recovered = vec![0; 55];
472 tdes.decrypt(cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
473 print!("Ba =\t");
474 for b in recovered.clone()
475 { print!("{:02X} ", b); }
476 println!();
477 let mut txt = String::new();
478 for c in recovered.clone()
479 { write!(txt, "{:02X} ", c); }
480 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
481
482 let mut converted = String::new();
483 unsafe { converted.as_mut_vec() }.append(&mut recovered);
484
485 println!("Bb =\t{}", converted);
486 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
487 assert_eq!(converted, message);
488 println!("-------------------------------");
489}
490
491fn bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_vec()
492{
493 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_vec()");
494 use std::io::Write;
495 use std::fmt::Write as _;
496 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
497
498 // TDES case
499 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
500 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
501 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
502 let message = "In the beginning God created the heavens and the earth.";
503 println!("M =\t{}", message);
504 let mut cipher = Vec::<u8>::new();
505 tdes.encrypt_str_into_vec(&message, &mut cipher);
506 print!("C =\t");
507 for c in cipher.clone()
508 { print!("{:02X} ", c); }
509 println!();
510 let mut txt = String::new();
511 for c in cipher.clone()
512 { write!(txt, "{:02X} ", c); }
513 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
514
515 let mut recovered = Vec::<u8>::new();
516 tdes.decrypt_into_vec(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
517 print!("Ba =\t");
518 for b in recovered.clone()
519 { print!("{:02X} ", b); }
520 println!();
521 let mut txt = String::new();
522 for c in recovered.clone()
523 { write!(txt, "{:02X} ", c); }
524 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
525
526 let mut converted = String::new();
527 unsafe { converted.as_mut_vec() }.append(&mut recovered);
528
529 println!("Bb =\t{}", converted);
530 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
531 assert_eq!(converted, message);
532 println!("-------------------------------");
533}
534
535fn bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_array()
536{
537 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_array()");
538 use std::io::Write;
539 use std::fmt::Write as _;
540 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
541
542 // TDES case
543 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
544 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
545 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
546 let message = "In the beginning God created the heavens and the earth.";
547 println!("M =\t{}", message);
548 let mut cipher = Vec::<u8>::new();
549 tdes.encrypt_str_into_vec(&message, &mut cipher);
550 print!("C =\t");
551 for c in cipher.clone()
552 { print!("{:02X} ", c); }
553 println!();
554 let mut txt = String::new();
555 for c in cipher.clone()
556 { write!(txt, "{:02X} ", c); }
557 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
558
559 let mut recovered = [0u8; 56];
560 let len = tdes.decrypt_into_array(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
561 print!("Ba =\t");
562 for b in recovered.clone()
563 { print!("{:02X} ", b); }
564 println!();
565 let mut txt = String::new();
566 for c in recovered.clone()
567 { write!(txt, "{:02X} ", c); }
568 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
569
570 let mut converted = String::new();
571 unsafe { converted.as_mut_vec() }.write(&recovered);
572 unsafe { converted.as_mut_vec() }.truncate(len as usize);
573 println!("Bb =\t{}", converted);
574 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
575 assert_eq!(converted, message);
576 println!("-------------------------------");
577}
578
579fn bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_string()
580{
581 println!("bigcryptor64_decrypt_with_padding_pkcs7_ecb_into_string()");
582 use std::io::Write;
583 use std::fmt::Write as _;
584 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
585
586 // TDES case
587 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
588 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
589 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
590 let message = "In the beginning God created the heavens and the earth.";
591 println!("M =\t{}", message);
592 let mut cipher = Vec::<u8>::new();
593 tdes.encrypt_str_into_vec(&message, &mut cipher);
594 print!("C =\t");
595 for c in cipher.clone()
596 { print!("{:02X} ", c); }
597 println!();
598 let mut txt = String::new();
599 for c in cipher.clone()
600 { write!(txt, "{:02X} ", c); }
601 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
602
603 let mut recovered = String::new();
604 tdes.decrypt_into_string(cipher.as_ptr(), cipher.len() as u64, &mut recovered);
605 println!("B =\t{}", recovered);
606 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
607 assert_eq!(recovered, message);
608 println!("-------------------------------");
609}
610
611fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb()
612{
613 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb()");
614 use std::io::Write;
615 use std::fmt::Write as _;
616 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
617
618 // TDES case
619 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
620 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
621 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
622 let message = "In the beginning God created the heavens and the earth.";
623 println!("M =\t{}", message);
624 let mut cipher = Vec::<u8>::new();
625 tdes.encrypt_str_into_vec(&message, &mut cipher);
626 print!("C =\t");
627 for c in cipher.clone()
628 { print!("{:02X} ", c); }
629 println!();
630 let mut txt = String::new();
631 for c in cipher.clone()
632 { write!(txt, "{:02X} ", c); }
633 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
634
635 let mut recovered = vec![0; 55];
636 tdes.decrypt_vec(&cipher, recovered.as_mut_ptr());
637 print!("Ba =\t");
638 for b in recovered.clone()
639 { print!("{:02X} ", b); }
640 println!();
641 let mut txt = String::new();
642 for c in recovered.clone()
643 { write!(txt, "{:02X} ", c); }
644 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
645
646 let mut converted = String::new();
647 unsafe { converted.as_mut_vec() }.append(&mut recovered);
648
649 println!("Bb =\t{}", converted);
650 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
651 assert_eq!(converted, message);
652 println!("-------------------------------");
653}
654
655fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_vec()
656{
657 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_vec()");
658 use std::io::Write;
659 use std::fmt::Write as _;
660 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
661
662 // TDES case
663 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
664 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
665 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
666 let message = "In the beginning God created the heavens and the earth.";
667 println!("M =\t{}", message);
668 let mut cipher = Vec::<u8>::new();
669 tdes.encrypt_str_into_vec(&message, &mut cipher);
670 print!("C =\t");
671 for c in cipher.clone()
672 { print!("{:02X} ", c); }
673 println!();
674 let mut txt = String::new();
675 for c in cipher.clone()
676 { write!(txt, "{:02X} ", c); }
677 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
678
679 let mut recovered = Vec::<u8>::new();
680 tdes.decrypt_vec_into_vec(&cipher, &mut recovered);
681 print!("Ba =\t");
682 for b in recovered.clone()
683 { print!("{:02X} ", b); }
684 println!();
685 let mut txt = String::new();
686 for c in recovered.clone()
687 { write!(txt, "{:02X} ", c); }
688 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
689
690 let mut converted = String::new();
691 unsafe { converted.as_mut_vec() }.append(&mut recovered);
692
693 println!("Bb =\t{}", converted);
694 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
695 assert_eq!(converted, message);
696 println!("-------------------------------");
697}
698
699fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_array()
700{
701 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_array()");
702 use std::io::Write;
703 use std::fmt::Write as _;
704 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
705
706 // TDES case
707 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
708 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
709 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
710 let message = "In the beginning God created the heavens and the earth.";
711 println!("M =\t{}", message);
712 let mut cipher = Vec::<u8>::new();
713 tdes.encrypt_str_into_vec(&message, &mut cipher);
714 print!("C =\t");
715 for c in cipher.clone()
716 { print!("{:02X} ", c); }
717 println!();
718 let mut txt = String::new();
719 for c in cipher.clone()
720 { write!(txt, "{:02X} ", c); }
721 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
722
723 let mut recovered = [0u8; 56];
724 let len = tdes.decrypt_vec_into_array(&cipher, &mut recovered);
725 print!("Ba =\t");
726 for b in recovered.clone()
727 { print!("{:02X} ", b); }
728 println!();
729 let mut txt = String::new();
730 for c in recovered.clone()
731 { write!(txt, "{:02X} ", c); }
732 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
733
734 let mut converted = String::new();
735 unsafe { converted.as_mut_vec() }.write(&recovered);
736 unsafe { converted.as_mut_vec() }.truncate(len as usize);
737 println!("Bb =\t{}", converted);
738 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
739 assert_eq!(converted, message);
740 println!("-------------------------------");
741}
742
743fn bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_string()
744{
745 println!("bigcryptor64_decrypt_vec_with_padding_pkcs7_ecb_into_string()");
746 use std::io::Write;
747 use std::fmt::Write as _;
748 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
749
750 // TDES case
751 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
752 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
753 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(&message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
766
767 let mut recovered = String::new();
768 tdes.decrypt_vec_into_string(&cipher, &mut recovered);
769 println!("B =\t{}", recovered);
770 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
771 assert_eq!(recovered, message);
772 println!("-------------------------------");
773}
774
775fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb()
776{
777 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb()");
778 use std::io::Write;
779 use std::fmt::Write as _;
780 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
781
782 // TDES case
783 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
784 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
785 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
786 let message = "In the beginning God created the heavens and the earth.";
787 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
788 tdes.encrypt_str_into_array(&message, &mut cipher);
789 print!("C =\t");
790 for c in cipher.clone()
791 { print!("{:02X} ", c); }
792 println!();
793 let mut txt = String::new();
794 for c in cipher.clone()
795 { write!(txt, "{:02X} ", c); }
796 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
797
798 let mut recovered = vec![0; 55];
799 let len = tdes.decrypt_array(&cipher, recovered.as_mut_ptr());
800 recovered.truncate(len as usize);
801 print!("Ba =\t");
802 for b in recovered.clone()
803 { print!("{:02X} ", b); }
804 println!();
805 let mut txt = String::new();
806 for c in recovered.clone()
807 { write!(txt, "{:02X} ", c); }
808 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
809
810 let mut converted = String::new();
811 unsafe { converted.as_mut_vec() }.append(&mut recovered);
812
813 println!("Bb =\t{}", converted);
814 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
815 assert_eq!(converted, message);
816 println!("-------------------------------");
817}
818
819fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_vec()
820{
821 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_vec()");
822 use std::io::Write;
823 use std::fmt::Write as _;
824 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
825
826 // TDES case
827 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
828 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
829 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
830 let message = "In the beginning God created the heavens and the earth.";
831 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
832 tdes.encrypt_str_into_array(&message, &mut cipher);
833 print!("C =\t");
834 for c in cipher.clone()
835 { print!("{:02X} ", c); }
836 println!();
837 let mut txt = String::new();
838 for c in cipher.clone()
839 { write!(txt, "{:02X} ", c); }
840 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
841
842 let mut recovered = Vec::<u8>::new();
843 tdes.decrypt_array_into_vec(&cipher, &mut recovered);
844 print!("Ba =\t");
845 for b in recovered.clone()
846 { print!("{:02X} ", b); }
847 println!();
848 let mut txt = String::new();
849 for c in recovered.clone()
850 { write!(txt, "{:02X} ", c); }
851 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
852
853 let mut converted = String::new();
854 unsafe { converted.as_mut_vec() }.append(&mut recovered);
855
856 println!("Bb =\t{}", converted);
857 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
858 assert_eq!(converted, message);
859 println!("-------------------------------");
860}
861
862fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_array()
863{
864 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_array()");
865 use std::io::Write;
866 use std::fmt::Write as _;
867 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
868
869 // TDES case
870 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
871 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
872 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
873 let message = "In the beginning God created the heavens and the earth.";
874 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
875 tdes.encrypt_str_into_array(&message, &mut cipher);
876 print!("C =\t");
877 for c in cipher.clone()
878 { print!("{:02X} ", c); }
879 println!();
880 let mut txt = String::new();
881 for c in cipher.clone()
882 { write!(txt, "{:02X} ", c); }
883 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
884
885 let mut recovered = [0u8; 56];
886 let len = tdes.decrypt_array_into_array(&cipher, &mut recovered);
887 print!("Ba =\t");
888 for b in recovered.clone()
889 { print!("{:02X} ", b); }
890 println!();
891 let mut txt = String::new();
892 for c in recovered.clone()
893 { write!(txt, "{:02X} ", c); }
894 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
895
896 let mut converted = String::new();
897 unsafe { converted.as_mut_vec() }.write(&recovered);
898 unsafe { converted.as_mut_vec() }.truncate(len as usize);
899 println!("Bb =\t{}", converted);
900 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
901 assert_eq!(converted, message);
902 println!("-------------------------------");
903}
904
905fn bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_string()
906{
907 println!("bigcryptor64_decrypt_array_with_padding_pkcs7_ecb_into_string()");
908 use std::io::Write;
909 use std::fmt::Write as _;
910 use cryptocol::symmetric::{ BigCryptor64, DES, ECB_PKCS7 };
911
912 // TDES case
913 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
914 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
915 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
916 let message = "In the beginning God created the heavens and the earth.";
917 println!("M =\t{}", message); let mut cipher = [0_u8; 56];
918 tdes.encrypt_str_into_array(&message, &mut cipher);
919 print!("C =\t");
920 for c in cipher.clone()
921 { print!("{:02X} ", c); }
922 println!();
923 let mut txt = String::new();
924 for c in cipher.clone()
925 { write!(txt, "{:02X} ", c); }
926 assert_eq!(txt, "99 2D 87 B2 70 5A 21 3B 7C 93 1A 2E D7 B9 3E E1 FD 47 70 51 48 1F 96 06 2E F3 64 AE 43 11 9C 72 E3 90 65 CF 5B FC 08 12 7A 99 5B B1 2F 7F B4 5D 49 94 44 D4 8B 57 00 30 ");
927
928 let mut recovered = String::new();
929 tdes.decrypt_array_into_string(&cipher, &mut recovered);
930 println!("B =\t{}", recovered);
931 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
932 assert_eq!(recovered, message);
933 println!("-------------------------------");
934}54fn bigcryptor64_encrypt_cfb()
55{
56 println!("bigcryptor64_encrypt_cfb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let iv = 0x_FEDCBA0987654321_u64;
66 println!("IV = {:#018X}", iv);
67 let message = "In the beginning God created the heavens and the earth.";
68 println!("M =\t{}", message);
69 let mut cipher = [0_u8; 55];
70 tdes.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
71 print!("C =\t");
72 for c in cipher.clone()
73 { print!("{:02X} ", c); }
74 println!();
75 let mut txt = String::new();
76 for c in cipher.clone()
77 { write!(txt, "{:02X} ", c); }
78 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
79 println!("-------------------------------");
80}
81
82fn bigcryptor64_encrypt_cfb_into_vec()
83{
84 println!("bigcryptor64_encrypt_cfb_into_vec()");
85 use std::io::Write;
86 use std::fmt::Write as _;
87 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
88
89 // TDES case
90 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
91 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
92 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
93 let iv = 0x_FEDCBA0987654321_u64;
94 println!("IV = {:#018X}", iv);
95 let message = "In the beginning God created the heavens and the earth.";
96 println!("M =\t{}", message);
97 let mut cipher = Vec::<u8>::new();
98 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
99 print!("C =\t");
100 for c in cipher.clone()
101 { print!("{:02X} ", c); }
102 println!();
103 let mut txt = String::new();
104 for c in cipher.clone()
105 { write!(txt, "{:02X} ", c); }
106 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
107 println!("-------------------------------");
108}
109
110fn bigcryptor64_encrypt_cfb_into_array()
111{
112 println!("bigcryptor64_encrypt_cfb_into_array()");
113 use std::io::Write;
114 use std::fmt::Write as _;
115 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
116
117 // TDES case
118 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
119 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
120 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
121 let iv = 0x_FEDCBA0987654321_u64;
122 println!("IV = {:#018X}", iv);
123 let message = "In the beginning God created the heavens and the earth.";
124 println!("M =\t{}", message);
125 let mut cipher = [0_u8; 55];
126 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
127 print!("C =\t");
128 for c in cipher.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
135 println!("-------------------------------");
136}
137
138fn bigcryptor64_encrypt_str_cfb()
139{
140 println!("bigcryptor64_encrypt_str_cfb()");
141 use std::io::Write;
142 use std::fmt::Write as _;
143 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
144
145 // TDES case
146 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
147 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
148 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
149 let iv = 0x_FEDCBA0987654321_u64;
150 println!("IV = {:#018X}", iv);
151 let message = "In the beginning God created the heavens and the earth.";
152 println!("M =\t{}", message);
153 let mut cipher = [0_u8; 55];
154 tdes.encrypt_str(iv, &message, cipher.as_mut_ptr());
155 print!("C =\t");
156 for c in cipher.clone()
157 { print!("{:02X} ", c); }
158 println!();
159 let mut txt = String::new();
160 for c in cipher.clone()
161 { write!(txt, "{:02X} ", c); }
162 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
163 println!("-------------------------------");
164}
165
166fn bigcryptor64_encrypt_str_cfb_into_vec()
167{
168 println!("bigcryptor64_encrypt_str_cfb_into_vec()");
169 use std::io::Write;
170 use std::fmt::Write as _;
171 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
172
173 // TDES case
174 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
175 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
176 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
177 let iv = 0x_FEDCBA0987654321_u64;
178 println!("IV = {:#018X}", iv);
179 let message = "In the beginning God created the heavens and the earth.";
180 let mut cipher = Vec::<u8>::new();
181 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
182 print!("C =\t");
183 for c in cipher.clone()
184 { print!("{:02X} ", c); }
185 println!();
186 let mut txt = String::new();
187 for c in cipher.clone()
188 { write!(txt, "{:02X} ", c); }
189 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
190 println!("-------------------------------");
191}
192
193fn bigcryptor64_encrypt_str_cfb_into_array()
194{
195 println!("bigcryptor64_encrypt_str_cfb_into_array()");
196 use std::io::Write;
197 use std::fmt::Write as _;
198 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
199
200 // TDES case
201 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
202 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
203 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
204 let iv = 0x_FEDCBA0987654321_u64;
205 println!("IV = {:#018X}", iv);
206 let message = "In the beginning God created the heavens and the earth.";
207 let mut cipher = [0_u8; 55];
208 tdes.encrypt_str_into_array(iv, &message, &mut cipher);
209 print!("C =\t");
210 for c in cipher.clone()
211 { print!("{:02X} ", c); }
212 println!();
213 let mut txt = String::new();
214 for c in cipher.clone()
215 { write!(txt, "{:02X} ", c); }
216 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
217 println!("-------------------------------");
218}
219
220fn bigcryptor64_encrypt_string_cfb()
221{
222 println!("bigcryptor64_encrypt_string_cfb()");
223 use std::io::Write;
224 use std::fmt::Write as _;
225 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
226
227 // TDES case
228 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
229 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
230 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
231 let iv = 0x_FEDCBA0987654321_u64;
232 println!("IV = {:#018X}", iv);
233 let message = "In the beginning God created the heavens and the earth.".to_string();
234 let mut cipher = [0_u8; 55];
235 tdes.encrypt_string(iv, &message, cipher.as_mut_ptr());
236 print!("C =\t");
237 for c in cipher.clone()
238 { print!("{:02X} ", c); }
239 println!();
240 let mut txt = String::new();
241 for c in cipher.clone()
242 { write!(txt, "{:02X} ", c); }
243 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
244 println!("-------------------------------");
245}
246
247fn bigcryptor64_encrypt_string_cfb_into_vec()
248{
249 println!("bigcryptor64_encrypt_string_cfb_into_vec()");
250 use std::io::Write;
251 use std::fmt::Write as _;
252 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
253
254 // TDES case
255 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
256 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
257 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
258 let iv = 0x_FEDCBA0987654321_u64;
259 println!("IV = {:#018X}", iv);
260 let message = "In the beginning God created the heavens and the earth.".to_string();
261 let mut cipher = Vec::<u8>::new();
262 tdes.encrypt_string_into_vec(iv, &message, &mut cipher);
263 print!("C =\t");
264 for c in cipher.clone()
265 { print!("{:02X} ", c); }
266 println!();
267 let mut txt = String::new();
268 for c in cipher.clone()
269 { write!(txt, "{:02X} ", c); }
270 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
271 println!("-------------------------------");
272}
273
274fn bigcryptor64_encrypt_string_cfb_into_array()
275{
276 println!("bigcryptor64_encrypt_string_cfb_into_array()");
277 use std::io::Write;
278 use std::fmt::Write as _;
279 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
280
281 // TDES case
282 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
283 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
284 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
285 let iv = 0x_FEDCBA0987654321_u64;
286 println!("IV = {:#018X}", iv);
287 let message = "In the beginning God created the heavens and the earth.".to_string();
288 let mut cipher = [0_u8; 55];
289 tdes.encrypt_string_into_array(iv, &message, &mut cipher);
290 print!("C =\t");
291 for c in cipher.clone()
292 { print!("{:02X} ", c); }
293 println!();
294 let mut txt = String::new();
295 for c in cipher.clone()
296 { write!(txt, "{:02X} ", c); }
297 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
298 println!("-------------------------------");
299}
300
301fn bigcryptor64_encrypt_vec_cfb()
302{
303 println!("bigcryptor64_encrypt_vec_cfb()");
304 use std::io::Write;
305 use std::fmt::Write as _;
306 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
307
308 // TDES case
309 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
310 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
311 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
312 let iv = 0x_FEDCBA0987654321_u64;
313 println!("IV = {:#018X}", iv);
314 let message = "In the beginning God created the heavens and the earth.";
315 println!("M =\t{}", message);
316 let message = unsafe { message.to_string().as_mut_vec().clone() };
317 let mut cipher = [0_u8; 55];
318 tdes.encrypt_vec(iv, &message, cipher.as_mut_ptr());
319 print!("C =\t");
320 for c in cipher.clone()
321 { print!("{:02X} ", c); }
322 println!();
323 let mut txt = String::new();
324 for c in cipher.clone()
325 { write!(txt, "{:02X} ", c); }
326 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
327 println!("-------------------------------");
328}
329
330fn bigcryptor64_encrypt_vec_cfb_into_vec()
331{
332 println!("bigcryptor64_encrypt_vec_cfb_into_vec()");
333 use std::io::Write;
334 use std::fmt::Write as _;
335 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
336
337 // TDES case
338 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
339 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
340 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
341 let iv = 0x_FEDCBA0987654321_u64;
342 println!("IV = {:#018X}", iv);
343 let message = "In the beginning God created the heavens and the earth.";
344 println!("M =\t{}", message);
345 let message = unsafe { message.to_string().as_mut_vec().clone() };
346 let mut cipher = Vec::<u8>::new();
347 tdes.encrypt_vec_into_vec(iv, &message, &mut cipher);
348 print!("C =\t");
349 for c in cipher.clone()
350 { print!("{:02X} ", c); }
351 println!();
352 let mut txt = String::new();
353 for c in cipher.clone()
354 { write!(txt, "{:02X} ", c); }
355 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
356 println!("-------------------------------");
357}
358
359fn bigcryptor64_encrypt_vec_cfb_into_array()
360{
361 println!("bigcryptor64_encrypt_vec_cfb_into_array()");
362 use std::io::Write;
363 use std::fmt::Write as _;
364 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
365
366 // TDES case
367 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
368 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
369 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
370 let iv = 0x_FEDCBA0987654321_u64;
371 println!("IV = {:#018X}", iv);
372 let message = "In the beginning God created the heavens and the earth.";
373 println!("M =\t{}", message);
374 let message = unsafe { message.to_string().as_mut_vec().clone() };
375 let mut cipher = [0_u8; 55];
376 tdes.encrypt_vec_into_array(iv, &message, &mut cipher);
377 print!("C =\t");
378 for c in cipher.clone()
379 { print!("{:02X} ", c); }
380 println!();
381 let mut txt = String::new();
382 for c in cipher.clone()
383 { write!(txt, "{:02X} ", c); }
384 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
385 println!("-------------------------------");
386}
387
388fn bigcryptor64_encrypt_array_cfb()
389{
390 println!("bigcryptor64_encrypt_array_cfb()");
391 use std::io::Write;
392 use std::fmt::Write as _;
393 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
394
395 // TDES case
396 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
397 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
398 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
399 let iv = 0x_FEDCBA0987654321_u64;
400 println!("IV = {:#018X}", iv);
401 let mes = "In the beginning God created the heavens and the earth.";
402 println!("M =\t{}", mes);
403 let mut message = [0_u8; 55];
404 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405 let mut cipher = [0_u8; 55];
406 tdes.encrypt_array(iv, &message, cipher.as_mut_ptr());
407 print!("C =\t");
408 for c in cipher.clone()
409 { print!("{:02X} ", c); }
410 println!();
411 let mut txt = String::new();
412 for c in cipher.clone()
413 { write!(txt, "{:02X} ", c); }
414 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
415 println!("-------------------------------");
416}
417
418fn bigcryptor64_encrypt_array_cfb_into_vec()
419{
420 println!("bigcryptor64_encrypt_array_cfb_into_vec()");
421 use std::io::Write;
422 use std::fmt::Write as _;
423 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
424
425 // TDES case
426 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
427 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
428 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
429 let iv = 0x_FEDCBA0987654321_u64;
430 println!("IV = {:#018X}", iv);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = Vec::<u8>::new();
436 tdes.encrypt_array_into_vec(iv, &message, &mut cipher);
437 print!("C =\t");
438 for c in cipher.clone()
439 { print!("{:02X} ", c); }
440 println!();
441 let mut txt = String::new();
442 for c in cipher.clone()
443 { write!(txt, "{:02X} ", c); }
444 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
445 println!("-------------------------------");
446}
447
448fn bigcryptor64_encrypt_array_cfb_into_array()
449{
450 println!("bigcryptor64_encrypt_array_cfb_into_array()");
451 use std::io::Write;
452 use std::fmt::Write as _;
453 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
454
455 // TDES case
456 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
457 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
458 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
459 let iv = 0x_FEDCBA0987654321_u64;
460 println!("IV = {:#018X}", iv);
461 let mes = "In the beginning God created the heavens and the earth.";
462 println!("M =\t{}", mes);
463 let mut message = [0_u8; 55];
464 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465 let mut cipher = [0_u8; 55];
466 tdes.encrypt_array_into_array(iv, &message, &mut cipher);
467 for c in cipher.clone()
468 { print!("{:02X} ", c); }
469 println!();
470 let mut txt = String::new();
471 for c in cipher.clone()
472 { write!(txt, "{:02X} ", c); }
473 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
474 println!("-------------------------------");
475}
476
477fn bigcryptor64_decrypt_cfb()
478{
479 println!("bigcryptor64_decrypt_cfb()");
480 use std::io::Write;
481 use std::fmt::Write as _;
482 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
483
484 // TDES case
485 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
486 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
487 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
488 let iv = 0x_FEDCBA0987654321_u64;
489 println!("IV = {:#018X}", iv);
490 let message = "In the beginning God created the heavens and the earth.";
491 println!("M =\t{}", message);
492 let mut cipher = Vec::<u8>::new();
493 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
494 print!("C =\t");
495 for c in cipher.clone()
496 { print!("{:02X} ", c); }
497 println!();
498 let mut txt = String::new();
499 for c in cipher.clone()
500 { write!(txt, "{:02X} ", c); }
501 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
502
503 let mut recovered = vec![0; 55];
504 tdes.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
505 print!("Ba =\t");
506 for b in recovered.clone()
507 { print!("{:02X} ", b); }
508 println!();
509 let mut txt = String::new();
510 for c in recovered.clone()
511 { write!(txt, "{:02X} ", c); }
512 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
513
514 let mut converted = String::new();
515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
516
517 println!("Bb =\t{}", converted);
518 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
519 assert_eq!(converted, message);
520 println!("-------------------------------");
521}
522
523fn bigcryptor64_decrypt_cfb_into_vec()
524{
525 println!("bigcryptor64_decrypt_cfb_into_vec()");
526 use std::io::Write;
527 use std::fmt::Write as _;
528 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
529
530 // TDES case
531 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
532 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
533 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
534 let iv = 0x_FEDCBA0987654321_u64;
535 println!("IV = {:#018X}", iv);
536 let message = "In the beginning God created the heavens and the earth.";
537 println!("M =\t{}", message);
538 let mut cipher = Vec::<u8>::new();
539 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
540 print!("C =\t");
541 for c in cipher.clone()
542 { print!("{:02X} ", c); }
543 println!();
544 let mut txt = String::new();
545 for c in cipher.clone()
546 { write!(txt, "{:02X} ", c); }
547 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
548
549 let mut recovered = Vec::<u8>::new();
550 tdes.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551 print!("Ba =\t");
552 for b in recovered.clone()
553 { print!("{:02X} ", b); }
554 println!();
555 let mut txt = String::new();
556 for c in recovered.clone()
557 { write!(txt, "{:02X} ", c); }
558 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560 let mut converted = String::new();
561 unsafe { converted.as_mut_vec() }.append(&mut recovered);
562
563 println!("Bb =\t{}", converted);
564 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565 assert_eq!(converted, message);
566 println!("-------------------------------");
567}
568
569fn bigcryptor64_decrypt_cfb_into_array()
570{
571 println!("bigcryptor64_decrypt_cfb_into_array()");
572 use std::io::Write;
573 use std::fmt::Write as _;
574 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
575
576 // TDES case
577 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
578 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
579 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
580 let iv = 0x_FEDCBA0987654321_u64;
581 println!("IV = {:#018X}", iv);
582 let message = "In the beginning God created the heavens and the earth.";
583 println!("M =\t{}", message);
584 let mut cipher = Vec::<u8>::new();
585 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
586 print!("C =\t");
587 for c in cipher.clone()
588 { print!("{:02X} ", c); }
589 println!();
590 let mut txt = String::new();
591 for c in cipher.clone()
592 { write!(txt, "{:02X} ", c); }
593 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
594
595 let mut recovered = [0u8; 56];
596 let len = tdes.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
597 print!("Ba =\t");
598 for b in recovered.clone()
599 { print!("{:02X} ", b); }
600 println!();
601 let mut txt = String::new();
602 for c in recovered.clone()
603 { write!(txt, "{:02X} ", c); }
604 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
605
606 let mut converted = String::new();
607 unsafe { converted.as_mut_vec() }.write(&recovered);
608 unsafe { converted.as_mut_vec() }.truncate(len as usize);
609 println!("Bb =\t{}", converted);
610 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
611 assert_eq!(converted, message);
612 println!("-------------------------------");
613}
614
615fn bigcryptor64_decrypt_cfb_into_string()
616{
617 println!("bigcryptor64_decrypt_cfb_into_string()");
618 use std::io::Write;
619 use std::fmt::Write as _;
620 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
621
622 // TDES case
623 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
624 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
625 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
626 let iv = 0x_FEDCBA0987654321_u64;
627 println!("IV = {:#018X}", iv);
628 let message = "In the beginning God created the heavens and the earth.";
629 println!("M =\t{}", message);
630 let mut cipher = Vec::<u8>::new();
631 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
632 print!("C =\t");
633 for c in cipher.clone()
634 { print!("{:02X} ", c); }
635 println!();
636 let mut txt = String::new();
637 for c in cipher.clone()
638 { write!(txt, "{:02X} ", c); }
639 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
640
641 let mut recovered = String::new();
642 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643 println!("B =\t{}", recovered);
644 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645 assert_eq!(recovered, message);
646 println!("-------------------------------");
647}
648
649fn bigcryptor64_decrypt_vec_cfb()
650{
651 println!("bigcryptor64_decrypt_vec_cfb()");
652 use std::io::Write;
653 use std::fmt::Write as _;
654 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
655
656 // TDES case
657 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
658 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
659 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
660 let iv = 0x_FEDCBA0987654321_u64;
661 println!("IV = {:#018X}", iv);
662 let message = "In the beginning God created the heavens and the earth.";
663 println!("M =\t{}", message);
664 let mut cipher = Vec::<u8>::new();
665 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
666 print!("C =\t");
667 for c in cipher.clone()
668 { print!("{:02X} ", c); }
669 println!();
670 let mut txt = String::new();
671 for c in cipher.clone()
672 { write!(txt, "{:02X} ", c); }
673 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
674
675 let mut recovered = vec![0; 55];
676 tdes.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
677 print!("Ba =\t");
678 for b in recovered.clone()
679 { print!("{:02X} ", b); }
680 println!();
681 let mut txt = String::new();
682 for c in recovered.clone()
683 { write!(txt, "{:02X} ", c); }
684 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686 let mut converted = String::new();
687 unsafe { converted.as_mut_vec() }.append(&mut recovered);
688
689 println!("Bb =\t{}", converted);
690 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691 assert_eq!(converted, message);
692 println!("-------------------------------");
693}
694
695fn bigcryptor64_decrypt_vec_cfb_into_vec()
696{
697 println!("bigcryptor64_decrypt_vec_cfb_into_vec()");
698 use std::io::Write;
699 use std::fmt::Write as _;
700 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
701
702 // TDES case
703 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
704 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
705 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
706 let iv = 0x_FEDCBA0987654321_u64;
707 println!("IV = {:#018X}", iv);
708 let message = "In the beginning God created the heavens and the earth.";
709 println!("M =\t{}", message);
710 let mut cipher = Vec::<u8>::new();
711 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
720
721 let mut recovered = Vec::<u8>::new();
722 tdes.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
723 print!("Ba =\t");
724 for b in recovered.clone()
725 { print!("{:02X} ", b); }
726 println!();
727 let mut txt = String::new();
728 for c in recovered.clone()
729 { write!(txt, "{:02X} ", c); }
730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732 let mut converted = String::new();
733 unsafe { converted.as_mut_vec() }.append(&mut recovered);
734
735 println!("Bb =\t{}", converted);
736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737 assert_eq!(converted, message);
738 println!("-------------------------------");
739}
740
741fn bigcryptor64_decrypt_vec_cfb_into_array()
742{
743 println!("bigcryptor64_decrypt_vec_cfb_into_array()");
744 use std::io::Write;
745 use std::fmt::Write as _;
746 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
747
748 // TDES case
749 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
750 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
751 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
752 let iv = 0x_FEDCBA0987654321_u64;
753 println!("IV = {:#018X}", iv);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
766
767 let mut recovered = [0u8; 56];
768 let len = tdes.decrypt_vec_into_array(iv, &cipher, &mut recovered);
769 print!("Ba =\t");
770 for b in recovered.clone()
771 { print!("{:02X} ", b); }
772 println!();
773 let mut txt = String::new();
774 for c in recovered.clone()
775 { write!(txt, "{:02X} ", c); }
776 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
777
778 let mut converted = String::new();
779 unsafe { converted.as_mut_vec() }.write(&recovered);
780 unsafe { converted.as_mut_vec() }.truncate(len as usize);
781 println!("Bb =\t{}", converted);
782 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783 assert_eq!(converted, message);
784 println!("-------------------------------");
785}
786
787fn bigcryptor64_decrypt_vec_cfb_into_string()
788{
789 println!("bigcryptor64_decrypt_vec_cfb_into_string()");
790 use std::io::Write;
791 use std::fmt::Write as _;
792 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
793
794 // TDES case
795 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
796 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
797 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
798 let iv = 0x_FEDCBA0987654321_u64;
799 println!("IV = {:#018X}", iv);
800 let message = "In the beginning God created the heavens and the earth.";
801 println!("M =\t{}", message);
802 let mut cipher = Vec::<u8>::new();
803 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
804 print!("C =\t");
805 for c in cipher.clone()
806 { print!("{:02X} ", c); }
807 println!();
808 let mut txt = String::new();
809 for c in cipher.clone()
810 { write!(txt, "{:02X} ", c); }
811 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
812
813 let mut recovered = String::new();
814 tdes.decrypt_vec_into_string(iv, &cipher, &mut recovered);
815 println!("B =\t{}", recovered);
816 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817 assert_eq!(recovered, message);
818 println!("-------------------------------");
819}
820
821fn bigcryptor64_decrypt_array_cfb()
822{
823 println!("bigcryptor64_decrypt_array_cfb()");
824 use std::io::Write;
825 use std::fmt::Write as _;
826 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
827
828 // TDES case
829 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
830 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
831 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
832 let iv = 0x_FEDCBA0987654321_u64;
833 println!("IV = {:#018X}", iv);
834 let message = "In the beginning God created the heavens and the earth.";
835 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
836 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
837 print!("C =\t");
838 for c in cipher.clone()
839 { print!("{:02X} ", c); }
840 println!();
841 let mut txt = String::new();
842 for c in cipher.clone()
843 { write!(txt, "{:02X} ", c); }
844 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
845
846 let mut recovered = vec![0; 55];
847 let len = tdes.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
848 recovered.truncate(len as usize);
849 print!("Ba =\t");
850 for b in recovered.clone()
851 { print!("{:02X} ", b); }
852 println!();
853 let mut txt = String::new();
854 for c in recovered.clone()
855 { write!(txt, "{:02X} ", c); }
856 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
857
858 let mut converted = String::new();
859 unsafe { converted.as_mut_vec() }.append(&mut recovered);
860
861 println!("Bb =\t{}", converted);
862 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
863 assert_eq!(converted, message);
864 println!("-------------------------------");
865}
866
867fn bigcryptor64_decrypt_array_cfb_into_vec()
868{
869 println!("bigcryptor64_decrypt_array_cfb_into_vec()");
870 use std::io::Write;
871 use std::fmt::Write as _;
872 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
873
874 // TDES case
875 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
876 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
877 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
878 let iv = 0x_FEDCBA0987654321_u64;
879 println!("IV = {:#018X}", iv);
880 let message = "In the beginning God created the heavens and the earth.";
881 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
882 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
883 print!("C =\t");
884 for c in cipher.clone()
885 { print!("{:02X} ", c); }
886 println!();
887 let mut txt = String::new();
888 for c in cipher.clone()
889 { write!(txt, "{:02X} ", c); }
890 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
891
892 let mut recovered = Vec::<u8>::new();
893 tdes.decrypt_array_into_vec(iv, &cipher, &mut recovered);
894 print!("Ba =\t");
895 for b in recovered.clone()
896 { print!("{:02X} ", b); }
897 println!();
898 let mut txt = String::new();
899 for c in recovered.clone()
900 { write!(txt, "{:02X} ", c); }
901 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
902
903 let mut converted = String::new();
904 unsafe { converted.as_mut_vec() }.append(&mut recovered);
905
906 println!("Bb =\t{}", converted);
907 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
908 assert_eq!(converted, message);
909 println!("-------------------------------");
910}
911
912fn bigcryptor64_decrypt_array_cfb_into_array()
913{
914 println!("bigcryptor64_decrypt_array_cfb_into_array()");
915 use std::io::Write;
916 use std::fmt::Write as _;
917 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
918
919 // TDES case
920 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
921 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
922 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
923 let iv = 0x_FEDCBA0987654321_u64;
924 println!("IV = {:#018X}", iv);
925 let message = "In the beginning God created the heavens and the earth.";
926 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
927 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
928 print!("C =\t");
929 for c in cipher.clone()
930 { print!("{:02X} ", c); }
931 println!();
932 let mut txt = String::new();
933 for c in cipher.clone()
934 { write!(txt, "{:02X} ", c); }
935 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
936
937 let mut recovered = [0u8; 56];
938 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
939 print!("Ba =\t");
940 for b in recovered.clone()
941 { print!("{:02X} ", b); }
942 println!();
943 let mut txt = String::new();
944 for c in recovered.clone()
945 { write!(txt, "{:02X} ", c); }
946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
947
948 let mut converted = String::new();
949 unsafe { converted.as_mut_vec() }.write(&recovered);
950 unsafe { converted.as_mut_vec() }.truncate(len as usize);
951 println!("Bb =\t{}", converted);
952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
953 assert_eq!(converted, message);
954 println!("-------------------------------");
955}
956
957fn bigcryptor64_decrypt_array_cfb_into_string()
958{
959 println!("bigcryptor64_decrypt_array_cfb_into_string()");
960 use std::io::Write;
961 use std::fmt::Write as _;
962 use cryptocol::symmetric::{ BigCryptor64, DES, CFB };
963
964 // TDES case
965 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
966 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
967 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
968 let iv = 0x_FEDCBA0987654321_u64;
969 println!("IV = {:#018X}", iv);
970 let message = "In the beginning God created the heavens and the earth.";
971 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
972 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
973 print!("C =\t");
974 for c in cipher.clone()
975 { print!("{:02X} ", c); }
976 println!();
977 let mut txt = String::new();
978 for c in cipher.clone()
979 { write!(txt, "{:02X} ", c); }
980 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 FA 6A 68 53 2A 4F CA B8 BB 7E 8D E4 1B 73 2A 9E 79 21 F3 8A 3E 16 10 33 00 EC D8 FC 02 A6 FF DB 8F C4 B1 49 0B AE 70 01 CC 31 6F 85 C3 47 F3 ");
981
982 let mut recovered = String::new();
983 tdes.decrypt_array_into_string(iv, &cipher, &mut recovered);
984 println!("B =\t{}", recovered);
985 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
986 assert_eq!(recovered, message);
987 println!("-------------------------------");
988}54fn bigcryptor64_encrypt_ofb()
55{
56 println!("bigcryptor64_encrypt_ofb()");
57 use std::io::Write;
58 use std::fmt::Write as _;
59 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
60
61 // TDES case
62 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
63 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
64 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
65 let iv = 0x_FEDCBA0987654321_u64;
66 println!("IV = {:#018X}", iv);
67 let message = "In the beginning God created the heavens and the earth.";
68 println!("M =\t{}", message);
69 let mut cipher = [0_u8; 55];
70 tdes.encrypt(iv, message.as_ptr(), message.len() as u64, cipher.as_mut_ptr());
71 print!("C =\t");
72 for c in cipher.clone()
73 { print!("{:02X} ", c); }
74 println!();
75 let mut txt = String::new();
76 for c in cipher.clone()
77 { write!(txt, "{:02X} ", c); }
78 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
79 println!("-------------------------------");
80}
81
82fn bigcryptor64_encrypt_ofb_into_vec()
83{
84 println!("bigcryptor64_encrypt_ofb_into_vec()");
85 use std::io::Write;
86 use std::fmt::Write as _;
87 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
88
89 // TDES case
90 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
91 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
92 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
93 let iv = 0x_FEDCBA0987654321_u64;
94 println!("IV = {:#018X}", iv);
95 let message = "In the beginning God created the heavens and the earth.";
96 println!("M =\t{}", message);
97 let mut cipher = Vec::<u8>::new();
98 tdes.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
99 print!("C =\t");
100 for c in cipher.clone()
101 { print!("{:02X} ", c); }
102 println!();
103 let mut txt = String::new();
104 for c in cipher.clone()
105 { write!(txt, "{:02X} ", c); }
106 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
107 println!("-------------------------------");
108}
109
110fn bigcryptor64_encrypt_ofb_into_array()
111{
112 println!("bigcryptor64_encrypt_ofb_into_array()");
113 use std::io::Write;
114 use std::fmt::Write as _;
115 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
116
117 // TDES case
118 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
119 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
120 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
121 let iv = 0x_FEDCBA0987654321_u64;
122 println!("IV = {:#018X}", iv);
123 let message = "In the beginning God created the heavens and the earth.";
124 println!("M =\t{}", message);
125 let mut cipher = [0_u8; 55];
126 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
127 print!("C =\t");
128 for c in cipher.clone()
129 { print!("{:02X} ", c); }
130 println!();
131 let mut txt = String::new();
132 for c in cipher.clone()
133 { write!(txt, "{:02X} ", c); }
134 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
135 println!("-------------------------------");
136}
137
138fn bigcryptor64_encrypt_str_ofb()
139{
140 println!("bigcryptor64_encrypt_str_ofb()");
141 use std::io::Write;
142 use std::fmt::Write as _;
143 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
144
145 // TDES case
146 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
147 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
148 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
149 let iv = 0x_FEDCBA0987654321_u64;
150 println!("IV = {:#018X}", iv);
151 let message = "In the beginning God created the heavens and the earth.";
152 println!("M =\t{}", message);
153 let mut cipher = [0_u8; 55];
154 tdes.encrypt_str(iv, &message, cipher.as_mut_ptr());
155 print!("C =\t");
156 for c in cipher.clone()
157 { print!("{:02X} ", c); }
158 println!();
159 let mut txt = String::new();
160 for c in cipher.clone()
161 { write!(txt, "{:02X} ", c); }
162 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
163 println!("-------------------------------");
164}
165
166fn bigcryptor64_encrypt_str_ofb_into_vec()
167{
168 println!("bigcryptor64_encrypt_str_ofb_into_vec()");
169 use std::io::Write;
170 use std::fmt::Write as _;
171 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
172
173 // TDES case
174 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
175 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
176 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
177 let iv = 0x_FEDCBA0987654321_u64;
178 println!("IV = {:#018X}", iv);
179 let message = "In the beginning God created the heavens and the earth.";
180 let mut cipher = Vec::<u8>::new();
181 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
182 print!("C =\t");
183 for c in cipher.clone()
184 { print!("{:02X} ", c); }
185 println!();
186 let mut txt = String::new();
187 for c in cipher.clone()
188 { write!(txt, "{:02X} ", c); }
189 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
190 println!("-------------------------------");
191}
192
193fn bigcryptor64_encrypt_str_ofb_into_array()
194{
195 println!("bigcryptor64_encrypt_str_ofb_into_array()");
196 use std::io::Write;
197 use std::fmt::Write as _;
198 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
199
200 // TDES case
201 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
202 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
203 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
204 let iv = 0x_FEDCBA0987654321_u64;
205 println!("IV = {:#018X}", iv);
206 let message = "In the beginning God created the heavens and the earth.";
207 let mut cipher = [0_u8; 55];
208 tdes.encrypt_str_into_array(iv, &message, &mut cipher);
209 print!("C =\t");
210 for c in cipher.clone()
211 { print!("{:02X} ", c); }
212 println!();
213 let mut txt = String::new();
214 for c in cipher.clone()
215 { write!(txt, "{:02X} ", c); }
216 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
217 println!("-------------------------------");
218}
219
220fn bigcryptor64_encrypt_string_ofb()
221{
222 println!("bigcryptor64_encrypt_string_ofb()");
223 use std::io::Write;
224 use std::fmt::Write as _;
225 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
226
227 // TDES case
228 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
229 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
230 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
231 let iv = 0x_FEDCBA0987654321_u64;
232 println!("IV = {:#018X}", iv);
233 let message = "In the beginning God created the heavens and the earth.".to_string();
234 let mut cipher = [0_u8; 55];
235 tdes.encrypt_string(iv, &message, cipher.as_mut_ptr());
236 print!("C =\t");
237 for c in cipher.clone()
238 { print!("{:02X} ", c); }
239 println!();
240 let mut txt = String::new();
241 for c in cipher.clone()
242 { write!(txt, "{:02X} ", c); }
243 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
244 println!("-------------------------------");
245}
246
247fn bigcryptor64_encrypt_string_ofb_into_vec()
248{
249 println!("bigcryptor64_encrypt_string_ofb_into_vec()");
250 use std::io::Write;
251 use std::fmt::Write as _;
252 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
253
254 // TDES case
255 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
256 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
257 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
258 let iv = 0x_FEDCBA0987654321_u64;
259 println!("IV = {:#018X}", iv);
260 let message = "In the beginning God created the heavens and the earth.".to_string();
261 let mut cipher = Vec::<u8>::new();
262 tdes.encrypt_string_into_vec(iv, &message, &mut cipher);
263 print!("C =\t");
264 for c in cipher.clone()
265 { print!("{:02X} ", c); }
266 println!();
267 let mut txt = String::new();
268 for c in cipher.clone()
269 { write!(txt, "{:02X} ", c); }
270 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
271 println!("-------------------------------");
272}
273
274fn bigcryptor64_encrypt_string_ofb_into_array()
275{
276 println!("bigcryptor64_encrypt_string_ofb_into_array()");
277 use std::io::Write;
278 use std::fmt::Write as _;
279 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
280
281 // TDES case
282 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
283 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
284 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
285 let iv = 0x_FEDCBA0987654321_u64;
286 println!("IV = {:#018X}", iv);
287 let message = "In the beginning God created the heavens and the earth.".to_string();
288 let mut cipher = [0_u8; 55];
289 tdes.encrypt_string_into_array(iv, &message, &mut cipher);
290 print!("C =\t");
291 for c in cipher.clone()
292 { print!("{:02X} ", c); }
293 println!();
294 let mut txt = String::new();
295 for c in cipher.clone()
296 { write!(txt, "{:02X} ", c); }
297 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
298 println!("-------------------------------");
299}
300
301fn bigcryptor64_encrypt_vec_ofb()
302{
303 println!("bigcryptor64_encrypt_vec_ofb()");
304 use std::io::Write;
305 use std::fmt::Write as _;
306 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
307
308 // TDES case
309 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
310 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
311 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
312 let iv = 0x_FEDCBA0987654321_u64;
313 println!("IV = {:#018X}", iv);
314 let message = "In the beginning God created the heavens and the earth.";
315 println!("M =\t{}", message);
316 let message = unsafe { message.to_string().as_mut_vec().clone() };
317 let mut cipher = [0_u8; 55];
318 tdes.encrypt_vec(iv, &message, cipher.as_mut_ptr());
319 print!("C =\t");
320 for c in cipher.clone()
321 { print!("{:02X} ", c); }
322 println!();
323 let mut txt = String::new();
324 for c in cipher.clone()
325 { write!(txt, "{:02X} ", c); }
326 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
327 println!("-------------------------------");
328}
329
330fn bigcryptor64_encrypt_vec_ofb_into_vec()
331{
332 println!("bigcryptor64_encrypt_vec_ofb_into_vec()");
333 use std::io::Write;
334 use std::fmt::Write as _;
335 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
336
337 // TDES case
338 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
339 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
340 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
341 let iv = 0x_FEDCBA0987654321_u64;
342 println!("IV = {:#018X}", iv);
343 let message = "In the beginning God created the heavens and the earth.";
344 println!("M =\t{}", message);
345 let message = unsafe { message.to_string().as_mut_vec().clone() };
346 let mut cipher = Vec::<u8>::new();
347 tdes.encrypt_vec_into_vec(iv, &message, &mut cipher);
348 print!("C =\t");
349 for c in cipher.clone()
350 { print!("{:02X} ", c); }
351 println!();
352 let mut txt = String::new();
353 for c in cipher.clone()
354 { write!(txt, "{:02X} ", c); }
355 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
356 println!("-------------------------------");
357}
358
359fn bigcryptor64_encrypt_vec_ofb_into_array()
360{
361 println!("bigcryptor64_encrypt_vec_ofb_into_array()");
362 use std::io::Write;
363 use std::fmt::Write as _;
364 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
365
366 // TDES case
367 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
368 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
369 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
370 let iv = 0x_FEDCBA0987654321_u64;
371 println!("IV = {:#018X}", iv);
372 let message = "In the beginning God created the heavens and the earth.";
373 println!("M =\t{}", message);
374 let message = unsafe { message.to_string().as_mut_vec().clone() };
375 let mut cipher = [0_u8; 55];
376 tdes.encrypt_vec_into_array(iv, &message, &mut cipher);
377 print!("C =\t");
378 for c in cipher.clone()
379 { print!("{:02X} ", c); }
380 println!();
381 let mut txt = String::new();
382 for c in cipher.clone()
383 { write!(txt, "{:02X} ", c); }
384 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
385 println!("-------------------------------");
386}
387
388fn bigcryptor64_encrypt_array_ofb()
389{
390 println!("bigcryptor64_encrypt_array_ofb()");
391 use std::io::Write;
392 use std::fmt::Write as _;
393 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
394
395 // TDES case
396 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
397 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
398 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
399 let iv = 0x_FEDCBA0987654321_u64;
400 println!("IV = {:#018X}", iv);
401 let mes = "In the beginning God created the heavens and the earth.";
402 println!("M =\t{}", mes);
403 let mut message = [0_u8; 55];
404 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
405 let mut cipher = [0_u8; 55];
406 tdes.encrypt_array(iv, &message, cipher.as_mut_ptr());
407 print!("C =\t");
408 for c in cipher.clone()
409 { print!("{:02X} ", c); }
410 println!();
411 let mut txt = String::new();
412 for c in cipher.clone()
413 { write!(txt, "{:02X} ", c); }
414 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
415 println!("-------------------------------");
416}
417
418fn bigcryptor64_encrypt_array_ofb_into_vec()
419{
420 println!("bigcryptor64_encrypt_array_ofb_into_vec()");
421 use std::io::Write;
422 use std::fmt::Write as _;
423 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
424
425 // TDES case
426 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
427 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
428 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
429 let iv = 0x_FEDCBA0987654321_u64;
430 println!("IV = {:#018X}", iv);
431 let mes = "In the beginning God created the heavens and the earth.";
432 println!("M =\t{}", mes);
433 let mut message = [0_u8; 55];
434 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
435 let mut cipher = Vec::<u8>::new();
436 tdes.encrypt_array_into_vec(iv, &message, &mut cipher);
437 print!("C =\t");
438 for c in cipher.clone()
439 { print!("{:02X} ", c); }
440 println!();
441 let mut txt = String::new();
442 for c in cipher.clone()
443 { write!(txt, "{:02X} ", c); }
444 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
445 println!("-------------------------------");
446}
447
448fn bigcryptor64_encrypt_array_ofb_into_array()
449{
450 println!("bigcryptor64_encrypt_array_ofb_into_array()");
451 use std::io::Write;
452 use std::fmt::Write as _;
453 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
454
455 // TDES case
456 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
457 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
458 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
459 let iv = 0x_FEDCBA0987654321_u64;
460 println!("IV = {:#018X}", iv);
461 let mes = "In the beginning God created the heavens and the earth.";
462 println!("M =\t{}", mes);
463 let mut message = [0_u8; 55];
464 message.copy_from_slice(unsafe { mes.to_string().as_mut_vec() });
465 let mut cipher = [0_u8; 55];
466 tdes.encrypt_array_into_array(iv, &message, &mut cipher);
467 for c in cipher.clone()
468 { print!("{:02X} ", c); }
469 println!();
470 let mut txt = String::new();
471 for c in cipher.clone()
472 { write!(txt, "{:02X} ", c); }
473 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
474 println!("-------------------------------");
475}
476
477fn bigcryptor64_decrypt_ofb()
478{
479 println!("bigcryptor64_decrypt_ofb()");
480 use std::io::Write;
481 use std::fmt::Write as _;
482 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
483
484 // TDES case
485 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
486 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
487 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
488 let iv = 0x_FEDCBA0987654321_u64;
489 println!("IV = {:#018X}", iv);
490 let message = "In the beginning God created the heavens and the earth.";
491 println!("M =\t{}", message);
492 let mut cipher = Vec::<u8>::new();
493 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
494 print!("C =\t");
495 for c in cipher.clone()
496 { print!("{:02X} ", c); }
497 println!();
498 let mut txt = String::new();
499 for c in cipher.clone()
500 { write!(txt, "{:02X} ", c); }
501 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
502
503 let mut recovered = vec![0; 55];
504 tdes.decrypt(iv, cipher.as_ptr(), cipher.len() as u64, recovered.as_mut_ptr());
505 print!("Ba =\t");
506 for b in recovered.clone()
507 { print!("{:02X} ", b); }
508 println!();
509 let mut txt = String::new();
510 for c in recovered.clone()
511 { write!(txt, "{:02X} ", c); }
512 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
513
514 let mut converted = String::new();
515 unsafe { converted.as_mut_vec() }.append(&mut recovered);
516
517 println!("Bb =\t{}", converted);
518 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
519 assert_eq!(converted, message);
520 println!("-------------------------------");
521}
522
523fn bigcryptor64_decrypt_ofb_into_vec()
524{
525 println!("bigcryptor64_decrypt_ofb_into_vec()");
526 use std::io::Write;
527 use std::fmt::Write as _;
528 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
529
530 // TDES case
531 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
532 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
533 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
534 let iv = 0x_FEDCBA0987654321_u64;
535 println!("IV = {:#018X}", iv);
536 let message = "In the beginning God created the heavens and the earth.";
537 println!("M =\t{}", message);
538 let mut cipher = Vec::<u8>::new();
539 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
540 print!("C =\t");
541 for c in cipher.clone()
542 { print!("{:02X} ", c); }
543 println!();
544 let mut txt = String::new();
545 for c in cipher.clone()
546 { write!(txt, "{:02X} ", c); }
547 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
548
549 let mut recovered = Vec::<u8>::new();
550 tdes.decrypt_into_vec(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
551 print!("Ba =\t");
552 for b in recovered.clone()
553 { print!("{:02X} ", b); }
554 println!();
555 let mut txt = String::new();
556 for c in recovered.clone()
557 { write!(txt, "{:02X} ", c); }
558 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
559
560 let mut converted = String::new();
561 unsafe { converted.as_mut_vec() }.append(&mut recovered);
562
563 println!("Bb =\t{}", converted);
564 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
565 assert_eq!(converted, message);
566 println!("-------------------------------");
567}
568
569fn bigcryptor64_decrypt_ofb_into_array()
570{
571 println!("bigcryptor64_decrypt_ofb_into_array()");
572 use std::io::Write;
573 use std::fmt::Write as _;
574 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
575
576 // TDES case
577 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
578 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
579 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
580 let iv = 0x_FEDCBA0987654321_u64;
581 println!("IV = {:#018X}", iv);
582 let message = "In the beginning God created the heavens and the earth.";
583 println!("M =\t{}", message);
584 let mut cipher = Vec::<u8>::new();
585 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
586 print!("C =\t");
587 for c in cipher.clone()
588 { print!("{:02X} ", c); }
589 println!();
590 let mut txt = String::new();
591 for c in cipher.clone()
592 { write!(txt, "{:02X} ", c); }
593 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
594
595 let mut recovered = [0u8; 56];
596 let len = tdes.decrypt_into_array(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
597 print!("Ba =\t");
598 for b in recovered.clone()
599 { print!("{:02X} ", b); }
600 println!();
601 let mut txt = String::new();
602 for c in recovered.clone()
603 { write!(txt, "{:02X} ", c); }
604 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
605
606 let mut converted = String::new();
607 unsafe { converted.as_mut_vec() }.write(&recovered);
608 unsafe { converted.as_mut_vec() }.truncate(len as usize);
609 println!("Bb =\t{}", converted);
610 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
611 assert_eq!(converted, message);
612 println!("-------------------------------");
613}
614
615fn bigcryptor64_decrypt_ofb_into_string()
616{
617 println!("bigcryptor64_decrypt_ofb_into_string()");
618 use std::io::Write;
619 use std::fmt::Write as _;
620 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
621
622 // TDES case
623 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
624 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
625 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
626 let iv = 0x_FEDCBA0987654321_u64;
627 println!("IV = {:#018X}", iv);
628 let message = "In the beginning God created the heavens and the earth.";
629 println!("M =\t{}", message);
630 let mut cipher = Vec::<u8>::new();
631 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
632 print!("C =\t");
633 for c in cipher.clone()
634 { print!("{:02X} ", c); }
635 println!();
636 let mut txt = String::new();
637 for c in cipher.clone()
638 { write!(txt, "{:02X} ", c); }
639 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
640
641 let mut recovered = String::new();
642 tdes.decrypt_into_string(iv, cipher.as_ptr(), cipher.len() as u64, &mut recovered);
643 println!("B =\t{}", recovered);
644 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
645 assert_eq!(recovered, message);
646 println!("-------------------------------");
647}
648
649fn bigcryptor64_decrypt_vec_ofb()
650{
651 println!("bigcryptor64_decrypt_vec_ofb()");
652 use std::io::Write;
653 use std::fmt::Write as _;
654 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
655
656 // TDES case
657 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
658 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
659 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
660 let iv = 0x_FEDCBA0987654321_u64;
661 println!("IV = {:#018X}", iv);
662 let message = "In the beginning God created the heavens and the earth.";
663 println!("M =\t{}", message);
664 let mut cipher = Vec::<u8>::new();
665 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
666 print!("C =\t");
667 for c in cipher.clone()
668 { print!("{:02X} ", c); }
669 println!();
670 let mut txt = String::new();
671 for c in cipher.clone()
672 { write!(txt, "{:02X} ", c); }
673 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
674
675 let mut recovered = vec![0; 55];
676 tdes.decrypt_vec(iv, &cipher, recovered.as_mut_ptr());
677 print!("Ba =\t");
678 for b in recovered.clone()
679 { print!("{:02X} ", b); }
680 println!();
681 let mut txt = String::new();
682 for c in recovered.clone()
683 { write!(txt, "{:02X} ", c); }
684 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
685
686 let mut converted = String::new();
687 unsafe { converted.as_mut_vec() }.append(&mut recovered);
688
689 println!("Bb =\t{}", converted);
690 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
691 assert_eq!(converted, message);
692 println!("-------------------------------");
693}
694
695fn bigcryptor64_decrypt_vec_ofb_into_vec()
696{
697 println!("bigcryptor64_decrypt_vec_ofb_into_vec()");
698 use std::io::Write;
699 use std::fmt::Write as _;
700 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
701
702 // TDES case
703 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
704 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
705 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
706 let iv = 0x_FEDCBA0987654321_u64;
707 println!("IV = {:#018X}", iv);
708 let message = "In the beginning God created the heavens and the earth.";
709 println!("M =\t{}", message);
710 let mut cipher = Vec::<u8>::new();
711 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
712 print!("C =\t");
713 for c in cipher.clone()
714 { print!("{:02X} ", c); }
715 println!();
716 let mut txt = String::new();
717 for c in cipher.clone()
718 { write!(txt, "{:02X} ", c); }
719 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
720
721 let mut recovered = Vec::<u8>::new();
722 tdes.decrypt_vec_into_vec(iv, &cipher, &mut recovered);
723 print!("Ba =\t");
724 for b in recovered.clone()
725 { print!("{:02X} ", b); }
726 println!();
727 let mut txt = String::new();
728 for c in recovered.clone()
729 { write!(txt, "{:02X} ", c); }
730 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
731
732 let mut converted = String::new();
733 unsafe { converted.as_mut_vec() }.append(&mut recovered);
734
735 println!("Bb =\t{}", converted);
736 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
737 assert_eq!(converted, message);
738 println!("-------------------------------");
739}
740
741fn bigcryptor64_decrypt_vec_ofb_into_array()
742{
743 println!("bigcryptor64_decrypt_vec_ofb_into_array()");
744 use std::io::Write;
745 use std::fmt::Write as _;
746 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
747
748 // TDES case
749 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
750 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
751 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
752 let iv = 0x_FEDCBA0987654321_u64;
753 println!("IV = {:#018X}", iv);
754 let message = "In the beginning God created the heavens and the earth.";
755 println!("M =\t{}", message);
756 let mut cipher = Vec::<u8>::new();
757 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
758 print!("C =\t");
759 for c in cipher.clone()
760 { print!("{:02X} ", c); }
761 println!();
762 let mut txt = String::new();
763 for c in cipher.clone()
764 { write!(txt, "{:02X} ", c); }
765 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
766
767 let mut recovered = [0u8; 56];
768 let len = tdes.decrypt_vec_into_array(iv, &cipher, &mut recovered);
769 print!("Ba =\t");
770 for b in recovered.clone()
771 { print!("{:02X} ", b); }
772 println!();
773 let mut txt = String::new();
774 for c in recovered.clone()
775 { write!(txt, "{:02X} ", c); }
776 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
777
778 let mut converted = String::new();
779 unsafe { converted.as_mut_vec() }.write(&recovered);
780 unsafe { converted.as_mut_vec() }.truncate(len as usize);
781 println!("Bb =\t{}", converted);
782 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
783 assert_eq!(converted, message);
784 println!("-------------------------------");
785}
786
787fn bigcryptor64_decrypt_vec_ofb_into_string()
788{
789 println!("bigcryptor64_decrypt_vec_ofb_into_string()");
790 use std::io::Write;
791 use std::fmt::Write as _;
792 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
793
794 // TDES case
795 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
796 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
797 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
798 let iv = 0x_FEDCBA0987654321_u64;
799 println!("IV = {:#018X}", iv);
800 let message = "In the beginning God created the heavens and the earth.";
801 println!("M =\t{}", message);
802 let mut cipher = Vec::<u8>::new();
803 tdes.encrypt_str_into_vec(iv, &message, &mut cipher);
804 print!("C =\t");
805 for c in cipher.clone()
806 { print!("{:02X} ", c); }
807 println!();
808 let mut txt = String::new();
809 for c in cipher.clone()
810 { write!(txt, "{:02X} ", c); }
811 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
812
813 let mut recovered = String::new();
814 tdes.decrypt_vec_into_string(iv, &cipher, &mut recovered);
815 println!("B =\t{}", recovered);
816 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
817 assert_eq!(recovered, message);
818 println!("-------------------------------");
819}
820
821fn bigcryptor64_decrypt_array_ofb()
822{
823 println!("bigcryptor64_decrypt_array_ofb()");
824 use std::io::Write;
825 use std::fmt::Write as _;
826 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
827
828 // TDES case
829 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
830 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
831 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
832 let iv = 0x_FEDCBA0987654321_u64;
833 println!("IV = {:#018X}", iv);
834 let message = "In the beginning God created the heavens and the earth.";
835 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
836 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
837 print!("C =\t");
838 for c in cipher.clone()
839 { print!("{:02X} ", c); }
840 println!();
841 let mut txt = String::new();
842 for c in cipher.clone()
843 { write!(txt, "{:02X} ", c); }
844 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
845
846 let mut recovered = vec![0; 55];
847 let len = tdes.decrypt_array(iv, &cipher, recovered.as_mut_ptr());
848 recovered.truncate(len as usize);
849 print!("Ba =\t");
850 for b in recovered.clone()
851 { print!("{:02X} ", b); }
852 println!();
853 let mut txt = String::new();
854 for c in recovered.clone()
855 { write!(txt, "{:02X} ", c); }
856 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
857
858 let mut converted = String::new();
859 unsafe { converted.as_mut_vec() }.append(&mut recovered);
860
861 println!("Bb =\t{}", converted);
862 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
863 assert_eq!(converted, message);
864 println!("-------------------------------");
865}
866
867fn bigcryptor64_decrypt_array_ofb_into_vec()
868{
869 println!("bigcryptor64_decrypt_array_ofb_into_vec()");
870 use std::io::Write;
871 use std::fmt::Write as _;
872 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
873
874 // TDES case
875 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
876 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
877 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
878 let iv = 0x_FEDCBA0987654321_u64;
879 println!("IV = {:#018X}", iv);
880 let message = "In the beginning God created the heavens and the earth.";
881 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
882 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
883 print!("C =\t");
884 for c in cipher.clone()
885 { print!("{:02X} ", c); }
886 println!();
887 let mut txt = String::new();
888 for c in cipher.clone()
889 { write!(txt, "{:02X} ", c); }
890 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
891
892 let mut recovered = Vec::<u8>::new();
893 tdes.decrypt_array_into_vec(iv, &cipher, &mut recovered);
894 print!("Ba =\t");
895 for b in recovered.clone()
896 { print!("{:02X} ", b); }
897 println!();
898 let mut txt = String::new();
899 for c in recovered.clone()
900 { write!(txt, "{:02X} ", c); }
901 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E ");
902
903 let mut converted = String::new();
904 unsafe { converted.as_mut_vec() }.append(&mut recovered);
905
906 println!("Bb =\t{}", converted);
907 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
908 assert_eq!(converted, message);
909 println!("-------------------------------");
910}
911
912fn bigcryptor64_decrypt_array_ofb_into_array()
913{
914 println!("bigcryptor64_decrypt_array_ofb_into_array()");
915 use std::io::Write;
916 use std::fmt::Write as _;
917 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
918
919 // TDES case
920 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
921 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
922 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
923 let iv = 0x_FEDCBA0987654321_u64;
924 println!("IV = {:#018X}", iv);
925 let message = "In the beginning God created the heavens and the earth.";
926 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
927 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
928 print!("C =\t");
929 for c in cipher.clone()
930 { print!("{:02X} ", c); }
931 println!();
932 let mut txt = String::new();
933 for c in cipher.clone()
934 { write!(txt, "{:02X} ", c); }
935 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
936
937 let mut recovered = [0u8; 56];
938 let len = tdes.decrypt_array_into_array(iv, &cipher, &mut recovered);
939 print!("Ba =\t");
940 for b in recovered.clone()
941 { print!("{:02X} ", b); }
942 println!();
943 let mut txt = String::new();
944 for c in recovered.clone()
945 { write!(txt, "{:02X} ", c); }
946 assert_eq!(txt, "49 6E 20 74 68 65 20 62 65 67 69 6E 6E 69 6E 67 20 47 6F 64 20 63 72 65 61 74 65 64 20 74 68 65 20 68 65 61 76 65 6E 73 20 61 6E 64 20 74 68 65 20 65 61 72 74 68 2E 00 ");
947
948 let mut converted = String::new();
949 unsafe { converted.as_mut_vec() }.write(&recovered);
950 unsafe { converted.as_mut_vec() }.truncate(len as usize);
951 println!("Bb =\t{}", converted);
952 assert_eq!(converted, "In the beginning God created the heavens and the earth.");
953 assert_eq!(converted, message);
954 println!("-------------------------------");
955}
956
957fn bigcryptor64_decrypt_array_ofb_into_string()
958{
959 println!("bigcryptor64_decrypt_array_ofb_into_string()");
960 use std::io::Write;
961 use std::fmt::Write as _;
962 use cryptocol::symmetric::{ BigCryptor64, DES, OFB };
963
964 // TDES case
965 let mut tdes = DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
966 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
967 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
968 let iv = 0x_FEDCBA0987654321_u64;
969 println!("IV = {:#018X}", iv);
970 let message = "In the beginning God created the heavens and the earth.";
971 println!("M =\t{}", message); let mut cipher = [0_u8; 55];
972 tdes.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
973 print!("C =\t");
974 for c in cipher.clone()
975 { print!("{:02X} ", c); }
976 println!();
977 let mut txt = String::new();
978 for c in cipher.clone()
979 { write!(txt, "{:02X} ", c); }
980 assert_eq!(txt, "A8 E8 A8 5C 2E 0C B6 68 B2 9A 04 35 11 DD F7 C6 8E 4E 9E EB D0 9B 97 1C F0 19 3F 0D 24 57 78 0F 84 2B F8 8C 22 26 B8 D3 AF D4 9C 69 86 1E 6D 2B 31 B4 10 49 29 0A 7A ");
981
982 let mut recovered = String::new();
983 tdes.decrypt_array_into_string(iv, &cipher, &mut recovered);
984 println!("B =\t{}", recovered);
985 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
986 assert_eq!(recovered, message);
987 println!("-------------------------------");
988}Sourcepub fn get_key(&mut self) -> [u8; 8]
pub fn get_key(&mut self) -> [u8; 8]
Gets the key.
§Output
This method returns the key in the form of array of u8.
§Example
use cryptocol::symmetric::DES;
let mut des = DES::new();
des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
let key = des.get_key();
print!("K = ");
for k in key
{ print!("{:X02#} ", k); }
assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);Examples found in repository?
942fn des_get_key()
943{
944 println!("des_get_key");
945 use cryptocol::symmetric::DES;
946
947 let mut des = DES::new();
948 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
949 let key = des.get_key();
950 print!("K = ");
951 for k in key
952 { print!("{:#02X} ", k); }
953 assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
954}Sourcepub fn get_key_u64(&self) -> u64
pub fn get_key_u64(&self) -> u64
Sourcepub fn set_key(&mut self, key: [u8; 8])
pub fn set_key(&mut self, key: [u8; 8])
Sets the key.
§Arguments
- The argument
keyis the array ofu8that has 8 elements. - Remember that inverted parity bits do not affect the 56-bit real key. So, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00], [0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01], etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
This method sets the key to be the given argument key.
§Example 1 for normal case
use cryptocol::symmetric::DES;
let mut des = DES::new();
des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
let plaintext = 0x1234567890ABCDEF_u64;
let ciphertext = des.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
let cipher_cipher_text = des.encrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
assert_ne!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
50fn des_quick_start_instantiation_without_key()
51{
52 println!("des_quick_start_instantiation_without_key()");
53 use cryptocol::symmetric::DES;
54
55 let mut a_des = DES::new();
56 let key = 0x_1234567890ABCDEF_u64;
57 a_des.set_key_u64(key);
58
59 let mut a_des = DES::new();
60 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
61 a_des.set_key(key);
62 println!("-------------------------------");
63}
64
65fn des_quick_start_encryption_decryption_16_rounds()
66{
67 println!("des_quick_start_encryption_decryption_16_rounds()");
68 use std::io::Write;
69 use std::fmt::Write as _;
70 use cryptocol::symmetric::{ CBC_PKCS7, DES };
71
72 let mut a_des = DES::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
73 let message = "In the beginning God created the heavens and the earth.";
74 println!("M =\t{}", message);
75 let iv = 0x_FEDCBA0987654321_u64;
76 println!("IV =\t{}", iv);
77 let mut cipher = Vec::<u8>::new();
78 a_des.encrypt_str_into_vec(iv, message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "4B B5 ED DC A0 58 7E 6D 6C 3B A2 00 38 C3 D4 29 42 B1 CF 0D E9 FA EA 11 11 6B C8 30 73 39 DD B7 3F 96 9B A3 76 05 34 7E 64 2F D4 CC B2 68 33 64 C5 9E EF 01 A9 4A FD 5B ");
87
88 let mut recovered = String::new();
89 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
90 println!("B (16 rounds) =\t{}", recovered);
91 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
92 assert_eq!(recovered, message);
93 println!("-------------------------------");
94}
95
96fn des_quick_start_encryption_decryption_256_rounds()
97{
98 println!("des_quick_start_encryption_decryption_256_rounds()");
99 use std::io::Write;
100 use std::fmt::Write as _;
101 use cryptocol::symmetric::{ CBC_PKCS7, DES_Expanded };
102
103 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
104 let message = "In the beginning God created the heavens and the earth.";
105 println!("M =\t{}", message);
106 let iv = 0x_FEDCBA0987654321_u64;
107 println!("IV =\t{}", iv);
108 let mut cipher = Vec::<u8>::new();
109 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
110 print!("C =\t");
111 for c in cipher.clone()
112 { print!("{:02X} ", c); }
113 println!();
114 let mut txt = String::new();
115 for c in cipher.clone()
116 { write!(txt, "{:02X} ", c); }
117 assert_eq!(txt, "0B EA 6B BC 68 F9 B0 3E 7D AF DE 71 9C 08 AA 16 42 40 1C C8 DC 40 51 C6 8D D4 E7 D2 0B A4 F2 09 02 02 C2 6E 99 BC 9E 2A F4 11 7E 48 A7 ED 76 70 C6 9D C6 BD A6 9B 58 8B ");
118
119 let mut recovered = String::new();
120 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
121 println!("B =\t{}", recovered);
122 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
123 assert_eq!(recovered, message);
124 println!("-------------------------------");
125}
126
127fn des_basic_operation_main()
128{
129 des_new();
130 des_new_with_key();
131 des_new_with_key_u64();
132 des_encryptor_with_key();
133 des_encryptor_with_key_u64();
134 des_decryptor_with_key();
135 des_decryptor_with_key_u64();
136 des_get_key();
137 des_get_key_u64();
138 des_set_key();
139 des_set_key_u64();
140 des_turn_inverse();
141 des_turn_encryptor();
142 des_turn_decryptor();
143}
144
145fn des_new()
146{
147 println!("des_new()");
148 use cryptocol::symmetric::DES;
149
150 let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
151 let plaintext = 0x1234567890ABCDEF_u64;
152 let ciphertext = des.encrypt_u64(plaintext);
153
154 println!("Plaintext:\t\t{:#018X}", plaintext);
155 println!("Ciphertext:\t\t{:#018X}", ciphertext);
156 assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
157
158 let cipher_cipher_text = des.encrypt_u64(ciphertext);
159 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
160 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
161 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
162
163 #[cfg(test)]
164 des_compile_fail_new();
165 println!("-------------------------------");
166}
167
168#[test]
169fn des_compile_fail_new()
170{
171 use cryptocol::symmetric::DES;
172 let des = DES::new();
173 // It cannot be compiled!
174 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
175}
176
177fn des_new_with_key()
178{
179 println!("des_new_with_key()");
180 use cryptocol::symmetric::DES;
181
182 // Normal case
183 let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
184 let plaintext = 0x1234567890ABCDEF_u64;
185 let ciphertext = des.encrypt_u64(plaintext);
186
187 println!("Plaintext:\t\t{:#018X}", plaintext);
188 println!("Ciphertext:\t\t{:#018X}", ciphertext);
189 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
190
191 let cipher_cipher_text = des.encrypt_u64(ciphertext);
192 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
193 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
194 assert_ne!(cipher_cipher_text, plaintext);
195 println!();
196
197 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
198 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
199 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
200 let mut des1 = DES::new_with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
201 let mut des2 = DES::new_with_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
202
203 let plaintext = 0x1234567890ABCDEF_u64;
204 let ciphertext1 = des1.encrypt_u64(plaintext);
205 let ciphertext2 = des2.encrypt_u64(plaintext);
206
207 println!("Plaintext:\t\t{:#018X}", plaintext);
208 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
209 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
210 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
211 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
212 assert_eq!(ciphertext1, ciphertext2);
213
214 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
215 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
216 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
217 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
218 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
219 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
220 assert_eq!(cipher_cipher_text1, plaintext);
221 assert_eq!(cipher_cipher_text2, plaintext);
222 println!();
223 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
224 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
225
226
227 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
228 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
229 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
230 let mut des1 = DES::new_with_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
231 let mut des2 = DES::new_with_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
232 let plaintext = 0x1234567890ABCDEF_u64;
233 let ciphertext1 = des1.encrypt_u64(plaintext);
234 let ciphertext2 = des2.encrypt_u64(plaintext);
235
236 println!("Plaintext:\t\t{:#018X}", plaintext);
237 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
238 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
239 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
240 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
241 assert_eq!(ciphertext1, ciphertext2);
242
243 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
244 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
245 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
246 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
247 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
248 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
249 assert_eq!(cipher_cipher_text1, plaintext);
250 assert_eq!(cipher_cipher_text2, plaintext);
251 println!();
252 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
253 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
254
255 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
256 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1] is the same key as the key
257 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
258 let mut des1 = DES::new_with_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
259 let mut des2 = DES::new_with_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
260 let plaintext = 0x1234567890ABCDEF_u64;
261 let ciphertext1 = des1.encrypt_u64(plaintext);
262 let ciphertext2 = des2.encrypt_u64(plaintext);
263
264 println!("Plaintext:\t\t{:#018X}", plaintext);
265 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
266 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
267 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
268 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
269 assert_eq!(ciphertext1, ciphertext2);
270
271 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
272 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
273 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
274 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
275 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
276 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
277 assert_eq!(cipher_cipher_text1, plaintext);
278 assert_eq!(cipher_cipher_text2, plaintext);
279 println!();
280 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
281 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
282
283 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
284 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
285 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
286 let mut des1 = DES::new_with_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
287 let mut des2 = DES::new_with_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
288 let plaintext = 0x1234567890ABCDEF_u64;
289 let ciphertext1 = des1.encrypt_u64(plaintext);
290 let ciphertext2 = des2.encrypt_u64(plaintext);
291
292 println!("Plaintext:\t\t{:#018X}", plaintext);
293 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
294 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
295 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
296 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
297 assert_eq!(ciphertext1, ciphertext2);
298
299 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
300 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
301 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
302 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
303 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
304 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
305 assert_eq!(cipher_cipher_text1, plaintext);
306 assert_eq!(cipher_cipher_text2, plaintext);
307 println!();
308 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
309 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
310
311 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
312 let mut des1 = DES::new_with_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
313 let mut des2 = DES::new_with_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
314
315 let plaintext = 0x1234567890ABCDEF_u64;
316 let ciphertext = des1.encrypt_u64(plaintext);
317 println!("Plaintext:\t\t{:#018X}", plaintext);
318 println!("Ciphertext:\t\t{:#018X}", ciphertext);
319 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
320
321 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
322 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
323 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
324 assert_eq!(cipher_cipher_text, plaintext);
325
326 let ciphertext = des2.encrypt_u64(plaintext);
327 println!("Plaintext:\t\t{:#018X}", plaintext);
328 println!("Ciphertext:\t\t{:#018X}", ciphertext);
329 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
330
331 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
332 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
333 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
334 assert_eq!(cipher_cipher_text, plaintext);
335 println!();
336 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
337
338 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
339 let mut des1 = DES::new_with_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
340 let mut des2 = DES::new_with_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
341
342 let plaintext = 0x1234567890ABCDEF_u64;
343 let ciphertext = des1.encrypt_u64(plaintext);
344 println!("Plaintext:\t\t{:#018X}", plaintext);
345 println!("Ciphertext:\t\t{:#018X}", ciphertext);
346 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
347
348 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
349 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
350 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
351 assert_eq!(cipher_cipher_text, plaintext);
352
353 let ciphertext = des2.encrypt_u64(plaintext);
354 println!("Plaintext:\t\t{:#018X}", plaintext);
355 println!("Ciphertext:\t\t{:#018X}", ciphertext);
356 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
357
358 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
359 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
360 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
361 assert_eq!(cipher_cipher_text, plaintext);
362 println!();
363 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
364
365 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
366 let mut des1 = DES::new_with_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
367 let mut des2 = DES::new_with_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
368
369 let plaintext = 0x1234567890ABCDEF_u64;
370 let ciphertext = des1.encrypt_u64(plaintext);
371 println!("Plaintext:\t\t{:#018X}", plaintext);
372 println!("Ciphertext:\t\t{:#018X}", ciphertext);
373 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
374
375 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
376 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
377 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
378 assert_eq!(cipher_cipher_text, plaintext);
379
380 let ciphertext = des2.encrypt_u64(plaintext);
381 println!("Plaintext:\t\t{:#018X}", plaintext);
382 println!("Ciphertext:\t\t{:#018X}", ciphertext);
383 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
384
385 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
386 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
387 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
388 assert_eq!(cipher_cipher_text, plaintext);
389 println!();
390 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
391
392 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
393 let mut des1 = DES::new_with_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
394 let mut des2 = DES::new_with_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
395
396 let plaintext = 0x1234567890ABCDEF_u64;
397 let ciphertext = des1.encrypt_u64(plaintext);
398 println!("Plaintext:\t\t{:#018X}", plaintext);
399 println!("Ciphertext:\t\t{:#018X}", ciphertext);
400 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
401
402 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
403 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
404 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
405 assert_eq!(cipher_cipher_text, plaintext);
406
407 let ciphertext = des2.encrypt_u64(plaintext);
408 println!("Plaintext:\t\t{:#018X}", plaintext);
409 println!("Ciphertext:\t\t{:#018X}", ciphertext);
410 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
411
412 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
413 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
414 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
415 assert_eq!(cipher_cipher_text, plaintext);
416 println!();
417 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
418
419 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
420 let mut des1 = DES::new_with_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
421 let mut des2 = DES::new_with_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
422
423 let plaintext = 0x1234567890ABCDEF_u64;
424 let ciphertext = des1.encrypt_u64(plaintext);
425 println!("Plaintext:\t\t{:#018X}", plaintext);
426 println!("Ciphertext:\t\t{:#018X}", ciphertext);
427 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
428
429 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
430 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
431 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
432 assert_eq!(cipher_cipher_text, plaintext);
433
434 let ciphertext = des2.encrypt_u64(plaintext);
435 println!("Plaintext:\t\t{:#018X}", plaintext);
436 println!("Ciphertext:\t\t{:#018X}", ciphertext);
437 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
438
439 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
440 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
441 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
442 assert_eq!(cipher_cipher_text, plaintext);
443 println!();
444 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
445
446 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
447 let mut des1 = DES::new_with_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
448 let mut des2 = DES::new_with_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
449
450 let plaintext = 0x1234567890ABCDEF_u64;
451 let ciphertext = des1.encrypt_u64(plaintext);
452 println!("Plaintext:\t\t{:#018X}", plaintext);
453 println!("Ciphertext:\t\t{:#018X}", ciphertext);
454 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
455
456 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
457 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
458 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
459 assert_eq!(cipher_cipher_text, plaintext);
460
461 let ciphertext = des2.encrypt_u64(plaintext);
462 println!("Plaintext:\t\t{:#018X}", plaintext);
463 println!("Ciphertext:\t\t{:#018X}", ciphertext);
464 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
465
466 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
467 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
468 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
469 assert_eq!(cipher_cipher_text, plaintext);
470 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
471
472 #[cfg(test)]
473 des_compile_fail_new_with_key();
474 println!("-------------------------------");
475}
476
477#[test]
478fn des_compile_fail_new_with_key()
479{
480 use cryptocol::symmetric::DES;
481 let des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
482 // It cannot be compiled!
483 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
484}
485
486fn des_new_with_key_u64()
487{
488 println!("des_new_with_key_u64");
489 use cryptocol::symmetric::DES;
490
491 // Normal case
492 let mut des = DES::new_with_key_u64(0xEFCDAB9078563412);
493 let plaintext = 0x1234567890ABCDEF_u64;
494 let ciphertext = des.encrypt_u64(plaintext);
495
496 println!("Plaintext:\t\t{:#018X}", plaintext);
497 println!("Ciphertext:\t\t{:#018X}", ciphertext);
498 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
499
500 let cipher_cipher_text = des.encrypt_u64(ciphertext);
501 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
502 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
503 assert_ne!(cipher_cipher_text, plaintext);
504 println!();
505
506 // Weak key case 1 for 0x0000000000000000
507 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
508 let mut des1 = DES::new_with_key_u64(0x0000000000000000);
509 let mut des2 = DES::new_with_key_u64(0x0101010101010101);
510
511 let plaintext = 0x1234567890ABCDEF_u64;
512 let ciphertext1 = des1.encrypt_u64(plaintext);
513 let ciphertext2 = des2.encrypt_u64(plaintext);
514
515 println!("Plaintext:\t\t{:#018X}", plaintext);
516 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
517 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
518 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
519 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
520 assert_eq!(ciphertext1, ciphertext2);
521
522 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
523 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
524 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
525 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
526 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
527 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
528 assert_eq!(cipher_cipher_text1, plaintext);
529 assert_eq!(cipher_cipher_text2, plaintext);
530 println!();
531 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
532
533 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
534 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
535 let mut des1 = DES::new_with_key_u64(0xFFFFFFFFFFFFFFFF);
536 let mut des2 = DES::new_with_key_u64(0xFEFEFEFEFEFEFEFE);
537 let plaintext = 0x1234567890ABCDEF_u64;
538 let ciphertext1 = des1.encrypt_u64(plaintext);
539 let ciphertext2 = des2.encrypt_u64(plaintext);
540
541 println!("Plaintext:\t\t{:#018X}", plaintext);
542 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
543 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
544 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
545 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
546 assert_eq!(ciphertext1, ciphertext2);
547
548 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
549 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
550 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
551 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
552 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
553 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
554 assert_eq!(cipher_cipher_text1, plaintext);
555 assert_eq!(cipher_cipher_text2, plaintext);
556 println!();
557 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
558
559 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
560 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
561 let mut des1 = DES::new_with_key_u64(0xF1F1F1F1E0E0E0E0);
562 let mut des2 = DES::new_with_key_u64(0xF0F0F0F0E1E1E1E1);
563 let plaintext = 0x1234567890ABCDEF_u64;
564 let ciphertext1 = des1.encrypt_u64(plaintext);
565 let ciphertext2 = des2.encrypt_u64(plaintext);
566
567 println!("Plaintext:\t\t{:#018X}", plaintext);
568 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
569 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
570 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
571 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
572 assert_eq!(ciphertext1, ciphertext2);
573
574 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
575 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
576 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
577 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
578 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
579 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
580 assert_eq!(cipher_cipher_text1, plaintext);
581 assert_eq!(cipher_cipher_text2, plaintext);
582 println!();
583 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
584
585 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
586 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
587 let mut des1 = DES::new_with_key_u64(0x0E0E0E0E1F1F1F1F);
588 let mut des2 = DES::new_with_key_u64(0x0F0F0F0F1E1E1E1E);
589 let plaintext = 0x1234567890ABCDEF_u64;
590 let ciphertext1 = des1.encrypt_u64(plaintext);
591 let ciphertext2 = des2.encrypt_u64(plaintext);
592
593 println!("Plaintext:\t\t{:#018X}", plaintext);
594 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
595 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
596 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
597 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
598 assert_eq!(ciphertext1, ciphertext2);
599
600 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
601 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
602 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
603 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
604 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
605 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
606 assert_eq!(cipher_cipher_text1, plaintext);
607 assert_eq!(cipher_cipher_text2, plaintext);
608 println!();
609 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
610
611 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
612 let mut des1 = DES::new_with_key_u64(0x0E010E011F011F01);
613 let mut des2 = DES::new_with_key_u64(0x010E010E011F011F);
614
615 let plaintext = 0x1234567890ABCDEF_u64;
616 let ciphertext = des1.encrypt_u64(plaintext);
617 println!("Plaintext:\t\t{:#018X}", plaintext);
618 println!("Ciphertext:\t\t{:#018X}", ciphertext);
619 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
620
621 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
622 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
623 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
624 assert_eq!(cipher_cipher_text, plaintext);
625
626 let ciphertext = des2.encrypt_u64(plaintext);
627 println!("Plaintext:\t\t{:#018X}", plaintext);
628 println!("Ciphertext:\t\t{:#018X}", ciphertext);
629 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
630
631 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
632 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
633 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
634 assert_eq!(cipher_cipher_text, plaintext);
635 println!();
636 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
637
638 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
639 let mut des1 = DES::new_with_key_u64(0xF101F101E001E001);
640 let mut des2 = DES::new_with_key_u64(0x01F101F101E001E0);
641
642 let plaintext = 0x1234567890ABCDEF_u64;
643 let ciphertext = des1.encrypt_u64(plaintext);
644 println!("Plaintext:\t\t{:#018X}", plaintext);
645 println!("Ciphertext:\t\t{:#018X}", ciphertext);
646 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
647
648 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
649 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
650 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
651 assert_eq!(cipher_cipher_text, plaintext);
652
653 let ciphertext = des2.encrypt_u64(plaintext);
654 println!("Plaintext:\t\t{:#018X}", plaintext);
655 println!("Ciphertext:\t\t{:#018X}", ciphertext);
656 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
657
658 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
659 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
660 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
661 assert_eq!(cipher_cipher_text, plaintext);
662 println!();
663 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
664
665 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
666 let mut des1 = DES::new_with_key_u64(0xFE01FE01FE01FE01);
667 let mut des2 = DES::new_with_key_u64(0x01FE01FE01FE01FE);
668
669 let plaintext = 0x1234567890ABCDEF_u64;
670 let ciphertext = des1.encrypt_u64(plaintext);
671 println!("Plaintext:\t\t{:#018X}", plaintext);
672 println!("Ciphertext:\t\t{:#018X}", ciphertext);
673 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
674
675 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
676 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
677 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
678 assert_eq!(cipher_cipher_text, plaintext);
679
680 let ciphertext = des2.encrypt_u64(plaintext);
681 println!("Plaintext:\t\t{:#018X}", plaintext);
682 println!("Ciphertext:\t\t{:#018X}", ciphertext);
683 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
684
685 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
686 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
687 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
688 assert_eq!(cipher_cipher_text, plaintext);
689 println!();
690 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
691
692 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
693 let mut des1 = DES::new_with_key_u64(0xF10EF10EE01FE01F);
694 let mut des2 = DES::new_with_key_u64(0x0EF10EF11FE01FE0);
695
696 let plaintext = 0x1234567890ABCDEF_u64;
697 let ciphertext = des1.encrypt_u64(plaintext);
698 println!("Plaintext:\t\t{:#018X}", plaintext);
699 println!("Ciphertext:\t\t{:#018X}", ciphertext);
700 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
701
702 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
703 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
704 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
705 assert_eq!(cipher_cipher_text, plaintext);
706
707 let ciphertext = des2.encrypt_u64(plaintext);
708 println!("Plaintext:\t\t{:#018X}", plaintext);
709 println!("Ciphertext:\t\t{:#018X}", ciphertext);
710 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
711
712 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
713 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
714 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
715 assert_eq!(cipher_cipher_text, plaintext);
716 println!();
717 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
718
719 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
720 let mut des1 = DES::new_with_key_u64(0xFE0EFE0EFE1FFE1F);
721 let mut des2 = DES::new_with_key_u64(0x0EFE0EFE1FFE1FFE);
722
723 let plaintext = 0x1234567890ABCDEF_u64;
724 let ciphertext = des1.encrypt_u64(plaintext);
725 println!("Plaintext:\t\t{:#018X}", plaintext);
726 println!("Ciphertext:\t\t{:#018X}", ciphertext);
727 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
728
729 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
730 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
731 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
732 assert_eq!(cipher_cipher_text, plaintext);
733
734 let ciphertext = des2.encrypt_u64(plaintext);
735 println!("Plaintext:\t\t{:#018X}", plaintext);
736 println!("Ciphertext:\t\t{:#018X}", ciphertext);
737 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
738
739 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
740 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
741 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
742 assert_eq!(cipher_cipher_text, plaintext);
743 println!();
744 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
745
746 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
747 let mut des1 = DES::new_with_key_u64(0xFEF1FEF1FEE0FEE0);
748 let mut des2 = DES::new_with_key_u64(0xF1FEF1FEE0FEE0FE);
749
750 let plaintext = 0x1234567890ABCDEF_u64;
751 let ciphertext = des1.encrypt_u64(plaintext);
752 println!("Plaintext:\t\t{:#018X}", plaintext);
753 println!("Ciphertext:\t\t{:#018X}", ciphertext);
754 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
755
756 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
757 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
758 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
759 assert_eq!(cipher_cipher_text, plaintext);
760
761 let ciphertext = des2.encrypt_u64(plaintext);
762 println!("Plaintext:\t\t{:#018X}", plaintext);
763 println!("Ciphertext:\t\t{:#018X}", ciphertext);
764 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
765
766 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
767 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
768 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
769 assert_eq!(cipher_cipher_text, plaintext);
770 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
771 println!("-------------------------------");
772}
773
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}
899
900fn des_decryptor_with_key_u64()
901{
902 println!("des_decryptor_with_key_u64");
903 use cryptocol::symmetric::{ BigCryptor64, DES };
904
905 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
906 [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
907 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
908 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ] );
909 let plaintext = 0x_1234567890ABCDEF_u64;
910 let ciphertext = tdes.encrypt_u64(plaintext);
911
912 println!("Plaintext:\t\t{:#018X}", plaintext);
913 println!("Ciphertext:\t\t{:#018X}", ciphertext);
914 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
915
916 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
917 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
918 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
919 assert_eq!(cipher_cipher_text, plaintext);
920 println!();
921
922
923 // Operators
924 let mut tdes = BigCryptor64::new()
925 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64)
926 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
927 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64);
928 let plaintext = 0x_1234567890ABCDEF_u64;
929 let ciphertext = tdes.encrypt_u64(plaintext);
930
931 println!("Plaintext:\t\t{:#018X}", plaintext);
932 println!("Ciphertext:\t\t{:#018X}", ciphertext);
933 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
934
935 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
936 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
937 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
938 assert_eq!(cipher_cipher_text, plaintext);
939 println!("-------------------------------");
940}
941
942fn des_get_key()
943{
944 println!("des_get_key");
945 use cryptocol::symmetric::DES;
946
947 let mut des = DES::new();
948 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
949 let key = des.get_key();
950 print!("K = ");
951 for k in key
952 { print!("{:#02X} ", k); }
953 assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
954}
955
956fn des_get_key_u64()
957{
958 println!("des_get_key_u64");
959 use cryptocol::symmetric::DES;
960
961 let mut des = DES::new();
962 des.set_key_u64(0xEFCDAB9078563412);
963 let key = des.get_key_u64();
964 println!("Key = {}", key);
965 assert_eq!(key, 0xEFCDAB9078563412_u64);
966}
967
968fn des_set_key()
969{
970 println!("des_set_key");
971 use cryptocol::symmetric::DES;
972
973 // Normal case
974 let mut des = DES::new();
975 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
976 let plaintext = 0x1234567890ABCDEF_u64;
977 let ciphertext = des.encrypt_u64(plaintext);
978
979 println!("Plaintext:\t\t{:#018X}", plaintext);
980 println!("Ciphertext:\t\t{:#018X}", ciphertext);
981 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
982
983 let cipher_cipher_text = des.encrypt_u64(ciphertext);
984 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
985 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
986 assert_ne!(cipher_cipher_text, plaintext);
987 println!();
988
989 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
990 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
991 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
992 let mut des1 = DES::new();
993 let mut des2 = DES::new();
994 des1.set_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
995 des2.set_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
996
997 let plaintext = 0x1234567890ABCDEF_u64;
998 let ciphertext1 = des1.encrypt_u64(plaintext);
999 let ciphertext2 = des2.encrypt_u64(plaintext);
1000
1001 println!("Plaintext:\t\t{:#018X}", plaintext);
1002 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1003 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1004 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1005 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1006 assert_eq!(ciphertext1, ciphertext2);
1007
1008 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1009 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1010 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1011 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1012 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1013 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1014 assert_eq!(cipher_cipher_text1, plaintext);
1015 assert_eq!(cipher_cipher_text2, plaintext);
1016 println!();
1017 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
1018 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
1019
1020
1021 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1022 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
1023 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
1024 let mut des1 = DES::new();
1025 let mut des2 = DES::new();
1026 des1.set_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
1027 des2.set_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
1028 let plaintext = 0x1234567890ABCDEF_u64;
1029 let ciphertext1 = des1.encrypt_u64(plaintext);
1030 let ciphertext2 = des2.encrypt_u64(plaintext);
1031
1032 println!("Plaintext:\t\t{:#018X}", plaintext);
1033 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1034 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1035 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1036 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1037 assert_eq!(ciphertext1, ciphertext2);
1038
1039 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1040 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1041 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1042 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1043 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1044 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1045 assert_eq!(cipher_cipher_text1, plaintext);
1046 assert_eq!(cipher_cipher_text2, plaintext);
1047 println!();
1048 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1049 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
1050
1051 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1052 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0] is the same key as the key
1053 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
1054 let mut des1 = DES::new();
1055 let mut des2 = DES::new();
1056 des1.set_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
1057 des2.set_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
1058 let plaintext = 0x1234567890ABCDEF_u64;
1059 let ciphertext1 = des1.encrypt_u64(plaintext);
1060 let ciphertext2 = des2.encrypt_u64(plaintext);
1061
1062 println!("Plaintext:\t\t{:#018X}", plaintext);
1063 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1064 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1065 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1066 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1067 assert_eq!(ciphertext1, ciphertext2);
1068
1069 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1070 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1071 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1072 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1073 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1074 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1075 assert_eq!(cipher_cipher_text1, plaintext);
1076 assert_eq!(cipher_cipher_text2, plaintext);
1077 println!();
1078 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1079 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
1080
1081 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1082 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
1083 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
1084 let mut des1 = DES::new();
1085 let mut des2 = DES::new();
1086 des1.set_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
1087 des2.set_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
1088 let plaintext = 0x1234567890ABCDEF_u64;
1089 let ciphertext1 = des1.encrypt_u64(plaintext);
1090 let ciphertext2 = des2.encrypt_u64(plaintext);
1091
1092 println!("Plaintext:\t\t{:#018X}", plaintext);
1093 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1094 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1095 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1096 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1097 assert_eq!(ciphertext1, ciphertext2);
1098
1099 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1100 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1101 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1102 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1103 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1104 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1105 assert_eq!(cipher_cipher_text1, plaintext);
1106 assert_eq!(cipher_cipher_text2, plaintext);
1107 println!();
1108 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1109 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
1110
1111 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
1112 let mut des1 = DES::new();
1113 let mut des2 = DES::new();
1114 des1.set_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
1115 des2.set_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
1116
1117 let plaintext = 0x1234567890ABCDEF_u64;
1118 let ciphertext = des1.encrypt_u64(plaintext);
1119 println!("Plaintext:\t\t{:#018X}", plaintext);
1120 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1121 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1122
1123 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1124 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1125 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1126 assert_eq!(cipher_cipher_text, plaintext);
1127
1128 let ciphertext = des2.encrypt_u64(plaintext);
1129 println!("Plaintext:\t\t{:#018X}", plaintext);
1130 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1131 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1132
1133 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1134 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1135 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1136 assert_eq!(cipher_cipher_text, plaintext);
1137 println!();
1138 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]
1139 // and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
1140
1141 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
1142 let mut des1 = DES::new();
1143 let mut des2 = DES::new();
1144 des1.set_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
1145 des2.set_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
1146
1147 let plaintext = 0x1234567890ABCDEF_u64;
1148 let ciphertext = des1.encrypt_u64(plaintext);
1149 println!("Plaintext:\t\t{:#018X}", plaintext);
1150 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1151 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1152
1153 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1154 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1155 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1156 assert_eq!(cipher_cipher_text, plaintext);
1157
1158 let ciphertext = des2.encrypt_u64(plaintext);
1159 println!("Plaintext:\t\t{:#018X}", plaintext);
1160 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1161 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1162
1163 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1164 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1165 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1166 assert_eq!(cipher_cipher_text, plaintext);
1167 println!();
1168 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]
1169 // and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
1170
1171 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
1172 let mut des1 = DES::new();
1173 let mut des2 = DES::new();
1174 des1.set_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
1175 des2.set_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
1176
1177 let plaintext = 0x1234567890ABCDEF_u64;
1178 let ciphertext = des1.encrypt_u64(plaintext);
1179 println!("Plaintext:\t\t{:#018X}", plaintext);
1180 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1181 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1182
1183 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1184 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1185 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1186 assert_eq!(cipher_cipher_text, plaintext);
1187
1188 let ciphertext = des2.encrypt_u64(plaintext);
1189 println!("Plaintext:\t\t{:#018X}", plaintext);
1190 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1191 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1192
1193 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1194 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1195 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1196 assert_eq!(cipher_cipher_text, plaintext);
1197 println!();
1198 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]
1199 // and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
1200
1201 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
1202 let mut des1 = DES::new();
1203 let mut des2 = DES::new();
1204 des1.set_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
1205 des2.set_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
1206
1207 let plaintext = 0x1234567890ABCDEF_u64;
1208 let ciphertext = des1.encrypt_u64(plaintext);
1209 println!("Plaintext:\t\t{:#018X}", plaintext);
1210 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1211 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1212
1213 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1214 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1215 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1216 assert_eq!(cipher_cipher_text, plaintext);
1217
1218 let ciphertext = des2.encrypt_u64(plaintext);
1219 println!("Plaintext:\t\t{:#018X}", plaintext);
1220 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1221 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1222
1223 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1224 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1225 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1226 assert_eq!(cipher_cipher_text, plaintext);
1227 println!();
1228 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]
1229 // and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
1230
1231 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
1232 let mut des1 = DES::new();
1233 let mut des2 = DES::new();
1234 des1.set_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
1235 des2.set_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
1236
1237 let plaintext = 0x1234567890ABCDEF_u64;
1238 let ciphertext = des1.encrypt_u64(plaintext);
1239 println!("Plaintext:\t\t{:#018X}", plaintext);
1240 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1241 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1242
1243 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1244 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1245 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1246 assert_eq!(cipher_cipher_text, plaintext);
1247
1248 let ciphertext = des2.encrypt_u64(plaintext);
1249 println!("Plaintext:\t\t{:#018X}", plaintext);
1250 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1251 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1252
1253 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1254 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1255 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1256 assert_eq!(cipher_cipher_text, plaintext);
1257 println!();
1258 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]
1259 // and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
1260
1261 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
1262 let mut des1 = DES::new();
1263 let mut des2 = DES::new();
1264 des1.set_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
1265 des2.set_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
1266
1267 let plaintext = 0x1234567890ABCDEF_u64;
1268 let ciphertext = des1.encrypt_u64(plaintext);
1269 println!("Plaintext:\t\t{:#018X}", plaintext);
1270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1271 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1272
1273 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1274 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1275 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1276 assert_eq!(cipher_cipher_text, plaintext);
1277
1278 let ciphertext = des2.encrypt_u64(plaintext);
1279 println!("Plaintext:\t\t{:#018X}", plaintext);
1280 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1281 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1282
1283 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1284 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1285 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1286 assert_eq!(cipher_cipher_text, plaintext);
1287 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]
1288 // and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
1289 println!("-------------------------------");
1290}Sourcepub fn set_key_u64(&mut self, key: u64)
pub fn set_key_u64(&mut self, key: u64)
Sets the key.
§Arguments
- The argument
keyis ofu64. - It should be in the same endianness of machine. For example,
if a key is [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF],
the key in
u64is 0x_1234567890ABCDEF_u64 for big-endian machine, and the key inu64is 0x_EFCDAB9078563412_u64 for little-endian machine. - Remember that inverted parity bits do not affect the 56-bit real key. So, 0x_0000_0000_0000_0000_u4, 0x_0101_0101_0101_0101_u64, 0x_0000_0000_0000_0001_u64, 0x_0000_0000_0000_0100_u64, 0x_0100_0010_0000_0001_u64, etc. are all the same keys. Each key has 255 different equivalent keys in DES.
§Features
This method sets the key to be the given argument key.
§Example 1 for normal case
use cryptocol::symmetric::DES;
let mut des = DES::new();
des.set_key_u64(0xEFCDAB9078563412);
let plaintext = 0x1234567890ABCDEF_u64;
let ciphertext = des.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
let cipher_cipher_text = des.encrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
assert_ne!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
50fn des_quick_start_instantiation_without_key()
51{
52 println!("des_quick_start_instantiation_without_key()");
53 use cryptocol::symmetric::DES;
54
55 let mut a_des = DES::new();
56 let key = 0x_1234567890ABCDEF_u64;
57 a_des.set_key_u64(key);
58
59 let mut a_des = DES::new();
60 let key = [0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8];
61 a_des.set_key(key);
62 println!("-------------------------------");
63}
64
65fn des_quick_start_encryption_decryption_16_rounds()
66{
67 println!("des_quick_start_encryption_decryption_16_rounds()");
68 use std::io::Write;
69 use std::fmt::Write as _;
70 use cryptocol::symmetric::{ CBC_PKCS7, DES };
71
72 let mut a_des = DES::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
73 let message = "In the beginning God created the heavens and the earth.";
74 println!("M =\t{}", message);
75 let iv = 0x_FEDCBA0987654321_u64;
76 println!("IV =\t{}", iv);
77 let mut cipher = Vec::<u8>::new();
78 a_des.encrypt_str_into_vec(iv, message, &mut cipher);
79 print!("C =\t");
80 for c in cipher.clone()
81 { print!("{:02X} ", c); }
82 println!();
83 let mut txt = String::new();
84 for c in cipher.clone()
85 { write!(txt, "{:02X} ", c); }
86 assert_eq!(txt, "4B B5 ED DC A0 58 7E 6D 6C 3B A2 00 38 C3 D4 29 42 B1 CF 0D E9 FA EA 11 11 6B C8 30 73 39 DD B7 3F 96 9B A3 76 05 34 7E 64 2F D4 CC B2 68 33 64 C5 9E EF 01 A9 4A FD 5B ");
87
88 let mut recovered = String::new();
89 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
90 println!("B (16 rounds) =\t{}", recovered);
91 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
92 assert_eq!(recovered, message);
93 println!("-------------------------------");
94}
95
96fn des_quick_start_encryption_decryption_256_rounds()
97{
98 println!("des_quick_start_encryption_decryption_256_rounds()");
99 use std::io::Write;
100 use std::fmt::Write as _;
101 use cryptocol::symmetric::{ CBC_PKCS7, DES_Expanded };
102
103 let mut a_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key([0xEFu8, 0xCDu8, 0xABu8, 0x90u8, 0x78u8, 0x56u8, 0x34u8, 0x12u8]);
104 let message = "In the beginning God created the heavens and the earth.";
105 println!("M =\t{}", message);
106 let iv = 0x_FEDCBA0987654321_u64;
107 println!("IV =\t{}", iv);
108 let mut cipher = Vec::<u8>::new();
109 a_des.encrypt_into_vec(iv, message.as_ptr(), message.len() as u64, &mut cipher);
110 print!("C =\t");
111 for c in cipher.clone()
112 { print!("{:02X} ", c); }
113 println!();
114 let mut txt = String::new();
115 for c in cipher.clone()
116 { write!(txt, "{:02X} ", c); }
117 assert_eq!(txt, "0B EA 6B BC 68 F9 B0 3E 7D AF DE 71 9C 08 AA 16 42 40 1C C8 DC 40 51 C6 8D D4 E7 D2 0B A4 F2 09 02 02 C2 6E 99 BC 9E 2A F4 11 7E 48 A7 ED 76 70 C6 9D C6 BD A6 9B 58 8B ");
118
119 let mut recovered = String::new();
120 a_des.decrypt_vec_into_string(iv, &cipher, &mut recovered);
121 println!("B =\t{}", recovered);
122 assert_eq!(recovered, "In the beginning God created the heavens and the earth.");
123 assert_eq!(recovered, message);
124 println!("-------------------------------");
125}
126
127fn des_basic_operation_main()
128{
129 des_new();
130 des_new_with_key();
131 des_new_with_key_u64();
132 des_encryptor_with_key();
133 des_encryptor_with_key_u64();
134 des_decryptor_with_key();
135 des_decryptor_with_key_u64();
136 des_get_key();
137 des_get_key_u64();
138 des_set_key();
139 des_set_key_u64();
140 des_turn_inverse();
141 des_turn_encryptor();
142 des_turn_decryptor();
143}
144
145fn des_new()
146{
147 println!("des_new()");
148 use cryptocol::symmetric::DES;
149
150 let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
151 let plaintext = 0x1234567890ABCDEF_u64;
152 let ciphertext = des.encrypt_u64(plaintext);
153
154 println!("Plaintext:\t\t{:#018X}", plaintext);
155 println!("Ciphertext:\t\t{:#018X}", ciphertext);
156 assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
157
158 let cipher_cipher_text = des.encrypt_u64(ciphertext);
159 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
160 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
161 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
162
163 #[cfg(test)]
164 des_compile_fail_new();
165 println!("-------------------------------");
166}
167
168#[test]
169fn des_compile_fail_new()
170{
171 use cryptocol::symmetric::DES;
172 let des = DES::new();
173 // It cannot be compiled!
174 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
175}
176
177fn des_new_with_key()
178{
179 println!("des_new_with_key()");
180 use cryptocol::symmetric::DES;
181
182 // Normal case
183 let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
184 let plaintext = 0x1234567890ABCDEF_u64;
185 let ciphertext = des.encrypt_u64(plaintext);
186
187 println!("Plaintext:\t\t{:#018X}", plaintext);
188 println!("Ciphertext:\t\t{:#018X}", ciphertext);
189 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
190
191 let cipher_cipher_text = des.encrypt_u64(ciphertext);
192 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
193 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
194 assert_ne!(cipher_cipher_text, plaintext);
195 println!();
196
197 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
198 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
199 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
200 let mut des1 = DES::new_with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
201 let mut des2 = DES::new_with_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
202
203 let plaintext = 0x1234567890ABCDEF_u64;
204 let ciphertext1 = des1.encrypt_u64(plaintext);
205 let ciphertext2 = des2.encrypt_u64(plaintext);
206
207 println!("Plaintext:\t\t{:#018X}", plaintext);
208 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
209 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
210 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
211 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
212 assert_eq!(ciphertext1, ciphertext2);
213
214 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
215 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
216 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
217 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
218 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
219 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
220 assert_eq!(cipher_cipher_text1, plaintext);
221 assert_eq!(cipher_cipher_text2, plaintext);
222 println!();
223 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
224 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
225
226
227 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
228 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
229 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
230 let mut des1 = DES::new_with_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
231 let mut des2 = DES::new_with_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
232 let plaintext = 0x1234567890ABCDEF_u64;
233 let ciphertext1 = des1.encrypt_u64(plaintext);
234 let ciphertext2 = des2.encrypt_u64(plaintext);
235
236 println!("Plaintext:\t\t{:#018X}", plaintext);
237 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
238 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
239 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
240 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
241 assert_eq!(ciphertext1, ciphertext2);
242
243 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
244 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
245 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
246 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
247 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
248 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
249 assert_eq!(cipher_cipher_text1, plaintext);
250 assert_eq!(cipher_cipher_text2, plaintext);
251 println!();
252 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
253 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
254
255 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
256 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1] is the same key as the key
257 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
258 let mut des1 = DES::new_with_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
259 let mut des2 = DES::new_with_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
260 let plaintext = 0x1234567890ABCDEF_u64;
261 let ciphertext1 = des1.encrypt_u64(plaintext);
262 let ciphertext2 = des2.encrypt_u64(plaintext);
263
264 println!("Plaintext:\t\t{:#018X}", plaintext);
265 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
266 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
267 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
268 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
269 assert_eq!(ciphertext1, ciphertext2);
270
271 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
272 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
273 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
274 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
275 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
276 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
277 assert_eq!(cipher_cipher_text1, plaintext);
278 assert_eq!(cipher_cipher_text2, plaintext);
279 println!();
280 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
281 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
282
283 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
284 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
285 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
286 let mut des1 = DES::new_with_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
287 let mut des2 = DES::new_with_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
288 let plaintext = 0x1234567890ABCDEF_u64;
289 let ciphertext1 = des1.encrypt_u64(plaintext);
290 let ciphertext2 = des2.encrypt_u64(plaintext);
291
292 println!("Plaintext:\t\t{:#018X}", plaintext);
293 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
294 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
295 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
296 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
297 assert_eq!(ciphertext1, ciphertext2);
298
299 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
300 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
301 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
302 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
303 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
304 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
305 assert_eq!(cipher_cipher_text1, plaintext);
306 assert_eq!(cipher_cipher_text2, plaintext);
307 println!();
308 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
309 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
310
311 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
312 let mut des1 = DES::new_with_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
313 let mut des2 = DES::new_with_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
314
315 let plaintext = 0x1234567890ABCDEF_u64;
316 let ciphertext = des1.encrypt_u64(plaintext);
317 println!("Plaintext:\t\t{:#018X}", plaintext);
318 println!("Ciphertext:\t\t{:#018X}", ciphertext);
319 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
320
321 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
322 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
323 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
324 assert_eq!(cipher_cipher_text, plaintext);
325
326 let ciphertext = des2.encrypt_u64(plaintext);
327 println!("Plaintext:\t\t{:#018X}", plaintext);
328 println!("Ciphertext:\t\t{:#018X}", ciphertext);
329 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
330
331 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
332 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
333 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
334 assert_eq!(cipher_cipher_text, plaintext);
335 println!();
336 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
337
338 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
339 let mut des1 = DES::new_with_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
340 let mut des2 = DES::new_with_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
341
342 let plaintext = 0x1234567890ABCDEF_u64;
343 let ciphertext = des1.encrypt_u64(plaintext);
344 println!("Plaintext:\t\t{:#018X}", plaintext);
345 println!("Ciphertext:\t\t{:#018X}", ciphertext);
346 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
347
348 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
349 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
350 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
351 assert_eq!(cipher_cipher_text, plaintext);
352
353 let ciphertext = des2.encrypt_u64(plaintext);
354 println!("Plaintext:\t\t{:#018X}", plaintext);
355 println!("Ciphertext:\t\t{:#018X}", ciphertext);
356 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
357
358 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
359 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
360 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
361 assert_eq!(cipher_cipher_text, plaintext);
362 println!();
363 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
364
365 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
366 let mut des1 = DES::new_with_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
367 let mut des2 = DES::new_with_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
368
369 let plaintext = 0x1234567890ABCDEF_u64;
370 let ciphertext = des1.encrypt_u64(plaintext);
371 println!("Plaintext:\t\t{:#018X}", plaintext);
372 println!("Ciphertext:\t\t{:#018X}", ciphertext);
373 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
374
375 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
376 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
377 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
378 assert_eq!(cipher_cipher_text, plaintext);
379
380 let ciphertext = des2.encrypt_u64(plaintext);
381 println!("Plaintext:\t\t{:#018X}", plaintext);
382 println!("Ciphertext:\t\t{:#018X}", ciphertext);
383 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
384
385 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
386 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
387 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
388 assert_eq!(cipher_cipher_text, plaintext);
389 println!();
390 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
391
392 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
393 let mut des1 = DES::new_with_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
394 let mut des2 = DES::new_with_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
395
396 let plaintext = 0x1234567890ABCDEF_u64;
397 let ciphertext = des1.encrypt_u64(plaintext);
398 println!("Plaintext:\t\t{:#018X}", plaintext);
399 println!("Ciphertext:\t\t{:#018X}", ciphertext);
400 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
401
402 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
403 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
404 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
405 assert_eq!(cipher_cipher_text, plaintext);
406
407 let ciphertext = des2.encrypt_u64(plaintext);
408 println!("Plaintext:\t\t{:#018X}", plaintext);
409 println!("Ciphertext:\t\t{:#018X}", ciphertext);
410 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
411
412 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
413 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
414 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
415 assert_eq!(cipher_cipher_text, plaintext);
416 println!();
417 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
418
419 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
420 let mut des1 = DES::new_with_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
421 let mut des2 = DES::new_with_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
422
423 let plaintext = 0x1234567890ABCDEF_u64;
424 let ciphertext = des1.encrypt_u64(plaintext);
425 println!("Plaintext:\t\t{:#018X}", plaintext);
426 println!("Ciphertext:\t\t{:#018X}", ciphertext);
427 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
428
429 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
430 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
431 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
432 assert_eq!(cipher_cipher_text, plaintext);
433
434 let ciphertext = des2.encrypt_u64(plaintext);
435 println!("Plaintext:\t\t{:#018X}", plaintext);
436 println!("Ciphertext:\t\t{:#018X}", ciphertext);
437 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
438
439 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
440 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
441 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
442 assert_eq!(cipher_cipher_text, plaintext);
443 println!();
444 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
445
446 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
447 let mut des1 = DES::new_with_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
448 let mut des2 = DES::new_with_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
449
450 let plaintext = 0x1234567890ABCDEF_u64;
451 let ciphertext = des1.encrypt_u64(plaintext);
452 println!("Plaintext:\t\t{:#018X}", plaintext);
453 println!("Ciphertext:\t\t{:#018X}", ciphertext);
454 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
455
456 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
457 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
458 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
459 assert_eq!(cipher_cipher_text, plaintext);
460
461 let ciphertext = des2.encrypt_u64(plaintext);
462 println!("Plaintext:\t\t{:#018X}", plaintext);
463 println!("Ciphertext:\t\t{:#018X}", ciphertext);
464 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
465
466 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
467 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
468 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
469 assert_eq!(cipher_cipher_text, plaintext);
470 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
471
472 #[cfg(test)]
473 des_compile_fail_new_with_key();
474 println!("-------------------------------");
475}
476
477#[test]
478fn des_compile_fail_new_with_key()
479{
480 use cryptocol::symmetric::DES;
481 let des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
482 // It cannot be compiled!
483 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
484}
485
486fn des_new_with_key_u64()
487{
488 println!("des_new_with_key_u64");
489 use cryptocol::symmetric::DES;
490
491 // Normal case
492 let mut des = DES::new_with_key_u64(0xEFCDAB9078563412);
493 let plaintext = 0x1234567890ABCDEF_u64;
494 let ciphertext = des.encrypt_u64(plaintext);
495
496 println!("Plaintext:\t\t{:#018X}", plaintext);
497 println!("Ciphertext:\t\t{:#018X}", ciphertext);
498 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
499
500 let cipher_cipher_text = des.encrypt_u64(ciphertext);
501 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
502 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
503 assert_ne!(cipher_cipher_text, plaintext);
504 println!();
505
506 // Weak key case 1 for 0x0000000000000000
507 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
508 let mut des1 = DES::new_with_key_u64(0x0000000000000000);
509 let mut des2 = DES::new_with_key_u64(0x0101010101010101);
510
511 let plaintext = 0x1234567890ABCDEF_u64;
512 let ciphertext1 = des1.encrypt_u64(plaintext);
513 let ciphertext2 = des2.encrypt_u64(plaintext);
514
515 println!("Plaintext:\t\t{:#018X}", plaintext);
516 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
517 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
518 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
519 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
520 assert_eq!(ciphertext1, ciphertext2);
521
522 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
523 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
524 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
525 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
526 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
527 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
528 assert_eq!(cipher_cipher_text1, plaintext);
529 assert_eq!(cipher_cipher_text2, plaintext);
530 println!();
531 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
532
533 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
534 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
535 let mut des1 = DES::new_with_key_u64(0xFFFFFFFFFFFFFFFF);
536 let mut des2 = DES::new_with_key_u64(0xFEFEFEFEFEFEFEFE);
537 let plaintext = 0x1234567890ABCDEF_u64;
538 let ciphertext1 = des1.encrypt_u64(plaintext);
539 let ciphertext2 = des2.encrypt_u64(plaintext);
540
541 println!("Plaintext:\t\t{:#018X}", plaintext);
542 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
543 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
544 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
545 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
546 assert_eq!(ciphertext1, ciphertext2);
547
548 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
549 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
550 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
551 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
552 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
553 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
554 assert_eq!(cipher_cipher_text1, plaintext);
555 assert_eq!(cipher_cipher_text2, plaintext);
556 println!();
557 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
558
559 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
560 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
561 let mut des1 = DES::new_with_key_u64(0xF1F1F1F1E0E0E0E0);
562 let mut des2 = DES::new_with_key_u64(0xF0F0F0F0E1E1E1E1);
563 let plaintext = 0x1234567890ABCDEF_u64;
564 let ciphertext1 = des1.encrypt_u64(plaintext);
565 let ciphertext2 = des2.encrypt_u64(plaintext);
566
567 println!("Plaintext:\t\t{:#018X}", plaintext);
568 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
569 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
570 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
571 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
572 assert_eq!(ciphertext1, ciphertext2);
573
574 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
575 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
576 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
577 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
578 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
579 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
580 assert_eq!(cipher_cipher_text1, plaintext);
581 assert_eq!(cipher_cipher_text2, plaintext);
582 println!();
583 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
584
585 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
586 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
587 let mut des1 = DES::new_with_key_u64(0x0E0E0E0E1F1F1F1F);
588 let mut des2 = DES::new_with_key_u64(0x0F0F0F0F1E1E1E1E);
589 let plaintext = 0x1234567890ABCDEF_u64;
590 let ciphertext1 = des1.encrypt_u64(plaintext);
591 let ciphertext2 = des2.encrypt_u64(plaintext);
592
593 println!("Plaintext:\t\t{:#018X}", plaintext);
594 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
595 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
596 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
597 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
598 assert_eq!(ciphertext1, ciphertext2);
599
600 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
601 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
602 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
603 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
604 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
605 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
606 assert_eq!(cipher_cipher_text1, plaintext);
607 assert_eq!(cipher_cipher_text2, plaintext);
608 println!();
609 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
610
611 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
612 let mut des1 = DES::new_with_key_u64(0x0E010E011F011F01);
613 let mut des2 = DES::new_with_key_u64(0x010E010E011F011F);
614
615 let plaintext = 0x1234567890ABCDEF_u64;
616 let ciphertext = des1.encrypt_u64(plaintext);
617 println!("Plaintext:\t\t{:#018X}", plaintext);
618 println!("Ciphertext:\t\t{:#018X}", ciphertext);
619 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
620
621 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
622 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
623 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
624 assert_eq!(cipher_cipher_text, plaintext);
625
626 let ciphertext = des2.encrypt_u64(plaintext);
627 println!("Plaintext:\t\t{:#018X}", plaintext);
628 println!("Ciphertext:\t\t{:#018X}", ciphertext);
629 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
630
631 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
632 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
633 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
634 assert_eq!(cipher_cipher_text, plaintext);
635 println!();
636 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
637
638 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
639 let mut des1 = DES::new_with_key_u64(0xF101F101E001E001);
640 let mut des2 = DES::new_with_key_u64(0x01F101F101E001E0);
641
642 let plaintext = 0x1234567890ABCDEF_u64;
643 let ciphertext = des1.encrypt_u64(plaintext);
644 println!("Plaintext:\t\t{:#018X}", plaintext);
645 println!("Ciphertext:\t\t{:#018X}", ciphertext);
646 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
647
648 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
649 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
650 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
651 assert_eq!(cipher_cipher_text, plaintext);
652
653 let ciphertext = des2.encrypt_u64(plaintext);
654 println!("Plaintext:\t\t{:#018X}", plaintext);
655 println!("Ciphertext:\t\t{:#018X}", ciphertext);
656 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
657
658 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
659 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
660 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
661 assert_eq!(cipher_cipher_text, plaintext);
662 println!();
663 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
664
665 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
666 let mut des1 = DES::new_with_key_u64(0xFE01FE01FE01FE01);
667 let mut des2 = DES::new_with_key_u64(0x01FE01FE01FE01FE);
668
669 let plaintext = 0x1234567890ABCDEF_u64;
670 let ciphertext = des1.encrypt_u64(plaintext);
671 println!("Plaintext:\t\t{:#018X}", plaintext);
672 println!("Ciphertext:\t\t{:#018X}", ciphertext);
673 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
674
675 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
676 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
677 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
678 assert_eq!(cipher_cipher_text, plaintext);
679
680 let ciphertext = des2.encrypt_u64(plaintext);
681 println!("Plaintext:\t\t{:#018X}", plaintext);
682 println!("Ciphertext:\t\t{:#018X}", ciphertext);
683 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
684
685 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
686 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
687 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
688 assert_eq!(cipher_cipher_text, plaintext);
689 println!();
690 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
691
692 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
693 let mut des1 = DES::new_with_key_u64(0xF10EF10EE01FE01F);
694 let mut des2 = DES::new_with_key_u64(0x0EF10EF11FE01FE0);
695
696 let plaintext = 0x1234567890ABCDEF_u64;
697 let ciphertext = des1.encrypt_u64(plaintext);
698 println!("Plaintext:\t\t{:#018X}", plaintext);
699 println!("Ciphertext:\t\t{:#018X}", ciphertext);
700 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
701
702 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
703 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
704 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
705 assert_eq!(cipher_cipher_text, plaintext);
706
707 let ciphertext = des2.encrypt_u64(plaintext);
708 println!("Plaintext:\t\t{:#018X}", plaintext);
709 println!("Ciphertext:\t\t{:#018X}", ciphertext);
710 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
711
712 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
713 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
714 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
715 assert_eq!(cipher_cipher_text, plaintext);
716 println!();
717 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
718
719 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
720 let mut des1 = DES::new_with_key_u64(0xFE0EFE0EFE1FFE1F);
721 let mut des2 = DES::new_with_key_u64(0x0EFE0EFE1FFE1FFE);
722
723 let plaintext = 0x1234567890ABCDEF_u64;
724 let ciphertext = des1.encrypt_u64(plaintext);
725 println!("Plaintext:\t\t{:#018X}", plaintext);
726 println!("Ciphertext:\t\t{:#018X}", ciphertext);
727 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
728
729 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
730 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
731 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
732 assert_eq!(cipher_cipher_text, plaintext);
733
734 let ciphertext = des2.encrypt_u64(plaintext);
735 println!("Plaintext:\t\t{:#018X}", plaintext);
736 println!("Ciphertext:\t\t{:#018X}", ciphertext);
737 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
738
739 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
740 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
741 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
742 assert_eq!(cipher_cipher_text, plaintext);
743 println!();
744 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
745
746 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
747 let mut des1 = DES::new_with_key_u64(0xFEF1FEF1FEE0FEE0);
748 let mut des2 = DES::new_with_key_u64(0xF1FEF1FEE0FEE0FE);
749
750 let plaintext = 0x1234567890ABCDEF_u64;
751 let ciphertext = des1.encrypt_u64(plaintext);
752 println!("Plaintext:\t\t{:#018X}", plaintext);
753 println!("Ciphertext:\t\t{:#018X}", ciphertext);
754 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
755
756 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
757 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
758 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
759 assert_eq!(cipher_cipher_text, plaintext);
760
761 let ciphertext = des2.encrypt_u64(plaintext);
762 println!("Plaintext:\t\t{:#018X}", plaintext);
763 println!("Ciphertext:\t\t{:#018X}", ciphertext);
764 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
765
766 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
767 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
768 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
769 assert_eq!(cipher_cipher_text, plaintext);
770 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
771 println!("-------------------------------");
772}
773
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}
899
900fn des_decryptor_with_key_u64()
901{
902 println!("des_decryptor_with_key_u64");
903 use cryptocol::symmetric::{ BigCryptor64, DES };
904
905 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
906 [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
907 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
908 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ] );
909 let plaintext = 0x_1234567890ABCDEF_u64;
910 let ciphertext = tdes.encrypt_u64(plaintext);
911
912 println!("Plaintext:\t\t{:#018X}", plaintext);
913 println!("Ciphertext:\t\t{:#018X}", ciphertext);
914 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
915
916 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
917 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
918 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
919 assert_eq!(cipher_cipher_text, plaintext);
920 println!();
921
922
923 // Operators
924 let mut tdes = BigCryptor64::new()
925 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64)
926 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
927 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64);
928 let plaintext = 0x_1234567890ABCDEF_u64;
929 let ciphertext = tdes.encrypt_u64(plaintext);
930
931 println!("Plaintext:\t\t{:#018X}", plaintext);
932 println!("Ciphertext:\t\t{:#018X}", ciphertext);
933 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
934
935 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
936 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
937 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
938 assert_eq!(cipher_cipher_text, plaintext);
939 println!("-------------------------------");
940}
941
942fn des_get_key()
943{
944 println!("des_get_key");
945 use cryptocol::symmetric::DES;
946
947 let mut des = DES::new();
948 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
949 let key = des.get_key();
950 print!("K = ");
951 for k in key
952 { print!("{:#02X} ", k); }
953 assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
954}
955
956fn des_get_key_u64()
957{
958 println!("des_get_key_u64");
959 use cryptocol::symmetric::DES;
960
961 let mut des = DES::new();
962 des.set_key_u64(0xEFCDAB9078563412);
963 let key = des.get_key_u64();
964 println!("Key = {}", key);
965 assert_eq!(key, 0xEFCDAB9078563412_u64);
966}
967
968fn des_set_key()
969{
970 println!("des_set_key");
971 use cryptocol::symmetric::DES;
972
973 // Normal case
974 let mut des = DES::new();
975 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
976 let plaintext = 0x1234567890ABCDEF_u64;
977 let ciphertext = des.encrypt_u64(plaintext);
978
979 println!("Plaintext:\t\t{:#018X}", plaintext);
980 println!("Ciphertext:\t\t{:#018X}", ciphertext);
981 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
982
983 let cipher_cipher_text = des.encrypt_u64(ciphertext);
984 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
985 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
986 assert_ne!(cipher_cipher_text, plaintext);
987 println!();
988
989 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
990 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
991 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
992 let mut des1 = DES::new();
993 let mut des2 = DES::new();
994 des1.set_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
995 des2.set_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
996
997 let plaintext = 0x1234567890ABCDEF_u64;
998 let ciphertext1 = des1.encrypt_u64(plaintext);
999 let ciphertext2 = des2.encrypt_u64(plaintext);
1000
1001 println!("Plaintext:\t\t{:#018X}", plaintext);
1002 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1003 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1004 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1005 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1006 assert_eq!(ciphertext1, ciphertext2);
1007
1008 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1009 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1010 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1011 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1012 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1013 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1014 assert_eq!(cipher_cipher_text1, plaintext);
1015 assert_eq!(cipher_cipher_text2, plaintext);
1016 println!();
1017 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
1018 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
1019
1020
1021 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1022 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
1023 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
1024 let mut des1 = DES::new();
1025 let mut des2 = DES::new();
1026 des1.set_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
1027 des2.set_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
1028 let plaintext = 0x1234567890ABCDEF_u64;
1029 let ciphertext1 = des1.encrypt_u64(plaintext);
1030 let ciphertext2 = des2.encrypt_u64(plaintext);
1031
1032 println!("Plaintext:\t\t{:#018X}", plaintext);
1033 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1034 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1035 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1036 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1037 assert_eq!(ciphertext1, ciphertext2);
1038
1039 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1040 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1041 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1042 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1043 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1044 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1045 assert_eq!(cipher_cipher_text1, plaintext);
1046 assert_eq!(cipher_cipher_text2, plaintext);
1047 println!();
1048 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1049 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
1050
1051 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1052 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0] is the same key as the key
1053 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
1054 let mut des1 = DES::new();
1055 let mut des2 = DES::new();
1056 des1.set_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
1057 des2.set_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
1058 let plaintext = 0x1234567890ABCDEF_u64;
1059 let ciphertext1 = des1.encrypt_u64(plaintext);
1060 let ciphertext2 = des2.encrypt_u64(plaintext);
1061
1062 println!("Plaintext:\t\t{:#018X}", plaintext);
1063 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1064 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1065 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1066 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1067 assert_eq!(ciphertext1, ciphertext2);
1068
1069 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1070 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1071 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1072 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1073 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1074 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1075 assert_eq!(cipher_cipher_text1, plaintext);
1076 assert_eq!(cipher_cipher_text2, plaintext);
1077 println!();
1078 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1079 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
1080
1081 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1082 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
1083 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
1084 let mut des1 = DES::new();
1085 let mut des2 = DES::new();
1086 des1.set_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
1087 des2.set_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
1088 let plaintext = 0x1234567890ABCDEF_u64;
1089 let ciphertext1 = des1.encrypt_u64(plaintext);
1090 let ciphertext2 = des2.encrypt_u64(plaintext);
1091
1092 println!("Plaintext:\t\t{:#018X}", plaintext);
1093 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1094 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1095 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1096 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1097 assert_eq!(ciphertext1, ciphertext2);
1098
1099 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1100 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1101 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1102 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1103 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1104 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1105 assert_eq!(cipher_cipher_text1, plaintext);
1106 assert_eq!(cipher_cipher_text2, plaintext);
1107 println!();
1108 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1109 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
1110
1111 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
1112 let mut des1 = DES::new();
1113 let mut des2 = DES::new();
1114 des1.set_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
1115 des2.set_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
1116
1117 let plaintext = 0x1234567890ABCDEF_u64;
1118 let ciphertext = des1.encrypt_u64(plaintext);
1119 println!("Plaintext:\t\t{:#018X}", plaintext);
1120 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1121 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1122
1123 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1124 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1125 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1126 assert_eq!(cipher_cipher_text, plaintext);
1127
1128 let ciphertext = des2.encrypt_u64(plaintext);
1129 println!("Plaintext:\t\t{:#018X}", plaintext);
1130 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1131 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1132
1133 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1134 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1135 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1136 assert_eq!(cipher_cipher_text, plaintext);
1137 println!();
1138 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]
1139 // and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
1140
1141 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
1142 let mut des1 = DES::new();
1143 let mut des2 = DES::new();
1144 des1.set_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
1145 des2.set_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
1146
1147 let plaintext = 0x1234567890ABCDEF_u64;
1148 let ciphertext = des1.encrypt_u64(plaintext);
1149 println!("Plaintext:\t\t{:#018X}", plaintext);
1150 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1151 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1152
1153 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1154 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1155 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1156 assert_eq!(cipher_cipher_text, plaintext);
1157
1158 let ciphertext = des2.encrypt_u64(plaintext);
1159 println!("Plaintext:\t\t{:#018X}", plaintext);
1160 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1161 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1162
1163 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1164 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1165 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1166 assert_eq!(cipher_cipher_text, plaintext);
1167 println!();
1168 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]
1169 // and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
1170
1171 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
1172 let mut des1 = DES::new();
1173 let mut des2 = DES::new();
1174 des1.set_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
1175 des2.set_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
1176
1177 let plaintext = 0x1234567890ABCDEF_u64;
1178 let ciphertext = des1.encrypt_u64(plaintext);
1179 println!("Plaintext:\t\t{:#018X}", plaintext);
1180 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1181 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1182
1183 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1184 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1185 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1186 assert_eq!(cipher_cipher_text, plaintext);
1187
1188 let ciphertext = des2.encrypt_u64(plaintext);
1189 println!("Plaintext:\t\t{:#018X}", plaintext);
1190 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1191 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1192
1193 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1194 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1195 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1196 assert_eq!(cipher_cipher_text, plaintext);
1197 println!();
1198 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]
1199 // and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
1200
1201 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
1202 let mut des1 = DES::new();
1203 let mut des2 = DES::new();
1204 des1.set_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
1205 des2.set_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
1206
1207 let plaintext = 0x1234567890ABCDEF_u64;
1208 let ciphertext = des1.encrypt_u64(plaintext);
1209 println!("Plaintext:\t\t{:#018X}", plaintext);
1210 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1211 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1212
1213 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1214 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1215 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1216 assert_eq!(cipher_cipher_text, plaintext);
1217
1218 let ciphertext = des2.encrypt_u64(plaintext);
1219 println!("Plaintext:\t\t{:#018X}", plaintext);
1220 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1221 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1222
1223 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1224 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1225 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1226 assert_eq!(cipher_cipher_text, plaintext);
1227 println!();
1228 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]
1229 // and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
1230
1231 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
1232 let mut des1 = DES::new();
1233 let mut des2 = DES::new();
1234 des1.set_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
1235 des2.set_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
1236
1237 let plaintext = 0x1234567890ABCDEF_u64;
1238 let ciphertext = des1.encrypt_u64(plaintext);
1239 println!("Plaintext:\t\t{:#018X}", plaintext);
1240 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1241 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1242
1243 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1244 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1245 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1246 assert_eq!(cipher_cipher_text, plaintext);
1247
1248 let ciphertext = des2.encrypt_u64(plaintext);
1249 println!("Plaintext:\t\t{:#018X}", plaintext);
1250 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1251 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1252
1253 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1254 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1255 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1256 assert_eq!(cipher_cipher_text, plaintext);
1257 println!();
1258 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]
1259 // and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
1260
1261 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
1262 let mut des1 = DES::new();
1263 let mut des2 = DES::new();
1264 des1.set_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
1265 des2.set_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
1266
1267 let plaintext = 0x1234567890ABCDEF_u64;
1268 let ciphertext = des1.encrypt_u64(plaintext);
1269 println!("Plaintext:\t\t{:#018X}", plaintext);
1270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1271 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1272
1273 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1274 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1275 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1276 assert_eq!(cipher_cipher_text, plaintext);
1277
1278 let ciphertext = des2.encrypt_u64(plaintext);
1279 println!("Plaintext:\t\t{:#018X}", plaintext);
1280 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1281 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1282
1283 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1284 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1285 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1286 assert_eq!(cipher_cipher_text, plaintext);
1287 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]
1288 // and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
1289 println!("-------------------------------");
1290}
1291
1292fn des_set_key_u64()
1293{
1294 println!("des_set_key_u64");
1295 use cryptocol::symmetric::DES;
1296
1297 // Normal case
1298 let mut des = DES::new();
1299 des.set_key_u64(0xEFCDAB9078563412);
1300 let plaintext = 0x1234567890ABCDEF_u64;
1301 let ciphertext = des.encrypt_u64(plaintext);
1302
1303 println!("Plaintext:\t\t{:#018X}", plaintext);
1304 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1305 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
1306
1307 let cipher_cipher_text = des.encrypt_u64(ciphertext);
1308 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1309 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
1310 assert_ne!(cipher_cipher_text, plaintext);
1311 println!();
1312
1313 // Weak key case 1 for 0x0000000000000000
1314 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
1315 let mut des1 = DES::new();
1316 let mut des2 = DES::new();
1317 des1.set_key_u64(0x0000000000000000);
1318 des2.set_key_u64(0x0101010101010101);
1319
1320 let plaintext = 0x1234567890ABCDEF_u64;
1321 let ciphertext1 = des1.encrypt_u64(plaintext);
1322 let ciphertext2 = des2.encrypt_u64(plaintext);
1323
1324 println!("Plaintext:\t\t{:#018X}", plaintext);
1325 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1326 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1327 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1328 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1329 assert_eq!(ciphertext1, ciphertext2);
1330
1331 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1332 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1333 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1334 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1335 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1336 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1337 assert_eq!(cipher_cipher_text1, plaintext);
1338 assert_eq!(cipher_cipher_text2, plaintext);
1339 println!();
1340 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
1341
1342 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
1343 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
1344 let mut des1 = DES::new();
1345 let mut des2 = DES::new();
1346 des1.set_key_u64(0xFFFFFFFFFFFFFFFF);
1347 des2.set_key_u64(0xFEFEFEFEFEFEFEFE);
1348 let plaintext = 0x1234567890ABCDEF_u64;
1349 let ciphertext1 = des1.encrypt_u64(plaintext);
1350 let ciphertext2 = des2.encrypt_u64(plaintext);
1351
1352 println!("Plaintext:\t\t{:#018X}", plaintext);
1353 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1354 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1355 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1356 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1357 assert_eq!(ciphertext1, ciphertext2);
1358
1359 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1360 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1361 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1362 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1363 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1364 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1365 assert_eq!(cipher_cipher_text1, plaintext);
1366 assert_eq!(cipher_cipher_text2, plaintext);
1367 println!();
1368 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
1369
1370 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
1371 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
1372 let mut des1 = DES::new();
1373 let mut des2 = DES::new();
1374 des1.set_key_u64(0xF1F1F1F1E0E0E0E0);
1375 des2.set_key_u64(0xF0F0F0F0E1E1E1E1);
1376 let plaintext = 0x1234567890ABCDEF_u64;
1377 let ciphertext1 = des1.encrypt_u64(plaintext);
1378 let ciphertext2 = des2.encrypt_u64(plaintext);
1379
1380 println!("Plaintext:\t\t{:#018X}", plaintext);
1381 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1382 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1383 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1384 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1385 assert_eq!(ciphertext1, ciphertext2);
1386
1387 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1388 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1389 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1390 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1391 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1392 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1393 assert_eq!(cipher_cipher_text1, plaintext);
1394 assert_eq!(cipher_cipher_text2, plaintext);
1395 println!();
1396 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
1397
1398 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
1399 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
1400 let mut des1 = DES::new();
1401 let mut des2 = DES::new();
1402 des1.set_key_u64(0x0E0E0E0E1F1F1F1F);
1403 des2.set_key_u64(0x0F0F0F0F1E1E1E1E);
1404 let plaintext = 0x1234567890ABCDEF_u64;
1405 let ciphertext1 = des1.encrypt_u64(plaintext);
1406 let ciphertext2 = des2.encrypt_u64(plaintext);
1407
1408 println!("Plaintext:\t\t{:#018X}", plaintext);
1409 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1410 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1411 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1412 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1413 assert_eq!(ciphertext1, ciphertext2);
1414
1415 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1416 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1417 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1418 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1419 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1420 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1421 assert_eq!(cipher_cipher_text1, plaintext);
1422 assert_eq!(cipher_cipher_text2, plaintext);
1423 println!();
1424 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
1425
1426 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
1427 let mut des1 = DES::new();
1428 let mut des2 = DES::new();
1429 des1.set_key_u64(0x0E010E011F011F01);
1430 des2.set_key_u64(0x010E010E011F011F);
1431
1432 let plaintext = 0x1234567890ABCDEF_u64;
1433 let ciphertext = des1.encrypt_u64(plaintext);
1434 println!("Plaintext:\t\t{:#018X}", plaintext);
1435 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1436 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1437
1438 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1439 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1440 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1441 assert_eq!(cipher_cipher_text, plaintext);
1442
1443 let ciphertext = des2.encrypt_u64(plaintext);
1444 println!("Plaintext:\t\t{:#018X}", plaintext);
1445 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1446 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1447
1448 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1449 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1450 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1451 assert_eq!(cipher_cipher_text, plaintext);
1452 println!();
1453 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
1454
1455 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
1456 let mut des1 = DES::new();
1457 let mut des2 = DES::new();
1458 des1.set_key_u64(0xF101F101E001E001);
1459 des2.set_key_u64(0x01F101F101E001E0);
1460
1461 let plaintext = 0x1234567890ABCDEF_u64;
1462 let ciphertext = des1.encrypt_u64(plaintext);
1463 println!("Plaintext:\t\t{:#018X}", plaintext);
1464 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1465 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1466
1467 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1468 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1469 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1470 assert_eq!(cipher_cipher_text, plaintext);
1471
1472 let ciphertext = des2.encrypt_u64(plaintext);
1473 println!("Plaintext:\t\t{:#018X}", plaintext);
1474 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1475 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1476
1477 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1478 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1479 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1480 assert_eq!(cipher_cipher_text, plaintext);
1481 println!();
1482 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
1483
1484 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
1485 let mut des1 = DES::new();
1486 let mut des2 = DES::new();
1487 des1.set_key_u64(0xFE01FE01FE01FE01);
1488 des2.set_key_u64(0x01FE01FE01FE01FE);
1489
1490 let plaintext = 0x1234567890ABCDEF_u64;
1491 let ciphertext = des1.encrypt_u64(plaintext);
1492 println!("Plaintext:\t\t{:#018X}", plaintext);
1493 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1494 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1495
1496 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1497 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1498 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1499 assert_eq!(cipher_cipher_text, plaintext);
1500
1501 let ciphertext = des2.encrypt_u64(plaintext);
1502 println!("Plaintext:\t\t{:#018X}", plaintext);
1503 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1504 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1505
1506 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1507 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1508 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1509 assert_eq!(cipher_cipher_text, plaintext);
1510 println!();
1511 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
1512
1513 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
1514 let mut des1 = DES::new();
1515 let mut des2 = DES::new();
1516 des1.set_key_u64(0xF10EF10EE01FE01F);
1517 des2.set_key_u64(0x0EF10EF11FE01FE0);
1518
1519 let plaintext = 0x1234567890ABCDEF_u64;
1520 let ciphertext = des1.encrypt_u64(plaintext);
1521 println!("Plaintext:\t\t{:#018X}", plaintext);
1522 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1523 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1524
1525 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1526 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1527 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1528 assert_eq!(cipher_cipher_text, plaintext);
1529
1530 let ciphertext = des2.encrypt_u64(plaintext);
1531 println!("Plaintext:\t\t{:#018X}", plaintext);
1532 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1533 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1534
1535 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1536 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1537 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1538 assert_eq!(cipher_cipher_text, plaintext);
1539 println!();
1540 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
1541
1542 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
1543 let mut des1 = DES::new();
1544 let mut des2 = DES::new();
1545 des1.set_key_u64(0xFE0EFE0EFE1FFE1F);
1546 des2.set_key_u64(0x0EFE0EFE1FFE1FFE);
1547
1548 let plaintext = 0x1234567890ABCDEF_u64;
1549 let ciphertext = des1.encrypt_u64(plaintext);
1550 println!("Plaintext:\t\t{:#018X}", plaintext);
1551 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1552 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1553
1554 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1555 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1556 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1557 assert_eq!(cipher_cipher_text, plaintext);
1558
1559 let ciphertext = des2.encrypt_u64(plaintext);
1560 println!("Plaintext:\t\t{:#018X}", plaintext);
1561 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1562 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1563
1564 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1565 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1566 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1567 assert_eq!(cipher_cipher_text, plaintext);
1568 println!();
1569 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
1570
1571 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
1572 let mut des1 = DES::new();
1573 let mut des2 = DES::new();
1574 des1.set_key_u64(0xFEF1FEF1FEE0FEE0);
1575 des2.set_key_u64(0xF1FEF1FEE0FEE0FE);
1576
1577 let plaintext = 0x1234567890ABCDEF_u64;
1578 let ciphertext = des1.encrypt_u64(plaintext);
1579 println!("Plaintext:\t\t{:#018X}", plaintext);
1580 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1581 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1582
1583 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1584 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1585 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1586 assert_eq!(cipher_cipher_text, plaintext);
1587
1588 let ciphertext = des2.encrypt_u64(plaintext);
1589 println!("Plaintext:\t\t{:#018X}", plaintext);
1590 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1591 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1592
1593 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1594 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1595 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1596 assert_eq!(cipher_cipher_text, plaintext);
1597 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
1598 println!("-------------------------------");
1599}
1600
1601fn des_turn_inverse()
1602{
1603 println!("des_turn_inverse");
1604 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1605
1606 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1607 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1608 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1609 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1610 keys[1].turn_inverse();
1611
1612 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1613 let plaintext = 0x_1234567890ABCDEF_u64;
1614 let ciphertext = tdes.encrypt_u64(plaintext);
1615
1616 println!("Plaintext:\t\t{:#018X}", plaintext);
1617 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1618 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1619
1620 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1621 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1622 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1623 assert_eq!(cipher_cipher_text, plaintext);
1624 println!();
1625
1626
1627 // Operators
1628 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1629 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1630 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1631 des2.turn_inverse();
1632
1633 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1634 let plaintext = 0x_1234567890ABCDEF_u64;
1635 let ciphertext = tdes.encrypt_u64(plaintext);
1636
1637 println!("Plaintext:\t\t{:#018X}", plaintext);
1638 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1639 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1640
1641 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1642 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1643 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1644 assert_eq!(cipher_cipher_text, plaintext);
1645 println!("-------------------------------");
1646}
1647
1648fn des_turn_encryptor()
1649{
1650 println!("des_turn_encryptor");
1651 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1652
1653 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1654 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1655 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1656 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1657 keys[0].turn_encryptor();
1658
1659 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1660 let plaintext = 0x_1234567890ABCDEF_u64;
1661 let ciphertext = tdes.encrypt_u64(plaintext);
1662
1663 println!("Plaintext:\t\t{:#018X}", plaintext);
1664 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1665 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1666
1667 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1668 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1669 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1670 assert_eq!(cipher_cipher_text, plaintext);
1671 println!();
1672
1673
1674 // Operators
1675 let mut des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1676 let des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1677 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1678 des1.turn_encryptor();
1679
1680 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1681 let plaintext = 0x_1234567890ABCDEF_u64;
1682 let ciphertext = tdes.encrypt_u64(plaintext);
1683
1684 println!("Plaintext:\t\t{:#018X}", plaintext);
1685 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1686 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1687
1688 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1689 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1690 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1691 assert_eq!(cipher_cipher_text, plaintext);
1692 println!("-------------------------------");
1693}
1694
1695fn des_turn_decryptor()
1696{
1697 println!("des_turn_decryptor");
1698 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1699
1700 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1701 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1702 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1703 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1704 keys[1].turn_decryptor();
1705
1706 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1707 let plaintext = 0x_1234567890ABCDEF_u64;
1708 let ciphertext = tdes.encrypt_u64(plaintext);
1709
1710 println!("Plaintext:\t\t{:#018X}", plaintext);
1711 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1712 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1713
1714 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1715 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1716 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1717 assert_eq!(cipher_cipher_text, plaintext);
1718 println!();
1719
1720
1721 // Operators
1722 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1723 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1724 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1725 des2.turn_decryptor();
1726
1727 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1728 let plaintext = 0x_1234567890ABCDEF_u64;
1729 let ciphertext = tdes.encrypt_u64(plaintext);
1730
1731 println!("Plaintext:\t\t{:#018X}", plaintext);
1732 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1733 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1734
1735 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1736 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1737 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1738 assert_eq!(cipher_cipher_text, plaintext);
1739 println!("-------------------------------");
1740}
1741
1742fn des_encrypt_decrypt_u64_array_u64_main()
1743{
1744 des_encrypt_u64();
1745 des_decrypt_u64();
1746 // des__encrypt();
1747 // des__decrypt();
1748 des_encrypt_array_u64();
1749 des_decrypt_array_u64();
1750 des_is_successful();
1751 des_is_failed();
1752 // des_set_successful();
1753 // des_set_failed();
1754 des_has_weak_key();
1755}
1756
1757fn des_encrypt_u64()
1758{
1759 println!("des_encrypt_u64");
1760 use cryptocol::symmetric::{ DES, DES_Expanded };
1761
1762 // Normal case
1763 let key = 0x_1234567890ABCDEF_u64;
1764 println!("K =\t{:#018X}", key);
1765
1766 let message = 0x_1234567890ABCDEF_u64;
1767 println!("M_u64 =\t{:#018X}", message);
1768
1769 let mut a_des = DES::new_with_key_u64(key);
1770 let cipher = a_des.encrypt_u64(message);
1771 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1772 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1773 println!();
1774
1775 // Expanded case for 128 rounds
1776 let key = 0x_1234567890ABCDEF_u64;
1777 println!("K =\t{:#018X}", key);
1778
1779 let message = 0x_1234567890ABCDEF_u64;
1780 println!("M_u64 =\t{:#018X}", message);
1781
1782 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1783 let cipher = b_des.encrypt_u64(message);
1784 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1785 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1786 println!();
1787
1788 // Expanded case for 0 rounds which means that key is meaningless
1789 let key1 = 0x_1234567890ABCDEF_u64;
1790 let key2 = 0_u64;
1791 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1792 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1793 println!("K1 =\t{:#016x}", key1);
1794
1795 let message = 0x_1234567890ABCDEF_u64;
1796 println!("M_u64 =\t{:#018X}", message);
1797
1798 let cipher1 = c_des.encrypt_u64(message);
1799 let cipher2 = d_des.encrypt_u64(message);
1800 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1801 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1802
1803 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1804 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1805 assert_eq!(cipher1, cipher2);
1806 println!("-------------------------------");
1807}
1808
1809fn des_decrypt_u64()
1810{
1811 println!("des_decrypt_u64");
1812 use cryptocol::symmetric::{ DES, DES_Expanded };
1813
1814 // Normal case
1815 let key = 0x_1234567890ABCDEF_u64;
1816 println!("K =\t{:#018X}", key);
1817
1818 let message = 0x_1234567890ABCDEF_u64;
1819 println!("M_u64 =\t{:#018X}", message);
1820
1821 let mut a_des = DES::new_with_key_u64(key);
1822 let cipher = a_des.encrypt_u64(message);
1823 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1824 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1825
1826 let recovered = a_des.decrypt_u64(cipher);
1827 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1828 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1829 assert_eq!(recovered, message);
1830 println!();
1831
1832 // Expanded case for 128 rounds
1833 let key = 0x_1234567890ABCDEF_u64;
1834 println!("K =\t{:#018X}", key);
1835
1836 let message = 0x_1234567890ABCDEF_u64;
1837 println!("M_u64 =\t{:#018X}", message);
1838
1839 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1840 let cipher = b_des.encrypt_u64(message);
1841 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1842 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1843
1844 let recovered = b_des.decrypt_u64(cipher);
1845 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1846 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1847 assert_eq!(recovered, message);
1848 println!();
1849
1850 // Expanded case for 0 rounds which means that key is meaningless
1851 let key1 = 0x_1234567890ABCDEF_u64;
1852 let key2 = 0_u64;
1853 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1854 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1855 println!("K =\t{:#018X}", key);
1856
1857 let message = 0x_1234567890ABCDEF_u64;
1858 println!("M_u64 =\t{:#018X}", message);
1859
1860 let cipher1 = c_des.encrypt_u64(message);
1861 let cipher2 = d_des.encrypt_u64(message);
1862 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1863 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1864
1865 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1866 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1867 assert_eq!(cipher1, cipher2);
1868
1869 let recovered1 = c_des.decrypt_u64(cipher1);
1870 let recovered2 = d_des.decrypt_u64(cipher2);
1871 println!("B1_u64 (0 rounds) =\t{:#018X}", recovered1);
1872 println!("B2_u64 (0 rounds) =\t{:#018X}", recovered2);
1873 assert_eq!(recovered1, 0x_1234567890ABCDEF_u64);
1874 assert_eq!(recovered1, message);
1875 assert_eq!(recovered2, 0x_1234567890ABCDEF_u64);
1876 assert_eq!(recovered2, message);
1877 assert_eq!(recovered1, recovered2);
1878 println!("-------------------------------");
1879}
1880
1881/*
1882fn des__encrypt()
1883{
1884 println!("des__encrypt");
1885 use cryptocol::symmetric::{ DES, DES_Expanded };
1886
1887 // Normal case
1888 let key = 0x_1234567890ABCDEF_u64;
1889 println!("K =\t{:#018X}", key);
1890
1891 let message = 0x_1234567890ABCDEF_u64;
1892 println!("M_u64 =\t{:#018X}", message);
1893
1894 let mut a_des = DES::new_with_key_u64(key);
1895 let cipher = a_des._encrypt(message);
1896 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1897 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1898 println!();
1899
1900 // Expanded case for 128 rounds
1901 let key = 0x_1234567890ABCDEF_u64;
1902 println!("K =\t{:#018X}", key);
1903
1904 let message = 0x_1234567890ABCDEF_u64;
1905 println!("M_u64 =\t{:#018X}", message);
1906
1907 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1908 let cipher = b_des._encrypt(message);
1909 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1910 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1911 println!();
1912
1913 // Expanded case for 0 rounds which means that key is meaningless
1914 let key1 = 0x_1234567890ABCDEF_u64;
1915 let key2 = 0_u64;
1916 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1917 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1918 println!("K1 =\t{:#016x}", key1);
1919
1920 let message = 0x_1234567890ABCDEF_u64;
1921 println!("M_u64 =\t{:#018X}", message);
1922
1923 let cipher1 = c_des._encrypt(message);
1924 let cipher2 = d_des._encrypt(message);
1925 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1926 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1927
1928 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1929 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1930 assert_eq!(cipher1, cipher2);
1931 println!("-------------------------------");
1932}
1933
1934fn des__decrypt()
1935{
1936 println!("des__decrypt");
1937 use cryptocol::symmetric::{ DES, DES_Expanded };
1938
1939 // Normal case
1940 let key = 0x_1234567890ABCDEF_u64;
1941 println!("K =\t{:#018X}", key);
1942
1943 let message = 0x_1234567890ABCDEF_u64;
1944 println!("M_u64 =\t{:#018X}", message);
1945
1946 let mut a_des = DES::new_with_key_u64(key);
1947 let cipher = a_des._encrypt(message);
1948 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1949 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1950
1951 let recovered = a_des._decrypt(cipher);
1952 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1953 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1954 assert_eq!(recovered, message);
1955 println!();
1956
1957 // Expanded case for 128 rounds
1958 let key = 0x_1234567890ABCDEF_u64;
1959 println!("K =\t{:#018X}", key);
1960
1961 let message = 0x_1234567890ABCDEF_u64;
1962 println!("M_u64 =\t{:#018X}", message);
1963
1964 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1965 let cipher = b_des._encrypt(message);
1966 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1967 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1968
1969 let recovered = b_des._decrypt(cipher);
1970 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1971 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1972 assert_eq!(recovered, message);
1973 println!();
1974
1975 // Expanded case for 0 rounds which means that key is meaningless
1976 let key1 = 0x_1234567890ABCDEF_u64;
1977 let key2 = 0_u64;
1978 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1979 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1980 println!("K =\t{:#018X}", key);
1981
1982 let message = 0x_1234567890ABCDEF_u64;
1983 println!("M_u64 =\t{:#018X}", message);
1984
1985 let cipher1 = c_des._encrypt(message);
1986 let cipher2 = d_des._encrypt(message);
1987 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1988 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1989
1990 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1991 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1992 assert_eq!(cipher1, cipher2);
1993
1994 let recovered1 = c_des._decrypt(cipher1);
1995 let recovered2 = d_des._decrypt(cipher2);
1996 println!("B1_u64 (0 rounds) =\t{:#018X}", recovered1);
1997 println!("B2_u64 (0 rounds) =\t{:#018X}", recovered2);
1998 assert_eq!(recovered1, 0x_1234567890ABCDEF_u64);
1999 assert_eq!(recovered1, message);
2000 assert_eq!(recovered2, 0x_1234567890ABCDEF_u64);
2001 assert_eq!(recovered2, message);
2002 assert_eq!(recovered1, recovered2);
2003 println!("-------------------------------");
2004}
2005*/
2006fn des_encrypt_array_u64()
2007{
2008 println!("des_encrypt_array_u64");
2009 use cryptocol::symmetric::{ DES, DES_Expanded };
2010
2011 // Normal case
2012 let key = 0x_1234567890ABCDEF_u64;
2013 println!("K =\t{:#018X}", key);
2014
2015 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2016 print!("M =\t");
2017 for m in message
2018 { print!("{:#018X} ", m); }
2019 println!();
2020 let mut a_des = DES::new_with_key_u64(key);
2021
2022 let mut cipher = [0; 3];
2023 a_des.encrypt_array_u64(&message, &mut cipher);
2024 print!("C (16 rounds) =\t");
2025 for c in cipher
2026 { print!("{:#018X} ", c); }
2027 println!();
2028 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2029 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2030 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2031 println!();
2032
2033 // Expanded case for 128 rounds
2034 let key = 0x_1234567890ABCDEF_u64;
2035 println!("K =\t{:#018X}", key);
2036
2037 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2038 print!("M =\t");
2039 for m in message
2040 { print!("{:#018X} ", m); }
2041 println!();
2042 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2043
2044 let mut cipher = [0; 3];
2045 b_des.encrypt_array_u64(&message, &mut cipher);
2046 print!("C (128 rounds) =\t");
2047 for c in cipher
2048 { print!("{:#018X} ", c); }
2049 println!();
2050 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2051 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2052 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2053 println!();
2054
2055
2056 // Expanded case for 0 rounds which means that key is meaningless
2057 let key1 = 0x_1234567890ABCDEF_u64;
2058 let key2 = 0_u64;
2059 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2060 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2061 println!("K =\t{:#018X}", key);
2062
2063 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2064 print!("M =\t");
2065 for m in message
2066 { print!("{:#018X} ", m); }
2067 println!();
2068
2069 let mut cipher1 = [0; 3];
2070 let mut cipher2 = [0; 3];
2071 c_des.encrypt_array_u64(&message, &mut cipher1);
2072 d_des.encrypt_array_u64(&message, &mut cipher2);
2073 print!("C (0 rounds) =\t");
2074 for c in cipher1
2075 { print!("{:#018X} ", c); }
2076 println!();
2077 print!("D (0 rounds) =\t");
2078 for c in cipher2
2079 { print!("{:#018X} ", c); }
2080 println!();
2081 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2082 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2083 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2084 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2085 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2086 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2087 assert_eq!(cipher1[0], cipher2[0]);
2088 assert_eq!(cipher1[1], cipher2[1]);
2089 assert_eq!(cipher1[2], cipher2[2]);
2090 println!("-------------------------------");
2091}
2092
2093fn des_decrypt_array_u64()
2094{
2095 println!("des_decrypt_array_u64");
2096 use cryptocol::symmetric::{ DES, DES_Expanded };
2097
2098 // Normal case
2099 let key = 0x_1234567890ABCDEF_u64;
2100 println!("K =\t{:#018X}", key);
2101
2102 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2103 print!("M =\t");
2104 for m in message
2105 { print!("{:#018X} ", m); }
2106 println!();
2107 let mut a_des = DES::new_with_key_u64(key);
2108
2109 let mut cipher = [0; 3];
2110 a_des.encrypt_array_u64(&message, &mut cipher);
2111 print!("C (16 rounds) =\t");
2112 for c in cipher
2113 { print!("{:#018X} ", c); }
2114 println!();
2115 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2116 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2117 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2118
2119 let mut recovered = [0; 3];
2120 a_des.decrypt_array_u64(&cipher, &mut recovered);
2121 print!("B (16 rounds) =\t");
2122 for r in recovered
2123 { print!("{:#018X} ", r); }
2124 println!();
2125 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2126 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2127 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2128 println!();
2129
2130 // Expanded case for 128 rounds
2131 let key = 0x_1234567890ABCDEF_u64;
2132 println!("K =\t{:#018X}", key);
2133
2134 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2135 print!("M =\t");
2136 for m in message
2137 { print!("{:#018X} ", m); }
2138 println!();
2139 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2140
2141 let mut cipher = [0; 3];
2142 b_des.encrypt_array_u64(&message, &mut cipher);
2143 print!("C (128 rounds) =\t");
2144 for c in cipher
2145 { print!("{:#018X} ", c); }
2146 println!();
2147 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2148 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2149 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2150
2151 let mut recovered = [0; 3];
2152 b_des.decrypt_array_u64(&cipher, &mut recovered);
2153 print!("B (128 rounds) =\t");
2154 for r in recovered
2155 { print!("{:#018X} ", r); }
2156 println!();
2157 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2158 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2159 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2160
2161 // Expanded case for 0 rounds which means that key is meaningless
2162 let key1 = 0x_1234567890ABCDEF_u64;
2163 let key2 = 0_u64;
2164 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2165 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2166 println!("K =\t{:#018X}", key);
2167
2168 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2169 print!("M =\t");
2170 for m in message
2171 { print!("{:#018X} ", m); }
2172 println!();
2173
2174 let mut cipher1 = [0; 3];
2175 let mut cipher2 = [0; 3];
2176 c_des.encrypt_array_u64(&message, &mut cipher1);
2177 d_des.encrypt_array_u64(&message, &mut cipher2);
2178 print!("C (0 rounds) =\t");
2179 for c in cipher1
2180 { print!("{:#018X} ", c); }
2181 println!();
2182 print!("D (0 rounds) =\t");
2183 for c in cipher2
2184 { print!("{:#018X} ", c); }
2185 println!();
2186 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2187 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2188 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2189 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2190 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2191 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2192 assert_eq!(cipher1[0], cipher2[0]);
2193 assert_eq!(cipher1[1], cipher2[1]);
2194 assert_eq!(cipher1[2], cipher2[2]);
2195
2196 let mut recovered1 = [0; 3];
2197 let mut recovered2 = [0; 3];
2198 c_des.decrypt_array_u64(&cipher1, &mut recovered1);
2199 d_des.decrypt_array_u64(&cipher2, &mut recovered2);
2200 print!("B1 (0 rounds) =\t");
2201 for r in recovered1
2202 { print!("{:#018X} ", r); }
2203 println!();
2204 print!("B2 (0 rounds) =\t");
2205 for r in recovered2
2206 { print!("{:#018X} ", r); }
2207 println!();
2208 assert_eq!(recovered1[0], 0x_1234567890ABCDEF_u64);
2209 assert_eq!(recovered1[1], 0x_EFCDAB9078563412_u64);
2210 assert_eq!(recovered1[2], 0x_FEDCBA0987654321_u64);
2211 assert_eq!(recovered2[0], 0x_1234567890ABCDEF_u64);
2212 assert_eq!(recovered2[1], 0x_EFCDAB9078563412_u64);
2213 assert_eq!(recovered2[2], 0x_FEDCBA0987654321_u64);
2214 assert_eq!(recovered1[0], recovered2[0]);
2215 assert_eq!(recovered1[1], recovered2[1]);
2216 assert_eq!(recovered1[2], recovered2[2]);
2217 println!("-------------------------------");
2218}
2219
2220fn des_is_successful()
2221{
2222 println!("des_is_successful");
2223 use std::io::Write;
2224 use std::fmt::Write as _;
2225 use cryptocol::symmetric::DES;
2226
2227 {
2228 use cryptocol::symmetric::ECB_PKCS7;
2229
2230 // Successful case for the message of 0 bytes
2231 let key = 0x_1234567890ABCDEF_u64;
2232 println!("K =\t{:#018X}", key);
2233 let mut a_des = DES::new_with_key_u64(key);
2234 let message = "";
2235 println!("M =\t{}", message);
2236 let mut cipher = [0_u8; 8];
2237 let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
2238 println!("The length of ciphertext = {}", len);
2239 assert_eq!(len, 8);
2240 let success = a_des.is_successful();
2241 assert_eq!(success, true);
2242 print!("C =\t");
2243 for c in cipher.clone()
2244 { print!("{:02X} ", c); }
2245 println!();
2246 let mut txt = String::new();
2247 for c in cipher.clone()
2248 { write!(txt, "{:02X} ", c); }
2249 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2250 println!();
2251
2252 // Successful case for the original message of 0 bytes
2253 let key = 0x_1234567890ABCDEF_u64;
2254 println!("K =\t{:#018X}", key);
2255 let mut a_des = DES::new_with_key_u64(key);
2256
2257 let cipher = [0x41u8, 0x7F, 0x89, 0x79, 0x08, 0xCD, 0xA1, 0x4C];
2258 print!("C =\t");
2259 for c in cipher.clone()
2260 { print!("{:02X} ", c); }
2261 println!();
2262 let mut recovered = [0u8; 8];
2263 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
2264 println!("The length of plaintext = {}", len);
2265 assert_eq!(len, 0);
2266 let success = a_des.is_successful();
2267 assert_eq!(success, true);
2268 print!("Ba =\t");
2269 for b in recovered.clone()
2270 { print!("{:02X} ", b); }
2271 println!();
2272 let mut txt = String::new();
2273 for c in recovered.clone()
2274 { write!(txt, "{:02X} ", c); }
2275 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2276
2277 let mut converted = String::new();
2278 unsafe { converted.as_mut_vec() }.write(&recovered);
2279 unsafe { converted.as_mut_vec() }.truncate(len as usize);
2280 println!("Bb =\t{}", converted);
2281 assert_eq!(converted, "");
2282 assert_eq!(converted, message);
2283 println!();
2284 }
2285
2286 {
2287 use cryptocol::symmetric::CBC_ISO;
2288
2289 // Failure case for the message of 0 bytes
2290 let iv = 0x_FEDCBA0987654321_u64;
2291 println!("IV = {}", iv);
2292 let key = 0x_1234567890ABCDEF_u64;
2293 println!("K =\t{:#018X}", key);
2294 let mut a_des = DES::new_with_key_u64(key);
2295 let message = "";
2296 println!("M =\t{}", message);
2297 let mut cipher = [0_u8; 4];
2298 let len = a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
2299 println!("The length of ciphertext = {}", len);
2300 assert_eq!(len, 0);
2301 let success = a_des.is_successful();
2302 assert_eq!(success, false);
2303 print!("C =\t");
2304 for c in cipher.clone()
2305 { print!("{:02X} ", c); }
2306 println!();
2307 let mut txt = String::new();
2308 for c in cipher.clone()
2309 { write!(txt, "{:02X} ", c); }
2310 assert_eq!(txt, "00 00 00 00 ");
2311 println!();
2312
2313 // Failed case for decryption
2314 let iv = 0x_FEDCBA0987654321_u64;
2315 println!("IV = {}", iv);
2316 let key = 0x_1234567890ABCDEF_u64;
2317 println!("K =\t{:#018X}", key);
2318 let mut a_des = DES::new_with_key_u64(key);
2319
2320 let cipher = [0u8; 4];
2321 print!("C =\t");
2322 for c in cipher.clone()
2323 { print!("{:02X} ", c); }
2324 println!();
2325 let mut recovered = [0u8; 8];
2326 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
2327 println!("The length of plaintext = {}", len);
2328 assert_eq!(len, 0);
2329 let success = a_des.is_successful();
2330 assert_eq!(success, false);
2331 }
2332 println!("-------------------------------");
2333}
2334
2335fn des_is_failed()
2336{
2337 println!("des_is_failed");
2338 use std::io::Write;
2339 use std::fmt::Write as _;
2340 use cryptocol::symmetric::DES;
2341
2342 {
2343 use cryptocol::symmetric::ECB_PKCS7;
2344
2345 // Successful case for the message of 0 bytes
2346 let key = 0x_1234567890ABCDEF_u64;
2347 println!("K =\t{:#018X}", key);
2348 let mut a_des = DES::new_with_key_u64(key);
2349 let message = "";
2350 println!("M =\t{}", message);
2351 let mut cipher = [0_u8; 8];
2352 let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
2353 println!("The length of ciphertext = {}", len);
2354 assert_eq!(len, 8);
2355 let failure = a_des.is_failed();
2356 assert_eq!(failure, false);
2357 print!("C =\t");
2358 for c in cipher.clone()
2359 { print!("{:02X} ", c); }
2360 println!();
2361 let mut txt = String::new();
2362 for c in cipher.clone()
2363 { write!(txt, "{:02X} ", c); }
2364 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2365 println!();
2366
2367 // Successful case for the original message of 0 bytes
2368 let key = 0x_1234567890ABCDEF_u64;
2369 println!("K =\t{:#018X}", key);
2370 let mut a_des = DES::new_with_key_u64(key);
2371
2372 let cipher = [0x41u8, 0x7F, 0x89, 0x79, 0x08, 0xCD, 0xA1, 0x4C];
2373 print!("C =\t");
2374 for c in cipher.clone()
2375 { print!("{:02X} ", c); }
2376 println!();
2377 let mut recovered = [0u8; 8];
2378 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
2379 println!("The length of plaintext = {}", len);
2380 assert_eq!(len, 0);
2381 let failure = a_des.is_failed();
2382 assert_eq!(failure, false);
2383 print!("Ba =\t");
2384 for b in recovered.clone()
2385 { print!("{:02X} ", b); }
2386 println!();
2387 let mut txt = String::new();
2388 for c in recovered.clone()
2389 { write!(txt, "{:02X} ", c); }
2390 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2391
2392 let mut converted = String::new();
2393 unsafe { converted.as_mut_vec() }.write(&recovered);
2394 unsafe { converted.as_mut_vec() }.truncate(len as usize);
2395 println!("Bb =\t{}", converted);
2396 assert_eq!(converted, "");
2397 assert_eq!(converted, message);
2398 println!();
2399 }
2400
2401 {
2402 use cryptocol::symmetric::CBC_ISO;
2403
2404 // Failure case for the message of 0 bytes
2405 let iv = 0x_FEDCBA0987654321_u64;
2406 println!("IV = {}", iv);
2407 let key = 0x_1234567890ABCDEF_u64;
2408 println!("K =\t{:#018X}", key);
2409 let mut a_des = DES::new_with_key_u64(key);
2410 let message = "";
2411 println!("M =\t{}", message);
2412 let mut cipher = [0_u8; 4];
2413 let len = a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
2414 println!("The length of ciphertext = {}", len);
2415 assert_eq!(len, 0);
2416 let failure = a_des.is_failed();
2417 assert_eq!(failure, true);
2418 print!("C =\t");
2419 for c in cipher.clone()
2420 { print!("{:02X} ", c); }
2421 println!();
2422 let mut txt = String::new();
2423 for c in cipher.clone()
2424 { write!(txt, "{:02X} ", c); }
2425 assert_eq!(txt, "00 00 00 00 ");
2426 println!();
2427
2428 // Failed case for decryption
2429 let iv = 0x_FEDCBA0987654321_u64;
2430 println!("IV = {}", iv);
2431 let key = 0x_1234567890ABCDEF_u64;
2432 println!("K =\t{:#018X}", key);
2433 let mut a_des = DES::new_with_key_u64(key);
2434
2435 let cipher = [0u8; 4];
2436 print!("C =\t");
2437 for c in cipher.clone()
2438 { print!("{:02X} ", c); }
2439 println!();
2440 let mut recovered = [0u8; 8];
2441 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
2442 println!("The length of plaintext = {}", len);
2443 assert_eq!(len, 0);
2444 let failure = a_des.is_failed();
2445 assert_eq!(failure, true);
2446 }
2447 println!("-------------------------------");
2448}
2449
2450// fn des_set_successful()
2451// {
2452// println!("des_set_successful");
2453// use cryptocol::symmetric::DES;
2454// let mut a_des = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
2455// assert_eq!(a_des.is_successful(), false);
2456
2457// a_des.set_successful();
2458// assert_eq!(a_des.is_successful(), true);
2459// println!("-------------------------------");
2460// }
2461
2462// fn des_set_failed()
2463// {
2464// println!("des_set_failed");
2465// use cryptocol::symmetric::DES;
2466// let mut a_des = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
2467// a_des.encrypt_u64(0x1234567890ABCDEF_u64);
2468// assert_eq!(a_des.is_failed(), false);
2469
2470// a_des.set_failed();
2471// assert_eq!(a_des.is_failed(), true);
2472// println!("-------------------------------");
2473// }
2474
2475fn des_has_weak_key()
2476{
2477 println!("des_has_weak_key");
2478 use cryptocol::symmetric::DES;
2479
2480 let key = 0x_1234567890ABCDEF_u64;
2481 let mut a_des = DES::new_with_key_u64(key);
2482 let weak_key = a_des.has_weak_key();
2483 println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
2484 assert_eq!(weak_key, false);
2485
2486 let key = 0x_0000000000000000_u64;
2487 a_des.set_key_u64(key);
2488 let weak_key = a_des.has_weak_key();
2489 println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
2490 assert_eq!(weak_key, true);
2491 println!("-------------------------------");
2492}Sourcepub fn turn_inverse(&mut self)
pub fn turn_inverse(&mut self)
Flips its role in BigCryptor64.
§Features
- You won’t use this method unless you use BigCryptor64 or NDES for such as Triple DES.
- Even if you are writing codes in the context of using BigCryptor64 or NDES, you will hardly use this method because it is high chance that you will have constructed components with the methods, encryptor_with_key, encryptor_with_key_u64, decryptor_with_key, and decryptor_with_key_u64.
- If it is constructed as encryptor for BigCryptor64 or NDES, it will be changed into decryptor.
- If it is constructed as decryptor for BigCryptor64 or NDES, it will be changed into encryptor.
§Example 1
use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
= [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
keys[1].turn_inverse();
let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
1601fn des_turn_inverse()
1602{
1603 println!("des_turn_inverse");
1604 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1605
1606 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1607 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1608 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1609 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1610 keys[1].turn_inverse();
1611
1612 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1613 let plaintext = 0x_1234567890ABCDEF_u64;
1614 let ciphertext = tdes.encrypt_u64(plaintext);
1615
1616 println!("Plaintext:\t\t{:#018X}", plaintext);
1617 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1618 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1619
1620 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1621 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1622 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1623 assert_eq!(cipher_cipher_text, plaintext);
1624 println!();
1625
1626
1627 // Operators
1628 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1629 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1630 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1631 des2.turn_inverse();
1632
1633 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1634 let plaintext = 0x_1234567890ABCDEF_u64;
1635 let ciphertext = tdes.encrypt_u64(plaintext);
1636
1637 println!("Plaintext:\t\t{:#018X}", plaintext);
1638 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1639 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1640
1641 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1642 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1643 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1644 assert_eq!(cipher_cipher_text, plaintext);
1645 println!("-------------------------------");
1646}Sourcepub fn turn_encryptor(&mut self)
pub fn turn_encryptor(&mut self)
Changes its role in BigCryptor64 or NDES to encryptor.
§Features
- You won’t use this method unless you use BigCryptor64 or NDES for such as Triple DES.
- Even if you are writing codes in the context of using BigCryptor64 or NDES, you will hardly use this method because it is high chance that you will have constructed components with the methods, encryptor_with_key, encryptor_with_key_u64, decryptor_with_key, and decryptor_with_key_u64.
- If it is constructed as encryptor for BigCryptor64 or NDES, it will not be changed at all.
- If it is constructed as decryptor for BigCryptor64 or NDES, it will be changed into encryptor.
§Example 1
use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
= [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
keys[0].turn_encryptor();
let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
1648fn des_turn_encryptor()
1649{
1650 println!("des_turn_encryptor");
1651 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1652
1653 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1654 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1655 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1656 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1657 keys[0].turn_encryptor();
1658
1659 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1660 let plaintext = 0x_1234567890ABCDEF_u64;
1661 let ciphertext = tdes.encrypt_u64(plaintext);
1662
1663 println!("Plaintext:\t\t{:#018X}", plaintext);
1664 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1665 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1666
1667 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1668 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1669 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1670 assert_eq!(cipher_cipher_text, plaintext);
1671 println!();
1672
1673
1674 // Operators
1675 let mut des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1676 let des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1677 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1678 des1.turn_encryptor();
1679
1680 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1681 let plaintext = 0x_1234567890ABCDEF_u64;
1682 let ciphertext = tdes.encrypt_u64(plaintext);
1683
1684 println!("Plaintext:\t\t{:#018X}", plaintext);
1685 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1686 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1687
1688 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1689 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1690 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1691 assert_eq!(cipher_cipher_text, plaintext);
1692 println!("-------------------------------");
1693}Sourcepub fn turn_decryptor(&mut self)
pub fn turn_decryptor(&mut self)
Changes its role in BigCryptor64 or NDES to decryptor.
§Features
- You won’t use this method unless you use BigCryptor64 or NDES for such as Triple DES.
- Even if you are writing codes in the context of using BigCryptor64 or NDES, you will hardly use this method because it is high chance that you will have constructed components with the methods, encryptor_with_key, encryptor_with_key_u64, decryptor_with_key, and decryptor_with_key_u64.
- If it is constructed as encryptor for BigCryptor64 or NDES, it will be changed into decryptor.
- If it is constructed as decryptor for BigCryptor64 or NDES, it will not be changed at all.
§Example 1
use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
= [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
keys[1].turn_decryptor();
let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
let plaintext = 0x_1234567890ABCDEF_u64;
let ciphertext = tdes.encrypt_u64(plaintext);
println!("Plaintext:\t\t{:#018X}", plaintext);
println!("Ciphertext:\t\t{:#018X}", ciphertext);
assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
assert_eq!(cipher_cipher_text, plaintext);§For more examples,
click here
Examples found in repository?
1695fn des_turn_decryptor()
1696{
1697 println!("des_turn_decryptor");
1698 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1699
1700 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1701 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1702 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1703 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1704 keys[1].turn_decryptor();
1705
1706 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1707 let plaintext = 0x_1234567890ABCDEF_u64;
1708 let ciphertext = tdes.encrypt_u64(plaintext);
1709
1710 println!("Plaintext:\t\t{:#018X}", plaintext);
1711 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1712 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1713
1714 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1715 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1716 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1717 assert_eq!(cipher_cipher_text, plaintext);
1718 println!();
1719
1720
1721 // Operators
1722 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1723 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1724 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1725 des2.turn_decryptor();
1726
1727 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1728 let plaintext = 0x_1234567890ABCDEF_u64;
1729 let ciphertext = tdes.encrypt_u64(plaintext);
1730
1731 println!("Plaintext:\t\t{:#018X}", plaintext);
1732 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1733 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1734
1735 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1736 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1737 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1738 assert_eq!(cipher_cipher_text, plaintext);
1739 println!("-------------------------------");
1740}Sourcepub fn encrypt_u64(&mut self, message: u64) -> u64
pub fn encrypt_u64(&mut self, message: u64) -> u64
Encrypts a 64-bit data.
§Arguments
message is of u64-type and the plaintext to be encrypted.
§Output
This method returns the encrypted data of u64-type from message.
§Counterpart Methods
For each trait
ECB_PKCS7,
ECB_ISO,
CBC_PKCS7,
CBC_ISO,
PCBC_PKCS7,
PCBC_ISO.
CFB,
OFB, and
CTR,
there are provided useful counterpart methods:
encrypt(), encrypt_into_vec(), encrypt_into_array(),
encrypt_str(), encrypt_str_into_vec(), encrypt_str_into_array(),
encrypt_string(), encrypt_string_into_vec(), encrypt_string_into_array(),
encrypt_vec(), encrypt_vec_into_vec(), encrypt_vec_into_array(),
encrypt_array(), encrypt_array_into_vec(), and encrypt_array_into_array().
§Example 1 for Normal case
use cryptocol::symmetric::DES;
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#018X}", key);
let message = 0x_1234567890ABCDEF_u64;
println!("M_u64 =\t{:#018X}", message);
let mut a_des = DES::new_with_key_u64(key);
let cipher = a_des.encrypt_u64(message);
println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
assert_eq!(cipher, 0x_1BC4896735BBE206_u64);§For more examples,
click here
Examples found in repository?
145fn des_new()
146{
147 println!("des_new()");
148 use cryptocol::symmetric::DES;
149
150 let mut des = DES::new(); // The default key is 0x0000000000000000 which is a weak key.
151 let plaintext = 0x1234567890ABCDEF_u64;
152 let ciphertext = des.encrypt_u64(plaintext);
153
154 println!("Plaintext:\t\t{:#018X}", plaintext);
155 println!("Ciphertext:\t\t{:#018X}", ciphertext);
156 assert_eq!(ciphertext, 0x1E32B46B44C69201_u64);
157
158 let cipher_cipher_text = des.encrypt_u64(ciphertext);
159 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
160 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
161 assert_eq!(cipher_cipher_text, plaintext); // So, you can't use the default key!!!
162
163 #[cfg(test)]
164 des_compile_fail_new();
165 println!("-------------------------------");
166}
167
168#[test]
169fn des_compile_fail_new()
170{
171 use cryptocol::symmetric::DES;
172 let des = DES::new();
173 // It cannot be compiled!
174 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
175}
176
177fn des_new_with_key()
178{
179 println!("des_new_with_key()");
180 use cryptocol::symmetric::DES;
181
182 // Normal case
183 let mut des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
184 let plaintext = 0x1234567890ABCDEF_u64;
185 let ciphertext = des.encrypt_u64(plaintext);
186
187 println!("Plaintext:\t\t{:#018X}", plaintext);
188 println!("Ciphertext:\t\t{:#018X}", ciphertext);
189 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
190
191 let cipher_cipher_text = des.encrypt_u64(ciphertext);
192 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
193 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
194 assert_ne!(cipher_cipher_text, plaintext);
195 println!();
196
197 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
198 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
199 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
200 let mut des1 = DES::new_with_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
201 let mut des2 = DES::new_with_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
202
203 let plaintext = 0x1234567890ABCDEF_u64;
204 let ciphertext1 = des1.encrypt_u64(plaintext);
205 let ciphertext2 = des2.encrypt_u64(plaintext);
206
207 println!("Plaintext:\t\t{:#018X}", plaintext);
208 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
209 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
210 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
211 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
212 assert_eq!(ciphertext1, ciphertext2);
213
214 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
215 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
216 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
217 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
218 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
219 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
220 assert_eq!(cipher_cipher_text1, plaintext);
221 assert_eq!(cipher_cipher_text2, plaintext);
222 println!();
223 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
224 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
225
226
227 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
228 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
229 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
230 let mut des1 = DES::new_with_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
231 let mut des2 = DES::new_with_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
232 let plaintext = 0x1234567890ABCDEF_u64;
233 let ciphertext1 = des1.encrypt_u64(plaintext);
234 let ciphertext2 = des2.encrypt_u64(plaintext);
235
236 println!("Plaintext:\t\t{:#018X}", plaintext);
237 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
238 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
239 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
240 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
241 assert_eq!(ciphertext1, ciphertext2);
242
243 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
244 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
245 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
246 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
247 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
248 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
249 assert_eq!(cipher_cipher_text1, plaintext);
250 assert_eq!(cipher_cipher_text2, plaintext);
251 println!();
252 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
253 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
254
255 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
256 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1] is the same key as the key
257 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
258 let mut des1 = DES::new_with_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
259 let mut des2 = DES::new_with_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
260 let plaintext = 0x1234567890ABCDEF_u64;
261 let ciphertext1 = des1.encrypt_u64(plaintext);
262 let ciphertext2 = des2.encrypt_u64(plaintext);
263
264 println!("Plaintext:\t\t{:#018X}", plaintext);
265 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
266 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
267 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
268 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
269 assert_eq!(ciphertext1, ciphertext2);
270
271 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
272 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
273 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
274 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
275 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
276 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
277 assert_eq!(cipher_cipher_text1, plaintext);
278 assert_eq!(cipher_cipher_text2, plaintext);
279 println!();
280 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
281 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
282
283 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
284 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
285 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
286 let mut des1 = DES::new_with_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
287 let mut des2 = DES::new_with_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
288 let plaintext = 0x1234567890ABCDEF_u64;
289 let ciphertext1 = des1.encrypt_u64(plaintext);
290 let ciphertext2 = des2.encrypt_u64(plaintext);
291
292 println!("Plaintext:\t\t{:#018X}", plaintext);
293 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
294 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
295 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
296 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
297 assert_eq!(ciphertext1, ciphertext2);
298
299 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
300 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
301 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
302 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
303 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
304 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
305 assert_eq!(cipher_cipher_text1, plaintext);
306 assert_eq!(cipher_cipher_text2, plaintext);
307 println!();
308 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
309 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
310
311 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
312 let mut des1 = DES::new_with_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
313 let mut des2 = DES::new_with_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
314
315 let plaintext = 0x1234567890ABCDEF_u64;
316 let ciphertext = des1.encrypt_u64(plaintext);
317 println!("Plaintext:\t\t{:#018X}", plaintext);
318 println!("Ciphertext:\t\t{:#018X}", ciphertext);
319 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
320
321 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
322 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
323 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
324 assert_eq!(cipher_cipher_text, plaintext);
325
326 let ciphertext = des2.encrypt_u64(plaintext);
327 println!("Plaintext:\t\t{:#018X}", plaintext);
328 println!("Ciphertext:\t\t{:#018X}", ciphertext);
329 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
330
331 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
332 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
333 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
334 assert_eq!(cipher_cipher_text, plaintext);
335 println!();
336 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
337
338 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
339 let mut des1 = DES::new_with_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
340 let mut des2 = DES::new_with_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
341
342 let plaintext = 0x1234567890ABCDEF_u64;
343 let ciphertext = des1.encrypt_u64(plaintext);
344 println!("Plaintext:\t\t{:#018X}", plaintext);
345 println!("Ciphertext:\t\t{:#018X}", ciphertext);
346 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
347
348 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
349 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
350 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
351 assert_eq!(cipher_cipher_text, plaintext);
352
353 let ciphertext = des2.encrypt_u64(plaintext);
354 println!("Plaintext:\t\t{:#018X}", plaintext);
355 println!("Ciphertext:\t\t{:#018X}", ciphertext);
356 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
357
358 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
359 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
360 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
361 assert_eq!(cipher_cipher_text, plaintext);
362 println!();
363 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
364
365 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
366 let mut des1 = DES::new_with_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
367 let mut des2 = DES::new_with_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
368
369 let plaintext = 0x1234567890ABCDEF_u64;
370 let ciphertext = des1.encrypt_u64(plaintext);
371 println!("Plaintext:\t\t{:#018X}", plaintext);
372 println!("Ciphertext:\t\t{:#018X}", ciphertext);
373 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
374
375 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
376 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
377 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
378 assert_eq!(cipher_cipher_text, plaintext);
379
380 let ciphertext = des2.encrypt_u64(plaintext);
381 println!("Plaintext:\t\t{:#018X}", plaintext);
382 println!("Ciphertext:\t\t{:#018X}", ciphertext);
383 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
384
385 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
386 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
387 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
388 assert_eq!(cipher_cipher_text, plaintext);
389 println!();
390 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
391
392 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
393 let mut des1 = DES::new_with_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
394 let mut des2 = DES::new_with_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
395
396 let plaintext = 0x1234567890ABCDEF_u64;
397 let ciphertext = des1.encrypt_u64(plaintext);
398 println!("Plaintext:\t\t{:#018X}", plaintext);
399 println!("Ciphertext:\t\t{:#018X}", ciphertext);
400 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
401
402 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
403 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
404 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
405 assert_eq!(cipher_cipher_text, plaintext);
406
407 let ciphertext = des2.encrypt_u64(plaintext);
408 println!("Plaintext:\t\t{:#018X}", plaintext);
409 println!("Ciphertext:\t\t{:#018X}", ciphertext);
410 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
411
412 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
413 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
414 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
415 assert_eq!(cipher_cipher_text, plaintext);
416 println!();
417 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
418
419 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
420 let mut des1 = DES::new_with_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
421 let mut des2 = DES::new_with_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
422
423 let plaintext = 0x1234567890ABCDEF_u64;
424 let ciphertext = des1.encrypt_u64(plaintext);
425 println!("Plaintext:\t\t{:#018X}", plaintext);
426 println!("Ciphertext:\t\t{:#018X}", ciphertext);
427 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
428
429 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
430 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
431 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
432 assert_eq!(cipher_cipher_text, plaintext);
433
434 let ciphertext = des2.encrypt_u64(plaintext);
435 println!("Plaintext:\t\t{:#018X}", plaintext);
436 println!("Ciphertext:\t\t{:#018X}", ciphertext);
437 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
438
439 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
440 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
441 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
442 assert_eq!(cipher_cipher_text, plaintext);
443 println!();
444 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
445
446 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
447 let mut des1 = DES::new_with_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
448 let mut des2 = DES::new_with_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
449
450 let plaintext = 0x1234567890ABCDEF_u64;
451 let ciphertext = des1.encrypt_u64(plaintext);
452 println!("Plaintext:\t\t{:#018X}", plaintext);
453 println!("Ciphertext:\t\t{:#018X}", ciphertext);
454 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
455
456 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
457 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
458 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
459 assert_eq!(cipher_cipher_text, plaintext);
460
461 let ciphertext = des2.encrypt_u64(plaintext);
462 println!("Plaintext:\t\t{:#018X}", plaintext);
463 println!("Ciphertext:\t\t{:#018X}", ciphertext);
464 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
465
466 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
467 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
468 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
469 assert_eq!(cipher_cipher_text, plaintext);
470 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
471
472 #[cfg(test)]
473 des_compile_fail_new_with_key();
474 println!("-------------------------------");
475}
476
477#[test]
478fn des_compile_fail_new_with_key()
479{
480 use cryptocol::symmetric::DES;
481 let des = DES::new_with_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
482 // It cannot be compiled!
483 #[cfg(compile_fail)] des.encrypt_u64(0x1E32B46B44C69201_u64);
484}
485
486fn des_new_with_key_u64()
487{
488 println!("des_new_with_key_u64");
489 use cryptocol::symmetric::DES;
490
491 // Normal case
492 let mut des = DES::new_with_key_u64(0xEFCDAB9078563412);
493 let plaintext = 0x1234567890ABCDEF_u64;
494 let ciphertext = des.encrypt_u64(plaintext);
495
496 println!("Plaintext:\t\t{:#018X}", plaintext);
497 println!("Ciphertext:\t\t{:#018X}", ciphertext);
498 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
499
500 let cipher_cipher_text = des.encrypt_u64(ciphertext);
501 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
502 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
503 assert_ne!(cipher_cipher_text, plaintext);
504 println!();
505
506 // Weak key case 1 for 0x0000000000000000
507 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
508 let mut des1 = DES::new_with_key_u64(0x0000000000000000);
509 let mut des2 = DES::new_with_key_u64(0x0101010101010101);
510
511 let plaintext = 0x1234567890ABCDEF_u64;
512 let ciphertext1 = des1.encrypt_u64(plaintext);
513 let ciphertext2 = des2.encrypt_u64(plaintext);
514
515 println!("Plaintext:\t\t{:#018X}", plaintext);
516 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
517 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
518 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
519 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
520 assert_eq!(ciphertext1, ciphertext2);
521
522 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
523 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
524 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
525 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
526 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
527 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
528 assert_eq!(cipher_cipher_text1, plaintext);
529 assert_eq!(cipher_cipher_text2, plaintext);
530 println!();
531 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
532
533 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
534 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
535 let mut des1 = DES::new_with_key_u64(0xFFFFFFFFFFFFFFFF);
536 let mut des2 = DES::new_with_key_u64(0xFEFEFEFEFEFEFEFE);
537 let plaintext = 0x1234567890ABCDEF_u64;
538 let ciphertext1 = des1.encrypt_u64(plaintext);
539 let ciphertext2 = des2.encrypt_u64(plaintext);
540
541 println!("Plaintext:\t\t{:#018X}", plaintext);
542 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
543 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
544 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
545 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
546 assert_eq!(ciphertext1, ciphertext2);
547
548 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
549 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
550 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
551 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
552 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
553 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
554 assert_eq!(cipher_cipher_text1, plaintext);
555 assert_eq!(cipher_cipher_text2, plaintext);
556 println!();
557 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
558
559 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
560 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
561 let mut des1 = DES::new_with_key_u64(0xF1F1F1F1E0E0E0E0);
562 let mut des2 = DES::new_with_key_u64(0xF0F0F0F0E1E1E1E1);
563 let plaintext = 0x1234567890ABCDEF_u64;
564 let ciphertext1 = des1.encrypt_u64(plaintext);
565 let ciphertext2 = des2.encrypt_u64(plaintext);
566
567 println!("Plaintext:\t\t{:#018X}", plaintext);
568 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
569 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
570 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
571 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
572 assert_eq!(ciphertext1, ciphertext2);
573
574 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
575 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
576 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
577 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
578 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
579 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
580 assert_eq!(cipher_cipher_text1, plaintext);
581 assert_eq!(cipher_cipher_text2, plaintext);
582 println!();
583 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
584
585 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
586 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
587 let mut des1 = DES::new_with_key_u64(0x0E0E0E0E1F1F1F1F);
588 let mut des2 = DES::new_with_key_u64(0x0F0F0F0F1E1E1E1E);
589 let plaintext = 0x1234567890ABCDEF_u64;
590 let ciphertext1 = des1.encrypt_u64(plaintext);
591 let ciphertext2 = des2.encrypt_u64(plaintext);
592
593 println!("Plaintext:\t\t{:#018X}", plaintext);
594 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
595 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
596 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
597 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
598 assert_eq!(ciphertext1, ciphertext2);
599
600 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
601 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
602 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
603 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
604 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
605 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
606 assert_eq!(cipher_cipher_text1, plaintext);
607 assert_eq!(cipher_cipher_text2, plaintext);
608 println!();
609 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
610
611 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
612 let mut des1 = DES::new_with_key_u64(0x0E010E011F011F01);
613 let mut des2 = DES::new_with_key_u64(0x010E010E011F011F);
614
615 let plaintext = 0x1234567890ABCDEF_u64;
616 let ciphertext = des1.encrypt_u64(plaintext);
617 println!("Plaintext:\t\t{:#018X}", plaintext);
618 println!("Ciphertext:\t\t{:#018X}", ciphertext);
619 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
620
621 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
622 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
623 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
624 assert_eq!(cipher_cipher_text, plaintext);
625
626 let ciphertext = des2.encrypt_u64(plaintext);
627 println!("Plaintext:\t\t{:#018X}", plaintext);
628 println!("Ciphertext:\t\t{:#018X}", ciphertext);
629 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
630
631 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
632 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
633 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
634 assert_eq!(cipher_cipher_text, plaintext);
635 println!();
636 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
637
638 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
639 let mut des1 = DES::new_with_key_u64(0xF101F101E001E001);
640 let mut des2 = DES::new_with_key_u64(0x01F101F101E001E0);
641
642 let plaintext = 0x1234567890ABCDEF_u64;
643 let ciphertext = des1.encrypt_u64(plaintext);
644 println!("Plaintext:\t\t{:#018X}", plaintext);
645 println!("Ciphertext:\t\t{:#018X}", ciphertext);
646 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
647
648 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
649 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
650 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
651 assert_eq!(cipher_cipher_text, plaintext);
652
653 let ciphertext = des2.encrypt_u64(plaintext);
654 println!("Plaintext:\t\t{:#018X}", plaintext);
655 println!("Ciphertext:\t\t{:#018X}", ciphertext);
656 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
657
658 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
659 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
660 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
661 assert_eq!(cipher_cipher_text, plaintext);
662 println!();
663 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
664
665 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
666 let mut des1 = DES::new_with_key_u64(0xFE01FE01FE01FE01);
667 let mut des2 = DES::new_with_key_u64(0x01FE01FE01FE01FE);
668
669 let plaintext = 0x1234567890ABCDEF_u64;
670 let ciphertext = des1.encrypt_u64(plaintext);
671 println!("Plaintext:\t\t{:#018X}", plaintext);
672 println!("Ciphertext:\t\t{:#018X}", ciphertext);
673 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
674
675 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
676 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
677 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
678 assert_eq!(cipher_cipher_text, plaintext);
679
680 let ciphertext = des2.encrypt_u64(plaintext);
681 println!("Plaintext:\t\t{:#018X}", plaintext);
682 println!("Ciphertext:\t\t{:#018X}", ciphertext);
683 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
684
685 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
686 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
687 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
688 assert_eq!(cipher_cipher_text, plaintext);
689 println!();
690 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
691
692 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
693 let mut des1 = DES::new_with_key_u64(0xF10EF10EE01FE01F);
694 let mut des2 = DES::new_with_key_u64(0x0EF10EF11FE01FE0);
695
696 let plaintext = 0x1234567890ABCDEF_u64;
697 let ciphertext = des1.encrypt_u64(plaintext);
698 println!("Plaintext:\t\t{:#018X}", plaintext);
699 println!("Ciphertext:\t\t{:#018X}", ciphertext);
700 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
701
702 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
703 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
704 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
705 assert_eq!(cipher_cipher_text, plaintext);
706
707 let ciphertext = des2.encrypt_u64(plaintext);
708 println!("Plaintext:\t\t{:#018X}", plaintext);
709 println!("Ciphertext:\t\t{:#018X}", ciphertext);
710 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
711
712 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
713 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
714 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
715 assert_eq!(cipher_cipher_text, plaintext);
716 println!();
717 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
718
719 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
720 let mut des1 = DES::new_with_key_u64(0xFE0EFE0EFE1FFE1F);
721 let mut des2 = DES::new_with_key_u64(0x0EFE0EFE1FFE1FFE);
722
723 let plaintext = 0x1234567890ABCDEF_u64;
724 let ciphertext = des1.encrypt_u64(plaintext);
725 println!("Plaintext:\t\t{:#018X}", plaintext);
726 println!("Ciphertext:\t\t{:#018X}", ciphertext);
727 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
728
729 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
730 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
731 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
732 assert_eq!(cipher_cipher_text, plaintext);
733
734 let ciphertext = des2.encrypt_u64(plaintext);
735 println!("Plaintext:\t\t{:#018X}", plaintext);
736 println!("Ciphertext:\t\t{:#018X}", ciphertext);
737 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
738
739 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
740 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
741 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
742 assert_eq!(cipher_cipher_text, plaintext);
743 println!();
744 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
745
746 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
747 let mut des1 = DES::new_with_key_u64(0xFEF1FEF1FEE0FEE0);
748 let mut des2 = DES::new_with_key_u64(0xF1FEF1FEE0FEE0FE);
749
750 let plaintext = 0x1234567890ABCDEF_u64;
751 let ciphertext = des1.encrypt_u64(plaintext);
752 println!("Plaintext:\t\t{:#018X}", plaintext);
753 println!("Ciphertext:\t\t{:#018X}", ciphertext);
754 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
755
756 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
757 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
758 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
759 assert_eq!(cipher_cipher_text, plaintext);
760
761 let ciphertext = des2.encrypt_u64(plaintext);
762 println!("Plaintext:\t\t{:#018X}", plaintext);
763 println!("Ciphertext:\t\t{:#018X}", ciphertext);
764 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
765
766 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
767 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
768 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
769 assert_eq!(cipher_cipher_text, plaintext);
770 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
771 println!("-------------------------------");
772}
773
774fn des_encryptor_with_key()
775{
776 println!("des_encryptor_with_key");
777 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
778
779 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
780 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
781 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
782 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
783 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
784 let plaintext = 0x_1234567890ABCDEF_u64;
785 let ciphertext = tdes.encrypt_u64(plaintext);
786
787 println!("Plaintext:\t\t{:#018X}", plaintext);
788 println!("Ciphertext:\t\t{:#018X}", ciphertext);
789 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
790
791 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
792 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
793 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
794 assert_eq!(cipher_cipher_text, plaintext);
795 println!();
796
797 // Operators
798 let mut tdes = BigCryptor64::new()
799 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
800 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
801 + DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
802 let plaintext = 0x_1234567890ABCDEF_u64;
803 let ciphertext = tdes.encrypt_u64(plaintext);
804
805 println!("Plaintext:\t\t{:#018X}", plaintext);
806 println!("Ciphertext:\t\t{:#018X}", ciphertext);
807 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
808
809 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
810 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
811 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
812 assert_eq!(cipher_cipher_text, plaintext);
813 println!("-------------------------------");
814}
815
816fn des_encryptor_with_key_u64()
817{
818 println!("des_encryptor_with_key_u64");
819 use cryptocol::symmetric::{ BigCryptor64, DES };
820
821 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
822 [Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
823 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
824 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64))]
825 );
826 let plaintext = 0x_1234567890ABCDEF_u64;
827 let ciphertext = tdes.encrypt_u64(plaintext);
828
829 println!("Plaintext:\t\t{:#018X}", plaintext);
830 println!("Ciphertext:\t\t{:#018X}", ciphertext);
831 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
832
833 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
834 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
835 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
836 assert_eq!(cipher_cipher_text, plaintext);
837 println!();
838
839 // Operators
840 let mut tdes = BigCryptor64::new()
841 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)
842 - DES::encryptor_with_key_u64(0x_FEDCBA0987654321_u64)
843 + DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64);
844 let plaintext = 0x_1234567890ABCDEF_u64;
845 let ciphertext = tdes.encrypt_u64(plaintext);
846
847 println!("Plaintext:\t\t{:#018X}", plaintext);
848 println!("Ciphertext:\t\t{:#018X}", ciphertext);
849 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
850
851 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
852 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
853 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
854 assert_eq!(cipher_cipher_text, plaintext);
855 println!("-------------------------------");
856}
857
858fn des_decryptor_with_key()
859{
860 println!("des_decryptor_with_key_u64");
861 use cryptocol::symmetric::{ DES, BigCryptor64, SmallCryptor };
862
863 let keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
864 = [ Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])),
865 Box::new(DES::decryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])),
866 Box::new(DES::encryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])) ];
867 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
868 let plaintext = 0x_1234567890ABCDEF_u64;
869 let ciphertext = tdes.encrypt_u64(plaintext);
870
871 println!("Plaintext:\t\t{:#018X}", plaintext);
872 println!("Ciphertext:\t\t{:#018X}", ciphertext);
873 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
874
875 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
876 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
877 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
878 assert_eq!(cipher_cipher_text, plaintext);
879 println!();
880
881 // Operators
882 let mut tdes = BigCryptor64::new()
883 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12])
884 - DES::encryptor_with_key([0x21_u8, 0x43, 0x65, 0x87, 0x09, 0xBA, 0xDC, 0xFE])
885 - DES::decryptor_with_key([0xEF_u8, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12]);
886 let plaintext = 0x_1234567890ABCDEF_u64;
887 let ciphertext = tdes.encrypt_u64(plaintext);
888
889 println!("Plaintext:\t\t{:#018X}", plaintext);
890 println!("Ciphertext:\t\t{:#018X}", ciphertext);
891 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
892
893 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
894 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
895 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
896 assert_eq!(cipher_cipher_text, plaintext);
897 println!("-------------------------------");
898}
899
900fn des_decryptor_with_key_u64()
901{
902 println!("des_decryptor_with_key_u64");
903 use cryptocol::symmetric::{ BigCryptor64, DES };
904
905 let mut tdes = BigCryptor64::new_with_small_cryptor_array(
906 [ Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)),
907 Box::new(DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)),
908 Box::new(DES::encryptor_with_key_u64(0x_1234567890ABCDEF_u64)) ] );
909 let plaintext = 0x_1234567890ABCDEF_u64;
910 let ciphertext = tdes.encrypt_u64(plaintext);
911
912 println!("Plaintext:\t\t{:#018X}", plaintext);
913 println!("Ciphertext:\t\t{:#018X}", ciphertext);
914 assert_eq!(ciphertext, 0x272A2AC7B4E66748_u64);
915
916 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
917 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
918 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
919 assert_eq!(cipher_cipher_text, plaintext);
920 println!();
921
922
923 // Operators
924 let mut tdes = BigCryptor64::new()
925 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64)
926 + DES::decryptor_with_key_u64(0x_FEDCBA0987654321_u64)
927 - DES::decryptor_with_key_u64(0x_1234567890ABCDEF_u64);
928 let plaintext = 0x_1234567890ABCDEF_u64;
929 let ciphertext = tdes.encrypt_u64(plaintext);
930
931 println!("Plaintext:\t\t{:#018X}", plaintext);
932 println!("Ciphertext:\t\t{:#018X}", ciphertext);
933 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
934
935 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
936 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
937 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
938 assert_eq!(cipher_cipher_text, plaintext);
939 println!("-------------------------------");
940}
941
942fn des_get_key()
943{
944 println!("des_get_key");
945 use cryptocol::symmetric::DES;
946
947 let mut des = DES::new();
948 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
949 let key = des.get_key();
950 print!("K = ");
951 for k in key
952 { print!("{:#02X} ", k); }
953 assert_eq!(key, [0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
954}
955
956fn des_get_key_u64()
957{
958 println!("des_get_key_u64");
959 use cryptocol::symmetric::DES;
960
961 let mut des = DES::new();
962 des.set_key_u64(0xEFCDAB9078563412);
963 let key = des.get_key_u64();
964 println!("Key = {}", key);
965 assert_eq!(key, 0xEFCDAB9078563412_u64);
966}
967
968fn des_set_key()
969{
970 println!("des_set_key");
971 use cryptocol::symmetric::DES;
972
973 // Normal case
974 let mut des = DES::new();
975 des.set_key([0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF]);
976 let plaintext = 0x1234567890ABCDEF_u64;
977 let ciphertext = des.encrypt_u64(plaintext);
978
979 println!("Plaintext:\t\t{:#018X}", plaintext);
980 println!("Ciphertext:\t\t{:#018X}", ciphertext);
981 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
982
983 let cipher_cipher_text = des.encrypt_u64(ciphertext);
984 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
985 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
986 assert_ne!(cipher_cipher_text, plaintext);
987 println!();
988
989 // Weak key case 1 for [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
990 // The key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] is the same key as the key
991 // [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01] because of parity bits.
992 let mut des1 = DES::new();
993 let mut des2 = DES::new();
994 des1.set_key([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
995 des2.set_key([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
996
997 let plaintext = 0x1234567890ABCDEF_u64;
998 let ciphertext1 = des1.encrypt_u64(plaintext);
999 let ciphertext2 = des2.encrypt_u64(plaintext);
1000
1001 println!("Plaintext:\t\t{:#018X}", plaintext);
1002 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1003 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1004 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1005 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1006 assert_eq!(ciphertext1, ciphertext2);
1007
1008 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1009 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1010 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1011 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1012 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1013 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1014 assert_eq!(cipher_cipher_text1, plaintext);
1015 assert_eq!(cipher_cipher_text2, plaintext);
1016 println!();
1017 // So, you can't use the weak key [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
1018 // and [0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]!!!
1019
1020
1021 // Weak key case 2 for [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1022 // The key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] is the same key as the key
1023 // [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE] because of parity bits.
1024 let mut des1 = DES::new();
1025 let mut des2 = DES::new();
1026 des1.set_key([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
1027 des2.set_key([0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]);
1028 let plaintext = 0x1234567890ABCDEF_u64;
1029 let ciphertext1 = des1.encrypt_u64(plaintext);
1030 let ciphertext2 = des2.encrypt_u64(plaintext);
1031
1032 println!("Plaintext:\t\t{:#018X}", plaintext);
1033 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1034 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1035 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1036 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1037 assert_eq!(ciphertext1, ciphertext2);
1038
1039 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1040 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1041 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1042 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1043 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1044 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1045 assert_eq!(cipher_cipher_text1, plaintext);
1046 assert_eq!(cipher_cipher_text2, plaintext);
1047 println!();
1048 // So, you can't use the weak key [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
1049 // and [0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE]!!!
1050
1051 // Weak key case 3 for [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1052 // The key [0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0] is the same key as the key
1053 // [0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0] because of parity bits.
1054 let mut des1 = DES::new();
1055 let mut des2 = DES::new();
1056 des1.set_key([0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]);
1057 des2.set_key([0xE1, 0xE1, 0xE1, 0xE1, 0xF0, 0xF0, 0xF0, 0xF0]);
1058 let plaintext = 0x1234567890ABCDEF_u64;
1059 let ciphertext1 = des1.encrypt_u64(plaintext);
1060 let ciphertext2 = des2.encrypt_u64(plaintext);
1061
1062 println!("Plaintext:\t\t{:#018X}", plaintext);
1063 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1064 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1065 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1066 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1067 assert_eq!(ciphertext1, ciphertext2);
1068
1069 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1070 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1071 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1072 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1073 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1074 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1075 assert_eq!(cipher_cipher_text1, plaintext);
1076 assert_eq!(cipher_cipher_text2, plaintext);
1077 println!();
1078 // So, you can't use the weak key [0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1]
1079 // and [0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1]!!!
1080
1081 // Weak key case 4 for [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1082 // The key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E] is the same key as the key
1083 // [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F] because of parity bits.
1084 let mut des1 = DES::new();
1085 let mut des2 = DES::new();
1086 des1.set_key([0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]);
1087 des2.set_key([0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]);
1088 let plaintext = 0x1234567890ABCDEF_u64;
1089 let ciphertext1 = des1.encrypt_u64(plaintext);
1090 let ciphertext2 = des2.encrypt_u64(plaintext);
1091
1092 println!("Plaintext:\t\t{:#018X}", plaintext);
1093 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1094 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1095 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1096 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1097 assert_eq!(ciphertext1, ciphertext2);
1098
1099 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1100 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1101 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1102 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1103 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1104 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1105 assert_eq!(cipher_cipher_text1, plaintext);
1106 assert_eq!(cipher_cipher_text2, plaintext);
1107 println!();
1108 // So, you can't use the weak key [0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E]
1109 // and [0x1E, 0x1E, 0x1E, 0x1E, 0x0F, 0x0F, 0x0F, 0x0F]!!!
1110
1111 // Semi-Weak key case 1 for [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E] and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]
1112 let mut des1 = DES::new();
1113 let mut des2 = DES::new();
1114 des1.set_key([0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]);
1115 des2.set_key([0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]);
1116
1117 let plaintext = 0x1234567890ABCDEF_u64;
1118 let ciphertext = des1.encrypt_u64(plaintext);
1119 println!("Plaintext:\t\t{:#018X}", plaintext);
1120 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1121 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1122
1123 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1124 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1125 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1126 assert_eq!(cipher_cipher_text, plaintext);
1127
1128 let ciphertext = des2.encrypt_u64(plaintext);
1129 println!("Plaintext:\t\t{:#018X}", plaintext);
1130 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1131 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1132
1133 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1134 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1135 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1136 assert_eq!(cipher_cipher_text, plaintext);
1137 println!();
1138 // So, you can't use the semi-weak keys [0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E]
1139 // and [0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01]!!!
1140
1141 // Semi-Weak key case 2 for [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1] and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]
1142 let mut des1 = DES::new();
1143 let mut des2 = DES::new();
1144 des1.set_key([0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]);
1145 des2.set_key([0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]);
1146
1147 let plaintext = 0x1234567890ABCDEF_u64;
1148 let ciphertext = des1.encrypt_u64(plaintext);
1149 println!("Plaintext:\t\t{:#018X}", plaintext);
1150 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1151 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1152
1153 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1154 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1155 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1156 assert_eq!(cipher_cipher_text, plaintext);
1157
1158 let ciphertext = des2.encrypt_u64(plaintext);
1159 println!("Plaintext:\t\t{:#018X}", plaintext);
1160 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1161 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1162
1163 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1164 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1165 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1166 assert_eq!(cipher_cipher_text, plaintext);
1167 println!();
1168 // So, you can't use the semi-weak keys [0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1]
1169 // and [0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01]!!!
1170
1171 // Semi-Weak key case 3 for [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE] and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]
1172 let mut des1 = DES::new();
1173 let mut des2 = DES::new();
1174 des1.set_key([0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]);
1175 des2.set_key([0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]);
1176
1177 let plaintext = 0x1234567890ABCDEF_u64;
1178 let ciphertext = des1.encrypt_u64(plaintext);
1179 println!("Plaintext:\t\t{:#018X}", plaintext);
1180 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1181 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1182
1183 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1184 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1185 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1186 assert_eq!(cipher_cipher_text, plaintext);
1187
1188 let ciphertext = des2.encrypt_u64(plaintext);
1189 println!("Plaintext:\t\t{:#018X}", plaintext);
1190 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1191 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1192
1193 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1194 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1195 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1196 assert_eq!(cipher_cipher_text, plaintext);
1197 println!();
1198 // So, you can't use the semi-weak keys [0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE]
1199 // and [0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01]!!!
1200
1201 // Semi-Weak key case 4 for [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1] and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]
1202 let mut des1 = DES::new();
1203 let mut des2 = DES::new();
1204 des1.set_key([0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]);
1205 des2.set_key([0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]);
1206
1207 let plaintext = 0x1234567890ABCDEF_u64;
1208 let ciphertext = des1.encrypt_u64(plaintext);
1209 println!("Plaintext:\t\t{:#018X}", plaintext);
1210 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1211 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1212
1213 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1214 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1215 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1216 assert_eq!(cipher_cipher_text, plaintext);
1217
1218 let ciphertext = des2.encrypt_u64(plaintext);
1219 println!("Plaintext:\t\t{:#018X}", plaintext);
1220 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1221 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1222
1223 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1224 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1225 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1226 assert_eq!(cipher_cipher_text, plaintext);
1227 println!();
1228 // So, you can't use the semi-weak keys [0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1]
1229 // and [0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E]!!!
1230
1231 // Semi-Weak key case 5 for [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE] and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]
1232 let mut des1 = DES::new();
1233 let mut des2 = DES::new();
1234 des1.set_key([0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]);
1235 des2.set_key([0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]);
1236
1237 let plaintext = 0x1234567890ABCDEF_u64;
1238 let ciphertext = des1.encrypt_u64(plaintext);
1239 println!("Plaintext:\t\t{:#018X}", plaintext);
1240 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1241 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1242
1243 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1244 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1245 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1246 assert_eq!(cipher_cipher_text, plaintext);
1247
1248 let ciphertext = des2.encrypt_u64(plaintext);
1249 println!("Plaintext:\t\t{:#018X}", plaintext);
1250 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1251 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1252
1253 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1254 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1255 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1256 assert_eq!(cipher_cipher_text, plaintext);
1257 println!();
1258 // So, you can't use the semi-weak keys [0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE]
1259 // and [0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E]!!!
1260
1261 // Semi-Weak key case 6 for [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE] and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]
1262 let mut des1 = DES::new();
1263 let mut des2 = DES::new();
1264 des1.set_key([0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]);
1265 des2.set_key([0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]);
1266
1267 let plaintext = 0x1234567890ABCDEF_u64;
1268 let ciphertext = des1.encrypt_u64(plaintext);
1269 println!("Plaintext:\t\t{:#018X}", plaintext);
1270 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1271 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1272
1273 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1274 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1275 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1276 assert_eq!(cipher_cipher_text, plaintext);
1277
1278 let ciphertext = des2.encrypt_u64(plaintext);
1279 println!("Plaintext:\t\t{:#018X}", plaintext);
1280 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1281 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1282
1283 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1284 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1285 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1286 assert_eq!(cipher_cipher_text, plaintext);
1287 // So, you can't use the semi-weak keys [0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE]
1288 // and [0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1]!!!
1289 println!("-------------------------------");
1290}
1291
1292fn des_set_key_u64()
1293{
1294 println!("des_set_key_u64");
1295 use cryptocol::symmetric::DES;
1296
1297 // Normal case
1298 let mut des = DES::new();
1299 des.set_key_u64(0xEFCDAB9078563412);
1300 let plaintext = 0x1234567890ABCDEF_u64;
1301 let ciphertext = des.encrypt_u64(plaintext);
1302
1303 println!("Plaintext:\t\t{:#018X}", plaintext);
1304 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1305 assert_eq!(ciphertext, 0x3B6041D76AF28F23_u64);
1306
1307 let cipher_cipher_text = des.encrypt_u64(ciphertext);
1308 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1309 assert_eq!(cipher_cipher_text, 0x7C5AAE491DC1310D_u64);
1310 assert_ne!(cipher_cipher_text, plaintext);
1311 println!();
1312
1313 // Weak key case 1 for 0x0000000000000000
1314 // The key 0x0000000000000000 is the same key as the key 0x0101010101010101 because of parity bits.
1315 let mut des1 = DES::new();
1316 let mut des2 = DES::new();
1317 des1.set_key_u64(0x0000000000000000);
1318 des2.set_key_u64(0x0101010101010101);
1319
1320 let plaintext = 0x1234567890ABCDEF_u64;
1321 let ciphertext1 = des1.encrypt_u64(plaintext);
1322 let ciphertext2 = des2.encrypt_u64(plaintext);
1323
1324 println!("Plaintext:\t\t{:#018X}", plaintext);
1325 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1326 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1327 assert_eq!(ciphertext1, 0x1E32B46B44C69201_u64);
1328 assert_eq!(ciphertext2, 0x1E32B46B44C69201_u64);
1329 assert_eq!(ciphertext1, ciphertext2);
1330
1331 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1332 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1333 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1334 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1335 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1336 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1337 assert_eq!(cipher_cipher_text1, plaintext);
1338 assert_eq!(cipher_cipher_text2, plaintext);
1339 println!();
1340 // So, you can't use the weak key 0x0000000000000000 and 0x0101010101010101!!!
1341
1342 // Weak key case 2 for 0xFFFFFFFFFFFFFFFF
1343 // The key 0xFFFFFFFFFFFFFFFF is the same key as the key 0xFEFEFEFEFEFEFEFE because of parity bits.
1344 let mut des1 = DES::new();
1345 let mut des2 = DES::new();
1346 des1.set_key_u64(0xFFFFFFFFFFFFFFFF);
1347 des2.set_key_u64(0xFEFEFEFEFEFEFEFE);
1348 let plaintext = 0x1234567890ABCDEF_u64;
1349 let ciphertext1 = des1.encrypt_u64(plaintext);
1350 let ciphertext2 = des2.encrypt_u64(plaintext);
1351
1352 println!("Plaintext:\t\t{:#018X}", plaintext);
1353 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1354 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1355 assert_eq!(ciphertext1, 0xA5997AB38BC07250_u64);
1356 assert_eq!(ciphertext2, 0xA5997AB38BC07250_u64);
1357 assert_eq!(ciphertext1, ciphertext2);
1358
1359 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1360 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1361 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1362 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1363 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1364 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1365 assert_eq!(cipher_cipher_text1, plaintext);
1366 assert_eq!(cipher_cipher_text2, plaintext);
1367 println!();
1368 // So, you can't use the weak key 0xFFFFFFFFFFFFFFFF and 0xFEFEFEFEFEFEFEFE!!!
1369
1370 // Weak key case 3 for 0xF1F1F1F1E0E0E0E0 in little-endianness
1371 // The key 0xF1F1F1F1E0E0E0E0 is the same key as the key 0xF0F0F0F0E1E1E1E1 because of parity bits.
1372 let mut des1 = DES::new();
1373 let mut des2 = DES::new();
1374 des1.set_key_u64(0xF1F1F1F1E0E0E0E0);
1375 des2.set_key_u64(0xF0F0F0F0E1E1E1E1);
1376 let plaintext = 0x1234567890ABCDEF_u64;
1377 let ciphertext1 = des1.encrypt_u64(plaintext);
1378 let ciphertext2 = des2.encrypt_u64(plaintext);
1379
1380 println!("Plaintext:\t\t{:#018X}", plaintext);
1381 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1382 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1383 assert_eq!(ciphertext1, 0x94CCA0201F033101_u64);
1384 assert_eq!(ciphertext2, 0x94CCA0201F033101_u64);
1385 assert_eq!(ciphertext1, ciphertext2);
1386
1387 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1388 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1389 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1390 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1391 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1392 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1393 assert_eq!(cipher_cipher_text1, plaintext);
1394 assert_eq!(cipher_cipher_text2, plaintext);
1395 println!();
1396 // So, you can't use the weak key 0xF1F1F1F1E0E0E0E0 and 0xF0F0F0F0E1E1E1E1!!!
1397
1398 // Weak key case 4 for 0x0E0E0E0E1F1F1F1F in little-endianness
1399 // The key 0x0E0E0E0E1F1F1F1F is the same key as the key 0x0F0F0F0F1E1E1E1E because of parity bits.
1400 let mut des1 = DES::new();
1401 let mut des2 = DES::new();
1402 des1.set_key_u64(0x0E0E0E0E1F1F1F1F);
1403 des2.set_key_u64(0x0F0F0F0F1E1E1E1E);
1404 let plaintext = 0x1234567890ABCDEF_u64;
1405 let ciphertext1 = des1.encrypt_u64(plaintext);
1406 let ciphertext2 = des2.encrypt_u64(plaintext);
1407
1408 println!("Plaintext:\t\t{:#018X}", plaintext);
1409 println!("Ciphertext1:\t\t{:#018X}", ciphertext1);
1410 println!("Ciphertext2:\t\t{:#018X}", ciphertext2);
1411 assert_eq!(ciphertext1, 0x4FB6397B5352DB0C_u64);
1412 assert_eq!(ciphertext2, 0x4FB6397B5352DB0C_u64);
1413 assert_eq!(ciphertext1, ciphertext2);
1414
1415 let cipher_cipher_text1 = des1.encrypt_u64(ciphertext1);
1416 let cipher_cipher_text2 = des2.encrypt_u64(ciphertext2);
1417 println!("Cipher-ciphertext1:\t{:#018X}\n", cipher_cipher_text1);
1418 println!("Cipher-ciphertext2:\t{:#018X}\n", cipher_cipher_text2);
1419 assert_eq!(cipher_cipher_text1, 0x1234567890ABCDEF_u64);
1420 assert_eq!(cipher_cipher_text2, 0x1234567890ABCDEF_u64);
1421 assert_eq!(cipher_cipher_text1, plaintext);
1422 assert_eq!(cipher_cipher_text2, plaintext);
1423 println!();
1424 // So, you can't use the weak key 0x0E0E0E0E1F1F1F1F and 0x0F0F0F0F1E1E1E1E!!!
1425
1426 // Semi-Weak key case 1 for 0x0E010E011F011F01 and 0x010E010E011F011F in little-endianness
1427 let mut des1 = DES::new();
1428 let mut des2 = DES::new();
1429 des1.set_key_u64(0x0E010E011F011F01);
1430 des2.set_key_u64(0x010E010E011F011F);
1431
1432 let plaintext = 0x1234567890ABCDEF_u64;
1433 let ciphertext = des1.encrypt_u64(plaintext);
1434 println!("Plaintext:\t\t{:#018X}", plaintext);
1435 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1436 assert_eq!(ciphertext, 0xC2C71D736E97876C_u64);
1437
1438 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1439 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1440 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1441 assert_eq!(cipher_cipher_text, plaintext);
1442
1443 let ciphertext = des2.encrypt_u64(plaintext);
1444 println!("Plaintext:\t\t{:#018X}", plaintext);
1445 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1446 assert_eq!(ciphertext, 0x063A6E55466423D2_u64);
1447
1448 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1449 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1450 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1451 assert_eq!(cipher_cipher_text, plaintext);
1452 println!();
1453 // So, you can't use the semi-weak keys 0x0E010E011F011F01 and 0x010E010E011F011F!!!
1454
1455 // Semi-Weak key case 2 for 0xF101F101E001E001 and 0x01F101F101E001E0 in little-endianness
1456 let mut des1 = DES::new();
1457 let mut des2 = DES::new();
1458 des1.set_key_u64(0xF101F101E001E001);
1459 des2.set_key_u64(0x01F101F101E001E0);
1460
1461 let plaintext = 0x1234567890ABCDEF_u64;
1462 let ciphertext = des1.encrypt_u64(plaintext);
1463 println!("Plaintext:\t\t{:#018X}", plaintext);
1464 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1465 assert_eq!(ciphertext, 0x85A63690E79AAA15_u64);
1466
1467 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1468 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1469 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1470 assert_eq!(cipher_cipher_text, plaintext);
1471
1472 let ciphertext = des2.encrypt_u64(plaintext);
1473 println!("Plaintext:\t\t{:#018X}", plaintext);
1474 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1475 assert_eq!(ciphertext, 0x15B721BBB44A12F5_u64);
1476
1477 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1478 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1479 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1480 assert_eq!(cipher_cipher_text, plaintext);
1481 println!();
1482 // So, you can't use the semi-weak keys 0xF101F101E001E001 and 0x01F101F101E001E0!!!
1483
1484 // Semi-Weak key case 3 for 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE in little-endianness
1485 let mut des1 = DES::new();
1486 let mut des2 = DES::new();
1487 des1.set_key_u64(0xFE01FE01FE01FE01);
1488 des2.set_key_u64(0x01FE01FE01FE01FE);
1489
1490 let plaintext = 0x1234567890ABCDEF_u64;
1491 let ciphertext = des1.encrypt_u64(plaintext);
1492 println!("Plaintext:\t\t{:#018X}", plaintext);
1493 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1494 assert_eq!(ciphertext, 0xAE38CC9D9FA48581_u64);
1495
1496 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1497 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1498 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1499 assert_eq!(cipher_cipher_text, plaintext);
1500
1501 let ciphertext = des2.encrypt_u64(plaintext);
1502 println!("Plaintext:\t\t{:#018X}", plaintext);
1503 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1504 assert_eq!(ciphertext, 0x7EE95658A653960D_u64);
1505
1506 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1507 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1508 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1509 assert_eq!(cipher_cipher_text, plaintext);
1510 println!();
1511 // So, you can't use the semi-weak keys 0xFE01FE01FE01FE01 and 0x01FE01FE01FE01FE!!!
1512
1513 // Semi-Weak key case 4 for 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0 in little-endianness
1514 let mut des1 = DES::new();
1515 let mut des2 = DES::new();
1516 des1.set_key_u64(0xF10EF10EE01FE01F);
1517 des2.set_key_u64(0x0EF10EF11FE01FE0);
1518
1519 let plaintext = 0x1234567890ABCDEF_u64;
1520 let ciphertext = des1.encrypt_u64(plaintext);
1521 println!("Plaintext:\t\t{:#018X}", plaintext);
1522 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1523 assert_eq!(ciphertext, 0x81ECC05B173F793E_u64);
1524
1525 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1526 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1527 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1528 assert_eq!(cipher_cipher_text, plaintext);
1529
1530 let ciphertext = des2.encrypt_u64(plaintext);
1531 println!("Plaintext:\t\t{:#018X}", plaintext);
1532 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1533 assert_eq!(ciphertext, 0x4D0AD4DC147E4BDF_u64);
1534
1535 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1536 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1537 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1538 assert_eq!(cipher_cipher_text, plaintext);
1539 println!();
1540 // So, you can't use the semi-weak keys 0xF10EF10EE01FE01F and 0x0EF10EF11FE01FE0!!!
1541
1542 // Semi-Weak key case 5 for 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE in little-endianness
1543 let mut des1 = DES::new();
1544 let mut des2 = DES::new();
1545 des1.set_key_u64(0xFE0EFE0EFE1FFE1F);
1546 des2.set_key_u64(0x0EFE0EFE1FFE1FFE);
1547
1548 let plaintext = 0x1234567890ABCDEF_u64;
1549 let ciphertext = des1.encrypt_u64(plaintext);
1550 println!("Plaintext:\t\t{:#018X}", plaintext);
1551 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1552 assert_eq!(ciphertext, 0x59735490F84A0AD0_u64);
1553
1554 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1555 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1556 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1557 assert_eq!(cipher_cipher_text, plaintext);
1558
1559 let ciphertext = des2.encrypt_u64(plaintext);
1560 println!("Plaintext:\t\t{:#018X}", plaintext);
1561 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1562 assert_eq!(ciphertext, 0x79FD3CBFE57F4B0B_u64);
1563
1564 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1565 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1566 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1567 assert_eq!(cipher_cipher_text, plaintext);
1568 println!();
1569 // So, you can't use the semi-weak keys 0xFE0EFE0EFE1FFE1F and 0x0EFE0EFE1FFE1FFE!!!
1570
1571 // Semi-Weak key case 6 for 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE in little-endianness
1572 let mut des1 = DES::new();
1573 let mut des2 = DES::new();
1574 des1.set_key_u64(0xFEF1FEF1FEE0FEE0);
1575 des2.set_key_u64(0xF1FEF1FEE0FEE0FE);
1576
1577 let plaintext = 0x1234567890ABCDEF_u64;
1578 let ciphertext = des1.encrypt_u64(plaintext);
1579 println!("Plaintext:\t\t{:#018X}", plaintext);
1580 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1581 assert_eq!(ciphertext, 0x27C83AAE29571889_u64);
1582
1583 let cipher_cipher_text = des2.encrypt_u64(ciphertext);
1584 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1585 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1586 assert_eq!(cipher_cipher_text, plaintext);
1587
1588 let ciphertext = des2.encrypt_u64(plaintext);
1589 println!("Plaintext:\t\t{:#018X}", plaintext);
1590 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1591 assert_eq!(ciphertext, 0xDE76DF630C033919_u64);
1592
1593 let cipher_cipher_text = des1.encrypt_u64(ciphertext);
1594 println!("Cipher-ciphertext:\t{:#018X}\n", cipher_cipher_text);
1595 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1596 assert_eq!(cipher_cipher_text, plaintext);
1597 // So, you can't use the semi-weak keys 0xFEF1FEF1FEE0FEE0 and 0xF1FEF1FEE0FEE0FE!!!
1598 println!("-------------------------------");
1599}
1600
1601fn des_turn_inverse()
1602{
1603 println!("des_turn_inverse");
1604 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1605
1606 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1607 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1608 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1609 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1610 keys[1].turn_inverse();
1611
1612 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1613 let plaintext = 0x_1234567890ABCDEF_u64;
1614 let ciphertext = tdes.encrypt_u64(plaintext);
1615
1616 println!("Plaintext:\t\t{:#018X}", plaintext);
1617 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1618 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1619
1620 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1621 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1622 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1623 assert_eq!(cipher_cipher_text, plaintext);
1624 println!();
1625
1626
1627 // Operators
1628 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1629 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1630 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1631 des2.turn_inverse();
1632
1633 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1634 let plaintext = 0x_1234567890ABCDEF_u64;
1635 let ciphertext = tdes.encrypt_u64(plaintext);
1636
1637 println!("Plaintext:\t\t{:#018X}", plaintext);
1638 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1639 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1640
1641 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1642 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1643 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1644 assert_eq!(cipher_cipher_text, plaintext);
1645 println!("-------------------------------");
1646}
1647
1648fn des_turn_encryptor()
1649{
1650 println!("des_turn_encryptor");
1651 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1652
1653 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1654 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1655 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1656 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1657 keys[0].turn_encryptor();
1658
1659 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1660 let plaintext = 0x_1234567890ABCDEF_u64;
1661 let ciphertext = tdes.encrypt_u64(plaintext);
1662
1663 println!("Plaintext:\t\t{:#018X}", plaintext);
1664 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1665 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1666
1667 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1668 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1669 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1670 assert_eq!(cipher_cipher_text, plaintext);
1671 println!();
1672
1673
1674 // Operators
1675 let mut des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1676 let des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1677 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1678 des1.turn_encryptor();
1679
1680 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1681 let plaintext = 0x_1234567890ABCDEF_u64;
1682 let ciphertext = tdes.encrypt_u64(plaintext);
1683
1684 println!("Plaintext:\t\t{:#018X}", plaintext);
1685 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1686 assert_eq!(ciphertext, 0x_CDAC175F3B7EAA2B_u64);
1687
1688 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1689 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1690 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1691 assert_eq!(cipher_cipher_text, plaintext);
1692 println!("-------------------------------");
1693}
1694
1695fn des_turn_decryptor()
1696{
1697 println!("des_turn_decryptor");
1698 use cryptocol::symmetric::{ BigCryptor64, DES, SmallCryptor };
1699
1700 let mut keys: [Box<dyn SmallCryptor<u64, 8>>; 3]
1701 = [ Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)),
1702 Box::new(DES::new_with_key_u64(0x_FEDCBA0987654321_u64)),
1703 Box::new(DES::new_with_key_u64(0x_1234567890ABCDEF_u64)) ];
1704 keys[1].turn_decryptor();
1705
1706 let mut tdes = BigCryptor64::new_with_small_cryptor_array(keys);
1707 let plaintext = 0x_1234567890ABCDEF_u64;
1708 let ciphertext = tdes.encrypt_u64(plaintext);
1709
1710 println!("Plaintext:\t\t{:#018X}", plaintext);
1711 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1712 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1713
1714 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1715 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1716 assert_eq!(cipher_cipher_text, 0x1234567890ABCDEF_u64);
1717 assert_eq!(cipher_cipher_text, plaintext);
1718 println!();
1719
1720
1721 // Operators
1722 let des1 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1723 let mut des2 = DES::new_with_key_u64(0x_FEDCBA0987654321_u64);
1724 let des3 = DES::new_with_key_u64(0x_1234567890ABCDEF_u64);
1725 des2.turn_decryptor();
1726
1727 let mut tdes = BigCryptor64::new() + des1 + des2 + des3;
1728 let plaintext = 0x_1234567890ABCDEF_u64;
1729 let ciphertext = tdes.encrypt_u64(plaintext);
1730
1731 println!("Plaintext:\t\t{:#018X}", plaintext);
1732 println!("Ciphertext:\t\t{:#018X}", ciphertext);
1733 assert_eq!(ciphertext, 0x_272A2AC7B4E66748_u64);
1734
1735 let cipher_cipher_text = tdes.decrypt_u64(ciphertext);
1736 println!("Cipher-ciphertext:\t{:#018X}", cipher_cipher_text);
1737 assert_eq!(cipher_cipher_text, 0x_1234567890ABCDEF_u64);
1738 assert_eq!(cipher_cipher_text, plaintext);
1739 println!("-------------------------------");
1740}
1741
1742fn des_encrypt_decrypt_u64_array_u64_main()
1743{
1744 des_encrypt_u64();
1745 des_decrypt_u64();
1746 // des__encrypt();
1747 // des__decrypt();
1748 des_encrypt_array_u64();
1749 des_decrypt_array_u64();
1750 des_is_successful();
1751 des_is_failed();
1752 // des_set_successful();
1753 // des_set_failed();
1754 des_has_weak_key();
1755}
1756
1757fn des_encrypt_u64()
1758{
1759 println!("des_encrypt_u64");
1760 use cryptocol::symmetric::{ DES, DES_Expanded };
1761
1762 // Normal case
1763 let key = 0x_1234567890ABCDEF_u64;
1764 println!("K =\t{:#018X}", key);
1765
1766 let message = 0x_1234567890ABCDEF_u64;
1767 println!("M_u64 =\t{:#018X}", message);
1768
1769 let mut a_des = DES::new_with_key_u64(key);
1770 let cipher = a_des.encrypt_u64(message);
1771 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1772 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1773 println!();
1774
1775 // Expanded case for 128 rounds
1776 let key = 0x_1234567890ABCDEF_u64;
1777 println!("K =\t{:#018X}", key);
1778
1779 let message = 0x_1234567890ABCDEF_u64;
1780 println!("M_u64 =\t{:#018X}", message);
1781
1782 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1783 let cipher = b_des.encrypt_u64(message);
1784 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1785 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1786 println!();
1787
1788 // Expanded case for 0 rounds which means that key is meaningless
1789 let key1 = 0x_1234567890ABCDEF_u64;
1790 let key2 = 0_u64;
1791 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1792 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1793 println!("K1 =\t{:#016x}", key1);
1794
1795 let message = 0x_1234567890ABCDEF_u64;
1796 println!("M_u64 =\t{:#018X}", message);
1797
1798 let cipher1 = c_des.encrypt_u64(message);
1799 let cipher2 = d_des.encrypt_u64(message);
1800 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1801 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1802
1803 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1804 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1805 assert_eq!(cipher1, cipher2);
1806 println!("-------------------------------");
1807}
1808
1809fn des_decrypt_u64()
1810{
1811 println!("des_decrypt_u64");
1812 use cryptocol::symmetric::{ DES, DES_Expanded };
1813
1814 // Normal case
1815 let key = 0x_1234567890ABCDEF_u64;
1816 println!("K =\t{:#018X}", key);
1817
1818 let message = 0x_1234567890ABCDEF_u64;
1819 println!("M_u64 =\t{:#018X}", message);
1820
1821 let mut a_des = DES::new_with_key_u64(key);
1822 let cipher = a_des.encrypt_u64(message);
1823 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1824 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1825
1826 let recovered = a_des.decrypt_u64(cipher);
1827 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1828 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1829 assert_eq!(recovered, message);
1830 println!();
1831
1832 // Expanded case for 128 rounds
1833 let key = 0x_1234567890ABCDEF_u64;
1834 println!("K =\t{:#018X}", key);
1835
1836 let message = 0x_1234567890ABCDEF_u64;
1837 println!("M_u64 =\t{:#018X}", message);
1838
1839 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1840 let cipher = b_des.encrypt_u64(message);
1841 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1842 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1843
1844 let recovered = b_des.decrypt_u64(cipher);
1845 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1846 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1847 assert_eq!(recovered, message);
1848 println!();
1849
1850 // Expanded case for 0 rounds which means that key is meaningless
1851 let key1 = 0x_1234567890ABCDEF_u64;
1852 let key2 = 0_u64;
1853 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1854 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1855 println!("K =\t{:#018X}", key);
1856
1857 let message = 0x_1234567890ABCDEF_u64;
1858 println!("M_u64 =\t{:#018X}", message);
1859
1860 let cipher1 = c_des.encrypt_u64(message);
1861 let cipher2 = d_des.encrypt_u64(message);
1862 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1863 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1864
1865 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1866 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1867 assert_eq!(cipher1, cipher2);
1868
1869 let recovered1 = c_des.decrypt_u64(cipher1);
1870 let recovered2 = d_des.decrypt_u64(cipher2);
1871 println!("B1_u64 (0 rounds) =\t{:#018X}", recovered1);
1872 println!("B2_u64 (0 rounds) =\t{:#018X}", recovered2);
1873 assert_eq!(recovered1, 0x_1234567890ABCDEF_u64);
1874 assert_eq!(recovered1, message);
1875 assert_eq!(recovered2, 0x_1234567890ABCDEF_u64);
1876 assert_eq!(recovered2, message);
1877 assert_eq!(recovered1, recovered2);
1878 println!("-------------------------------");
1879}Sourcepub fn decrypt_u64(&mut self, cipher: u64) -> u64
pub fn decrypt_u64(&mut self, cipher: u64) -> u64
Decrypts a 64-bit data.
§Arguments
cioher is of u64-type and the ciphertext to be decrypted.
§Output
This method returns the decrypted data of u64-type from cipher.
§Counterpart Methods
For each trait
ECB_PKCS7,
ECB_ISO,
CBC_PKCS7,
CBC_ISO,
PCBC_PKCS7,
PCBC_ISO.
CFB,
OFB, and
CTR,
there are provided useful counterpart methods:
decrypt(), decrypt_into_vec(), decrypt_into_array(),
decrypt_into_string(),
decrypt_vec(), decrypt_vec_into_vec(), decrypt_vec_into_array(),
decrypt_vec_into_string(),
decrypt_array(), decrypt_array_into_vec(), decrypt_array_into_array(),
and decrypt_array_into_string().
§Example 1 for Normal case
use cryptocol::symmetric::DES;
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#018X}", key);
let message = 0x_1234567890ABCDEF_u64;
println!("M_u64 =\t{:#018X}", message);
let mut a_des = DES::new_with_key_u64(key);
let cipher = a_des.encrypt_u64(message);
println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
let recovered = a_des.decrypt_u64(cipher);
println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
assert_eq!(recovered, message);§For more examples,
click here
Examples found in repository?
1809fn des_decrypt_u64()
1810{
1811 println!("des_decrypt_u64");
1812 use cryptocol::symmetric::{ DES, DES_Expanded };
1813
1814 // Normal case
1815 let key = 0x_1234567890ABCDEF_u64;
1816 println!("K =\t{:#018X}", key);
1817
1818 let message = 0x_1234567890ABCDEF_u64;
1819 println!("M_u64 =\t{:#018X}", message);
1820
1821 let mut a_des = DES::new_with_key_u64(key);
1822 let cipher = a_des.encrypt_u64(message);
1823 println!("C_u64 (16 rounds) =\t{:#018X}", cipher);
1824 assert_eq!(cipher, 0x_1BC4896735BBE206_u64);
1825
1826 let recovered = a_des.decrypt_u64(cipher);
1827 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1828 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1829 assert_eq!(recovered, message);
1830 println!();
1831
1832 // Expanded case for 128 rounds
1833 let key = 0x_1234567890ABCDEF_u64;
1834 println!("K =\t{:#018X}", key);
1835
1836 let message = 0x_1234567890ABCDEF_u64;
1837 println!("M_u64 =\t{:#018X}", message);
1838
1839 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
1840 let cipher = b_des.encrypt_u64(message);
1841 println!("C_u64 (128 rounds) =\t{:#018X}", cipher);
1842 assert_eq!(cipher, 0x_21F25F81CE4D4AA3_u64);
1843
1844 let recovered = b_des.decrypt_u64(cipher);
1845 println!("B_u64 (16 rounds) =\t{:#018X}", recovered);
1846 assert_eq!(recovered, 0x_1234567890ABCDEF_u64);
1847 assert_eq!(recovered, message);
1848 println!();
1849
1850 // Expanded case for 0 rounds which means that key is meaningless
1851 let key1 = 0x_1234567890ABCDEF_u64;
1852 let key2 = 0_u64;
1853 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
1854 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
1855 println!("K =\t{:#018X}", key);
1856
1857 let message = 0x_1234567890ABCDEF_u64;
1858 println!("M_u64 =\t{:#018X}", message);
1859
1860 let cipher1 = c_des.encrypt_u64(message);
1861 let cipher2 = d_des.encrypt_u64(message);
1862 println!("C_u64 (0 rounds) =\t{:#018X}", cipher1);
1863 assert_eq!(cipher1, 0x_2138A9B46057CEDF_u64);
1864
1865 println!("D_u64 (0 rounds) =\t{:#018X}", cipher);
1866 assert_eq!(cipher2, 0x_2138A9B46057CEDF_u64);
1867 assert_eq!(cipher1, cipher2);
1868
1869 let recovered1 = c_des.decrypt_u64(cipher1);
1870 let recovered2 = d_des.decrypt_u64(cipher2);
1871 println!("B1_u64 (0 rounds) =\t{:#018X}", recovered1);
1872 println!("B2_u64 (0 rounds) =\t{:#018X}", recovered2);
1873 assert_eq!(recovered1, 0x_1234567890ABCDEF_u64);
1874 assert_eq!(recovered1, message);
1875 assert_eq!(recovered2, 0x_1234567890ABCDEF_u64);
1876 assert_eq!(recovered2, message);
1877 assert_eq!(recovered1, recovered2);
1878 println!("-------------------------------");
1879}Sourcepub fn encrypt_array_u64<const N: usize>(
&mut self,
message: &[u64; N],
cipher: &mut [u64; N],
)
pub fn encrypt_array_u64<const N: usize>( &mut self, message: &[u64; N], cipher: &mut [u64; N], )
Encrypts an array of 64-bit data.
§Arguments
messageis of an array ofu64-type and the plaintext to be encrypted.cipheris of an array ofu64-type and the ciphertext to be stored.
§Features
This method encrypts multiple of 64-bit data without padding anything in ECB (Electronic CodeBook) mode.
§Counterpart methods
For each trait
ECB_PKCS7,
ECB_ISO,
CBC_PKCS7,
CBC_ISO,
PCBC_PKCS7,
PCBC_ISO.
CFB,
OFB, and
CTR,
there are provided useful counterpart methods:
encrypt(), encrypt_into_vec(), encrypt_into_array(),
encrypt_str(), encrypt_str_into_vec(), encrypt_str_into_array(),
encrypt_string(), encrypt_string_into_vec(), encrypt_string_into_array(),
encrypt_vec(), encrypt_vec_into_vec(), encrypt_vec_into_array(),
encrypt_array(), encrypt_array_into_vec(), and encrypt_array_into_array(),.
§Example 1 for Normal case
use cryptocol::symmetric::DES;
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#018X}", key);
let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
print!("M =\t");
for m in message
{ print!("{:#018X} ", m); }
println!();
let mut a_des = DES::new_with_key_u64(key);
let mut cipher = [0; 3];
a_des.encrypt_array_u64(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher
{ print!("{:#018X} ", c); }
println!();
assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
assert_eq!(cipher[2], 0x_2990D69525C17067_u64);§For more examples,
click here
Examples found in repository?
2006fn des_encrypt_array_u64()
2007{
2008 println!("des_encrypt_array_u64");
2009 use cryptocol::symmetric::{ DES, DES_Expanded };
2010
2011 // Normal case
2012 let key = 0x_1234567890ABCDEF_u64;
2013 println!("K =\t{:#018X}", key);
2014
2015 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2016 print!("M =\t");
2017 for m in message
2018 { print!("{:#018X} ", m); }
2019 println!();
2020 let mut a_des = DES::new_with_key_u64(key);
2021
2022 let mut cipher = [0; 3];
2023 a_des.encrypt_array_u64(&message, &mut cipher);
2024 print!("C (16 rounds) =\t");
2025 for c in cipher
2026 { print!("{:#018X} ", c); }
2027 println!();
2028 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2029 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2030 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2031 println!();
2032
2033 // Expanded case for 128 rounds
2034 let key = 0x_1234567890ABCDEF_u64;
2035 println!("K =\t{:#018X}", key);
2036
2037 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2038 print!("M =\t");
2039 for m in message
2040 { print!("{:#018X} ", m); }
2041 println!();
2042 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2043
2044 let mut cipher = [0; 3];
2045 b_des.encrypt_array_u64(&message, &mut cipher);
2046 print!("C (128 rounds) =\t");
2047 for c in cipher
2048 { print!("{:#018X} ", c); }
2049 println!();
2050 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2051 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2052 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2053 println!();
2054
2055
2056 // Expanded case for 0 rounds which means that key is meaningless
2057 let key1 = 0x_1234567890ABCDEF_u64;
2058 let key2 = 0_u64;
2059 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2060 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2061 println!("K =\t{:#018X}", key);
2062
2063 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2064 print!("M =\t");
2065 for m in message
2066 { print!("{:#018X} ", m); }
2067 println!();
2068
2069 let mut cipher1 = [0; 3];
2070 let mut cipher2 = [0; 3];
2071 c_des.encrypt_array_u64(&message, &mut cipher1);
2072 d_des.encrypt_array_u64(&message, &mut cipher2);
2073 print!("C (0 rounds) =\t");
2074 for c in cipher1
2075 { print!("{:#018X} ", c); }
2076 println!();
2077 print!("D (0 rounds) =\t");
2078 for c in cipher2
2079 { print!("{:#018X} ", c); }
2080 println!();
2081 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2082 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2083 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2084 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2085 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2086 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2087 assert_eq!(cipher1[0], cipher2[0]);
2088 assert_eq!(cipher1[1], cipher2[1]);
2089 assert_eq!(cipher1[2], cipher2[2]);
2090 println!("-------------------------------");
2091}
2092
2093fn des_decrypt_array_u64()
2094{
2095 println!("des_decrypt_array_u64");
2096 use cryptocol::symmetric::{ DES, DES_Expanded };
2097
2098 // Normal case
2099 let key = 0x_1234567890ABCDEF_u64;
2100 println!("K =\t{:#018X}", key);
2101
2102 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2103 print!("M =\t");
2104 for m in message
2105 { print!("{:#018X} ", m); }
2106 println!();
2107 let mut a_des = DES::new_with_key_u64(key);
2108
2109 let mut cipher = [0; 3];
2110 a_des.encrypt_array_u64(&message, &mut cipher);
2111 print!("C (16 rounds) =\t");
2112 for c in cipher
2113 { print!("{:#018X} ", c); }
2114 println!();
2115 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2116 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2117 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2118
2119 let mut recovered = [0; 3];
2120 a_des.decrypt_array_u64(&cipher, &mut recovered);
2121 print!("B (16 rounds) =\t");
2122 for r in recovered
2123 { print!("{:#018X} ", r); }
2124 println!();
2125 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2126 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2127 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2128 println!();
2129
2130 // Expanded case for 128 rounds
2131 let key = 0x_1234567890ABCDEF_u64;
2132 println!("K =\t{:#018X}", key);
2133
2134 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2135 print!("M =\t");
2136 for m in message
2137 { print!("{:#018X} ", m); }
2138 println!();
2139 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2140
2141 let mut cipher = [0; 3];
2142 b_des.encrypt_array_u64(&message, &mut cipher);
2143 print!("C (128 rounds) =\t");
2144 for c in cipher
2145 { print!("{:#018X} ", c); }
2146 println!();
2147 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2148 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2149 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2150
2151 let mut recovered = [0; 3];
2152 b_des.decrypt_array_u64(&cipher, &mut recovered);
2153 print!("B (128 rounds) =\t");
2154 for r in recovered
2155 { print!("{:#018X} ", r); }
2156 println!();
2157 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2158 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2159 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2160
2161 // Expanded case for 0 rounds which means that key is meaningless
2162 let key1 = 0x_1234567890ABCDEF_u64;
2163 let key2 = 0_u64;
2164 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2165 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2166 println!("K =\t{:#018X}", key);
2167
2168 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2169 print!("M =\t");
2170 for m in message
2171 { print!("{:#018X} ", m); }
2172 println!();
2173
2174 let mut cipher1 = [0; 3];
2175 let mut cipher2 = [0; 3];
2176 c_des.encrypt_array_u64(&message, &mut cipher1);
2177 d_des.encrypt_array_u64(&message, &mut cipher2);
2178 print!("C (0 rounds) =\t");
2179 for c in cipher1
2180 { print!("{:#018X} ", c); }
2181 println!();
2182 print!("D (0 rounds) =\t");
2183 for c in cipher2
2184 { print!("{:#018X} ", c); }
2185 println!();
2186 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2187 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2188 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2189 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2190 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2191 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2192 assert_eq!(cipher1[0], cipher2[0]);
2193 assert_eq!(cipher1[1], cipher2[1]);
2194 assert_eq!(cipher1[2], cipher2[2]);
2195
2196 let mut recovered1 = [0; 3];
2197 let mut recovered2 = [0; 3];
2198 c_des.decrypt_array_u64(&cipher1, &mut recovered1);
2199 d_des.decrypt_array_u64(&cipher2, &mut recovered2);
2200 print!("B1 (0 rounds) =\t");
2201 for r in recovered1
2202 { print!("{:#018X} ", r); }
2203 println!();
2204 print!("B2 (0 rounds) =\t");
2205 for r in recovered2
2206 { print!("{:#018X} ", r); }
2207 println!();
2208 assert_eq!(recovered1[0], 0x_1234567890ABCDEF_u64);
2209 assert_eq!(recovered1[1], 0x_EFCDAB9078563412_u64);
2210 assert_eq!(recovered1[2], 0x_FEDCBA0987654321_u64);
2211 assert_eq!(recovered2[0], 0x_1234567890ABCDEF_u64);
2212 assert_eq!(recovered2[1], 0x_EFCDAB9078563412_u64);
2213 assert_eq!(recovered2[2], 0x_FEDCBA0987654321_u64);
2214 assert_eq!(recovered1[0], recovered2[0]);
2215 assert_eq!(recovered1[1], recovered2[1]);
2216 assert_eq!(recovered1[2], recovered2[2]);
2217 println!("-------------------------------");
2218}Sourcepub fn decrypt_array_u64<const N: usize>(
&mut self,
cipher: &[u64; N],
message: &mut [u64; N],
)
pub fn decrypt_array_u64<const N: usize>( &mut self, cipher: &[u64; N], message: &mut [u64; N], )
Decrypts an array of 64-bit data.
§Arguments
cipheris of an array ofu64-type and the ciphertext to be decrypted.messageis of an array ofu64-type and the plaintext to be stored.
§Features
This method decrypts multiple of 64-bit data without padding anything in ECB (Electronic CodeBook) mode.
§Counterpart Methods
For each trait
ECB_PKCS7,
ECB_ISO,
CBC_PKCS7,
CBC_ISO,
PCBC_PKCS7,
PCBC_ISO.
CFB,
OFB, and
CTR,
there are provided useful counterpart methods:
decrypt(), decrypt_into_vec(), decrypt_into_array(),
decrypt_into_string(),
decrypt_vec(), decrypt_vec_into_vec(), decrypt_vec_into_array(),
decrypt_vec_into_string(),
decrypt_array(), decrypt_array_into_vec(), decrypt_array_into_array(),
and decrypt_array_into_string().
§Example 1 for Normal case
use cryptocol::symmetric::DES;
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#018X}", key);
let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
print!("M =\t");
for m in message
{ print!("{:#018X} ", m); }
println!();
let mut a_des = DES::new_with_key_u64(key);
let mut cipher = [0; 3];
a_des.encrypt_array_u64(&message, &mut cipher);
print!("C (16 rounds) =\t");
for c in cipher
{ print!("{:#018X} ", c); }
println!();
assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
let mut recovered = [0; 3];
a_des.decrypt_array_u64(&cipher, &mut recovered);
print!("B (16 rounds) =\t");
for r in recovered
{ print!("{:#018X} ", r); }
println!();
assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);§For more examples,
click here
Examples found in repository?
2093fn des_decrypt_array_u64()
2094{
2095 println!("des_decrypt_array_u64");
2096 use cryptocol::symmetric::{ DES, DES_Expanded };
2097
2098 // Normal case
2099 let key = 0x_1234567890ABCDEF_u64;
2100 println!("K =\t{:#018X}", key);
2101
2102 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2103 print!("M =\t");
2104 for m in message
2105 { print!("{:#018X} ", m); }
2106 println!();
2107 let mut a_des = DES::new_with_key_u64(key);
2108
2109 let mut cipher = [0; 3];
2110 a_des.encrypt_array_u64(&message, &mut cipher);
2111 print!("C (16 rounds) =\t");
2112 for c in cipher
2113 { print!("{:#018X} ", c); }
2114 println!();
2115 assert_eq!(cipher[0], 0x_1BC4896735BBE206_u64);
2116 assert_eq!(cipher[1], 0x_1D8A61E5E62226A4_u64);
2117 assert_eq!(cipher[2], 0x_2990D69525C17067_u64);
2118
2119 let mut recovered = [0; 3];
2120 a_des.decrypt_array_u64(&cipher, &mut recovered);
2121 print!("B (16 rounds) =\t");
2122 for r in recovered
2123 { print!("{:#018X} ", r); }
2124 println!();
2125 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2126 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2127 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2128 println!();
2129
2130 // Expanded case for 128 rounds
2131 let key = 0x_1234567890ABCDEF_u64;
2132 println!("K =\t{:#018X}", key);
2133
2134 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2135 print!("M =\t");
2136 for m in message
2137 { print!("{:#018X} ", m); }
2138 println!();
2139 let mut b_des = DES_Expanded::<128, 0x_8103_8103_8103_8103_8103_8103_8103_8103_u128>::new_with_key_u64(key);
2140
2141 let mut cipher = [0; 3];
2142 b_des.encrypt_array_u64(&message, &mut cipher);
2143 print!("C (128 rounds) =\t");
2144 for c in cipher
2145 { print!("{:#018X} ", c); }
2146 println!();
2147 assert_eq!(cipher[0], 0x_21F25F81CE4D4AA3_u64);
2148 assert_eq!(cipher[1], 0x_352F391A1482A504_u64);
2149 assert_eq!(cipher[2], 0x_F793546957AFDE50_u64);
2150
2151 let mut recovered = [0; 3];
2152 b_des.decrypt_array_u64(&cipher, &mut recovered);
2153 print!("B (128 rounds) =\t");
2154 for r in recovered
2155 { print!("{:#018X} ", r); }
2156 println!();
2157 assert_eq!(recovered[0], 0x_1234567890ABCDEF_u64);
2158 assert_eq!(recovered[1], 0x_EFCDAB9078563412_u64);
2159 assert_eq!(recovered[2], 0x_FEDCBA0987654321_u64);
2160
2161 // Expanded case for 0 rounds which means that key is meaningless
2162 let key1 = 0x_1234567890ABCDEF_u64;
2163 let key2 = 0_u64;
2164 let mut c_des = DES_Expanded::<0, 0>::new_with_key_u64(key1);
2165 let mut d_des = DES_Expanded::<0, 0>::new_with_key_u64(key2);
2166 println!("K =\t{:#018X}", key);
2167
2168 let message = [0x_1234567890ABCDEF_u64, 0xEFCDAB9078563412, 0xFEDCBA0987654321 ];
2169 print!("M =\t");
2170 for m in message
2171 { print!("{:#018X} ", m); }
2172 println!();
2173
2174 let mut cipher1 = [0; 3];
2175 let mut cipher2 = [0; 3];
2176 c_des.encrypt_array_u64(&message, &mut cipher1);
2177 d_des.encrypt_array_u64(&message, &mut cipher2);
2178 print!("C (0 rounds) =\t");
2179 for c in cipher1
2180 { print!("{:#018X} ", c); }
2181 println!();
2182 print!("D (0 rounds) =\t");
2183 for c in cipher2
2184 { print!("{:#018X} ", c); }
2185 println!();
2186 assert_eq!(cipher1[0], 0x_2138A9B46057CEDF_u64);
2187 assert_eq!(cipher1[1], 0x_DFCE5760B4A93821_u64);
2188 assert_eq!(cipher1[2], 0x_FDEC75064B9A8312_u64);
2189 assert_eq!(cipher2[0], 0x_2138A9B46057CEDF_u64);
2190 assert_eq!(cipher2[1], 0x_DFCE5760B4A93821_u64);
2191 assert_eq!(cipher2[2], 0x_FDEC75064B9A8312_u64);
2192 assert_eq!(cipher1[0], cipher2[0]);
2193 assert_eq!(cipher1[1], cipher2[1]);
2194 assert_eq!(cipher1[2], cipher2[2]);
2195
2196 let mut recovered1 = [0; 3];
2197 let mut recovered2 = [0; 3];
2198 c_des.decrypt_array_u64(&cipher1, &mut recovered1);
2199 d_des.decrypt_array_u64(&cipher2, &mut recovered2);
2200 print!("B1 (0 rounds) =\t");
2201 for r in recovered1
2202 { print!("{:#018X} ", r); }
2203 println!();
2204 print!("B2 (0 rounds) =\t");
2205 for r in recovered2
2206 { print!("{:#018X} ", r); }
2207 println!();
2208 assert_eq!(recovered1[0], 0x_1234567890ABCDEF_u64);
2209 assert_eq!(recovered1[1], 0x_EFCDAB9078563412_u64);
2210 assert_eq!(recovered1[2], 0x_FEDCBA0987654321_u64);
2211 assert_eq!(recovered2[0], 0x_1234567890ABCDEF_u64);
2212 assert_eq!(recovered2[1], 0x_EFCDAB9078563412_u64);
2213 assert_eq!(recovered2[2], 0x_FEDCBA0987654321_u64);
2214 assert_eq!(recovered1[0], recovered2[0]);
2215 assert_eq!(recovered1[1], recovered2[1]);
2216 assert_eq!(recovered1[2], recovered2[2]);
2217 println!("-------------------------------");
2218}Sourcepub fn is_successful(&self) -> bool
pub fn is_successful(&self) -> bool
Checks whether the previous encryption or decryption was successful.
§Output
If the previous encryption or decryption was successful, this method returns true. Otherwise, it returns false.
§Features
- Usually, you don’t have to use this method because the encryption
methods returns the length of ciphertext and the decryption methods
returns the length of plaintext but they returns
0when they failed. - If the ciphertext is 8 bytes for decryption with the padding either
pkcs7 or iso, the return value
0of the decryption methods is not discriminatory. You don’t know whether the previous decryption was failed or the original plaintext was just null string or “”. In this case you can check its success with this method.
§Example 1 for Normal case for the message of 0 bytes
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_PKCS7 };
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#018X}", key);
let mut a_des = DES::new_with_key_u64(key);
let message = "";
println!("M =\t{}", message);
let mut cipher = [0_u8; 8];
let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
println!("The length of ciphertext = {}", len);
assert_eq!(len, 8);
let success = a_des.is_successful();
assert_eq!(success, true);
print!("C =\t");
for c in cipher.clone()
{ print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
{ write!(txt, "{:02X} ", c); }
assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");§For more examples,
click here
Examples found in repository?
2220fn des_is_successful()
2221{
2222 println!("des_is_successful");
2223 use std::io::Write;
2224 use std::fmt::Write as _;
2225 use cryptocol::symmetric::DES;
2226
2227 {
2228 use cryptocol::symmetric::ECB_PKCS7;
2229
2230 // Successful case for the message of 0 bytes
2231 let key = 0x_1234567890ABCDEF_u64;
2232 println!("K =\t{:#018X}", key);
2233 let mut a_des = DES::new_with_key_u64(key);
2234 let message = "";
2235 println!("M =\t{}", message);
2236 let mut cipher = [0_u8; 8];
2237 let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
2238 println!("The length of ciphertext = {}", len);
2239 assert_eq!(len, 8);
2240 let success = a_des.is_successful();
2241 assert_eq!(success, true);
2242 print!("C =\t");
2243 for c in cipher.clone()
2244 { print!("{:02X} ", c); }
2245 println!();
2246 let mut txt = String::new();
2247 for c in cipher.clone()
2248 { write!(txt, "{:02X} ", c); }
2249 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2250 println!();
2251
2252 // Successful case for the original message of 0 bytes
2253 let key = 0x_1234567890ABCDEF_u64;
2254 println!("K =\t{:#018X}", key);
2255 let mut a_des = DES::new_with_key_u64(key);
2256
2257 let cipher = [0x41u8, 0x7F, 0x89, 0x79, 0x08, 0xCD, 0xA1, 0x4C];
2258 print!("C =\t");
2259 for c in cipher.clone()
2260 { print!("{:02X} ", c); }
2261 println!();
2262 let mut recovered = [0u8; 8];
2263 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
2264 println!("The length of plaintext = {}", len);
2265 assert_eq!(len, 0);
2266 let success = a_des.is_successful();
2267 assert_eq!(success, true);
2268 print!("Ba =\t");
2269 for b in recovered.clone()
2270 { print!("{:02X} ", b); }
2271 println!();
2272 let mut txt = String::new();
2273 for c in recovered.clone()
2274 { write!(txt, "{:02X} ", c); }
2275 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2276
2277 let mut converted = String::new();
2278 unsafe { converted.as_mut_vec() }.write(&recovered);
2279 unsafe { converted.as_mut_vec() }.truncate(len as usize);
2280 println!("Bb =\t{}", converted);
2281 assert_eq!(converted, "");
2282 assert_eq!(converted, message);
2283 println!();
2284 }
2285
2286 {
2287 use cryptocol::symmetric::CBC_ISO;
2288
2289 // Failure case for the message of 0 bytes
2290 let iv = 0x_FEDCBA0987654321_u64;
2291 println!("IV = {}", iv);
2292 let key = 0x_1234567890ABCDEF_u64;
2293 println!("K =\t{:#018X}", key);
2294 let mut a_des = DES::new_with_key_u64(key);
2295 let message = "";
2296 println!("M =\t{}", message);
2297 let mut cipher = [0_u8; 4];
2298 let len = a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
2299 println!("The length of ciphertext = {}", len);
2300 assert_eq!(len, 0);
2301 let success = a_des.is_successful();
2302 assert_eq!(success, false);
2303 print!("C =\t");
2304 for c in cipher.clone()
2305 { print!("{:02X} ", c); }
2306 println!();
2307 let mut txt = String::new();
2308 for c in cipher.clone()
2309 { write!(txt, "{:02X} ", c); }
2310 assert_eq!(txt, "00 00 00 00 ");
2311 println!();
2312
2313 // Failed case for decryption
2314 let iv = 0x_FEDCBA0987654321_u64;
2315 println!("IV = {}", iv);
2316 let key = 0x_1234567890ABCDEF_u64;
2317 println!("K =\t{:#018X}", key);
2318 let mut a_des = DES::new_with_key_u64(key);
2319
2320 let cipher = [0u8; 4];
2321 print!("C =\t");
2322 for c in cipher.clone()
2323 { print!("{:02X} ", c); }
2324 println!();
2325 let mut recovered = [0u8; 8];
2326 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
2327 println!("The length of plaintext = {}", len);
2328 assert_eq!(len, 0);
2329 let success = a_des.is_successful();
2330 assert_eq!(success, false);
2331 }
2332 println!("-------------------------------");
2333}Sourcepub fn is_failed(&self) -> bool
pub fn is_failed(&self) -> bool
Checks whether the previous encryption or decryption was failed.
§Output
If the previous encryption or decryption was failed, this method returns true. Otherwise, it returns false.
§Features
- Usually, you don’t have to use this method because the encryption
methods returns the length of ciphertext and the decryption methods
returns the length of plaintext but they returns
0when they failed. - If the ciphertext is 8 bytes for decryption with the padding either
pkcs7 or iso, the return value
0of the decryption methods is not discriminatory. You don’t know whether the previous decryption was failed or the original plaintext was just null string or “”. In this case you can check its success with this method.
§Example 1 for Normal case for the message of 0 bytes
use std::io::Write;
use std::fmt::Write as _;
use cryptocol::symmetric::{ DES, ECB_PKCS7 };
let key = 0x_1234567890ABCDEF_u64;
println!("K =\t{:#018X}", key);
let mut a_des = DES::new_with_key_u64(key);
let message = "";
println!("M =\t{}", message);
let mut cipher = [0_u8; 8];
let len = a_des.encrypt_str_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
println!("The length of ciphertext = {}", len);
assert_eq!(len, 8);
let failure = a_des.is_failed();
assert_eq!(failure, false);
print!("C =\t");
for c in cipher.clone()
{ print!("{:02X} ", c); }
println!();
let mut txt = String::new();
for c in cipher.clone()
{ write!(txt, "{:02X} ", c); }
assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");§For more examples,
click here
Examples found in repository?
2335fn des_is_failed()
2336{
2337 println!("des_is_failed");
2338 use std::io::Write;
2339 use std::fmt::Write as _;
2340 use cryptocol::symmetric::DES;
2341
2342 {
2343 use cryptocol::symmetric::ECB_PKCS7;
2344
2345 // Successful case for the message of 0 bytes
2346 let key = 0x_1234567890ABCDEF_u64;
2347 println!("K =\t{:#018X}", key);
2348 let mut a_des = DES::new_with_key_u64(key);
2349 let message = "";
2350 println!("M =\t{}", message);
2351 let mut cipher = [0_u8; 8];
2352 let len = a_des.encrypt_into_array(message.as_ptr(), message.len() as u64, &mut cipher);
2353 println!("The length of ciphertext = {}", len);
2354 assert_eq!(len, 8);
2355 let failure = a_des.is_failed();
2356 assert_eq!(failure, false);
2357 print!("C =\t");
2358 for c in cipher.clone()
2359 { print!("{:02X} ", c); }
2360 println!();
2361 let mut txt = String::new();
2362 for c in cipher.clone()
2363 { write!(txt, "{:02X} ", c); }
2364 assert_eq!(txt, "41 7F 89 79 08 CD A1 4C ");
2365 println!();
2366
2367 // Successful case for the original message of 0 bytes
2368 let key = 0x_1234567890ABCDEF_u64;
2369 println!("K =\t{:#018X}", key);
2370 let mut a_des = DES::new_with_key_u64(key);
2371
2372 let cipher = [0x41u8, 0x7F, 0x89, 0x79, 0x08, 0xCD, 0xA1, 0x4C];
2373 print!("C =\t");
2374 for c in cipher.clone()
2375 { print!("{:02X} ", c); }
2376 println!();
2377 let mut recovered = [0u8; 8];
2378 let len = a_des.decrypt_array_into_array(&cipher, &mut recovered);
2379 println!("The length of plaintext = {}", len);
2380 assert_eq!(len, 0);
2381 let failure = a_des.is_failed();
2382 assert_eq!(failure, false);
2383 print!("Ba =\t");
2384 for b in recovered.clone()
2385 { print!("{:02X} ", b); }
2386 println!();
2387 let mut txt = String::new();
2388 for c in recovered.clone()
2389 { write!(txt, "{:02X} ", c); }
2390 assert_eq!(txt, "00 00 00 00 00 00 00 00 ");
2391
2392 let mut converted = String::new();
2393 unsafe { converted.as_mut_vec() }.write(&recovered);
2394 unsafe { converted.as_mut_vec() }.truncate(len as usize);
2395 println!("Bb =\t{}", converted);
2396 assert_eq!(converted, "");
2397 assert_eq!(converted, message);
2398 println!();
2399 }
2400
2401 {
2402 use cryptocol::symmetric::CBC_ISO;
2403
2404 // Failure case for the message of 0 bytes
2405 let iv = 0x_FEDCBA0987654321_u64;
2406 println!("IV = {}", iv);
2407 let key = 0x_1234567890ABCDEF_u64;
2408 println!("K =\t{:#018X}", key);
2409 let mut a_des = DES::new_with_key_u64(key);
2410 let message = "";
2411 println!("M =\t{}", message);
2412 let mut cipher = [0_u8; 4];
2413 let len = a_des.encrypt_into_array(iv, message.as_ptr(), message.len() as u64, &mut cipher);
2414 println!("The length of ciphertext = {}", len);
2415 assert_eq!(len, 0);
2416 let failure = a_des.is_failed();
2417 assert_eq!(failure, true);
2418 print!("C =\t");
2419 for c in cipher.clone()
2420 { print!("{:02X} ", c); }
2421 println!();
2422 let mut txt = String::new();
2423 for c in cipher.clone()
2424 { write!(txt, "{:02X} ", c); }
2425 assert_eq!(txt, "00 00 00 00 ");
2426 println!();
2427
2428 // Failed case for decryption
2429 let iv = 0x_FEDCBA0987654321_u64;
2430 println!("IV = {}", iv);
2431 let key = 0x_1234567890ABCDEF_u64;
2432 println!("K =\t{:#018X}", key);
2433 let mut a_des = DES::new_with_key_u64(key);
2434
2435 let cipher = [0u8; 4];
2436 print!("C =\t");
2437 for c in cipher.clone()
2438 { print!("{:02X} ", c); }
2439 println!();
2440 let mut recovered = [0u8; 8];
2441 let len = a_des.decrypt_array_into_array(iv, &cipher, &mut recovered);
2442 println!("The length of plaintext = {}", len);
2443 assert_eq!(len, 0);
2444 let failure = a_des.is_failed();
2445 assert_eq!(failure, true);
2446 }
2447 println!("-------------------------------");
2448}Sourcepub fn has_weak_key(&mut self) -> bool
pub fn has_weak_key(&mut self) -> bool
Checks wether or not it has a weak key.
§Output
This method returns true if it has a weak key.
Otherwise, it returns false.
§Example 1 for not weak key
use cryptocol::symmetric::DES;
let key = 0x_1234567890ABCDEF_u64;
let mut a_des = DES::new_with_key_u64(key);
let weak_key = a_des.has_weak_key();
println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
assert_eq!(weak_key, false);§Example 2 for weak key
use cryptocol::symmetric::DES;
let key = 0x_0000000000000000_u64;
a_des.set_key_u64(key);
let weak_key = a_des.has_weak_key();
println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
assert_eq!(weak_key, true);§For more examples,
click here
Examples found in repository?
2475fn des_has_weak_key()
2476{
2477 println!("des_has_weak_key");
2478 use cryptocol::symmetric::DES;
2479
2480 let key = 0x_1234567890ABCDEF_u64;
2481 let mut a_des = DES::new_with_key_u64(key);
2482 let weak_key = a_des.has_weak_key();
2483 println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
2484 assert_eq!(weak_key, false);
2485
2486 let key = 0x_0000000000000000_u64;
2487 a_des.set_key_u64(key);
2488 let weak_key = a_des.has_weak_key();
2489 println!("{:016X} is {}a weak key.", key.to_be(), if weak_key {""} else {"not "});
2490 assert_eq!(weak_key, true);
2491 println!("-------------------------------");
2492}Sourcepub fn is_equivalent_key_u64(&mut self, key: u64) -> bool
pub fn is_equivalent_key_u64(&mut self, key: u64) -> bool
Checks wether or not it key is equivalent to its key.
§Output
This method returns true if it is equivalent to its key.
Otherwise, it returns false.
Trait Implementations§
Source§impl<S, const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> Add<S> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>where
S: SmallCryptor<u64, 8> + 'static,
impl<S, const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> Add<S> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>where
S: SmallCryptor<u64, 8> + 'static,
Source§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CBC_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CBC_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
str object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
iv: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, iv: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str with the padding defined according to
ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, iv: T, message: &str, cipher: &mut [U; N], ) -> u64
str object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
String object with the padding
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
iv: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, iv: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object with the padding
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode,
and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, iv: T, message: &String, cipher: &mut [U; N], ) -> u64
String object with the padding
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, iv: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and
stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and
stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object with the padding
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object with the padding
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and stores the
encrypted data in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, iv: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and
stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and
stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, iv: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str with the padding defined according to
ISO 7816-4 in CBC (Cipher-Block Chaining) mode, and stores the
decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode,
and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode,
and stores the decrypted data in array [V; M]. Read moreSource§fn decrypt_array_into_string<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut String,
) -> u64
fn decrypt_array_into_string<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut String, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in CBC (Cipher-Block Chaining) mode,
and stores the decrypted data in String. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CBC_PKCS7<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CBC_PKCS7<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
str object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
iv: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, iv: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str with the padding defined according to
PKCS #7 in CBC (Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, iv: T, message: &str, cipher: &mut [U; N], ) -> u64
str object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
String object with the padding
according to PKCS #7 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
iv: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, iv: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object with the padding
according to PKCS #7 in CBC (Cipher-Block Chaining) mode,
and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, iv: T, message: &String, cipher: &mut [U; N], ) -> u64
String object with the padding
according to PKCS #7 in CBC (Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, iv: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode, and
stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode, and
stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object with the padding
according to PKCS #7 in CBC (Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object with the padding
according to PKCS #7 in CBC (Cipher-Block Chaining) mode, and stores the
encrypted data in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, iv: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode, and
stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in CBC (Cipher-Block Chaining) mode, and
stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, iv: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str with the padding defined according to
PKCS #7 in CBC (Cipher-Block Chaining) mode, and stores the
decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in CBC (Cipher-Block Chaining) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in CBC (Cipher-Block Chaining) mode,
and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in CBC (Cipher-Block Chaining) mode,
and stores the decrypted data in array [V; M]. Read moreSource§fn decrypt_array_into_string<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut String,
) -> u64
fn decrypt_array_into_string<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut String, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in CBC (Cipher-Block Chaining) mode,
and stores the decrypted data in String. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CFB<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CFB<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
str object without any padding in CFB (Cipher
FeedBack) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
iv: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, iv: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str without any padding in CFB (Cipher FeedBack)
mode, and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, iv: T, message: &str, cipher: &mut [U; N], ) -> u64
str object without any padding in CFB (Cipher
FeedBack) mode, and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
String object without any padding
in CFB (Cipher FeedBack) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
iv: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, iv: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object without any padding in
CFB (Cipher FeedBack) mode, and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, iv: T, message: &String, cipher: &mut [U; N], ) -> u64
String object without any padding in CFB
(Cipher FeedBack) mode, and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object without any padding
in CFB (Cipher FeedBack) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, iv: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object without any padding in
CFB (Cipher FeedBack) mode, and stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object without any padding in CFB
(Cipher FeedBack) mode, and stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object without any
padding in CFB (Cipher FeedBack) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object without any padding
in CFB (Cipher FeedBack) mode, and stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object without any padding
in CFB (Cipher FeedBack) mode, and stores the encrypted data
in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object without any padding
in CFB (Cipher FeedBack) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, iv: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object without any padding in
CFB (Cipher FeedBack) mode, and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object without any padding in CFB
(Cipher FeedBack) mode, and stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, iv: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str without any padding in CFB (Cipher FeedBack)
mode, and stores the decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object without any padding
in CFB (Cipher FeedBack) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object without any padding
in CFB (Cipher FeedBack) mode, and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object without any padding
in CFB (Cipher FeedBack) mode, and stores the decrypted data
in array [V; M]. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CTR<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> CTR<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
nonce: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, nonce: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, nonce: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, nonce: T, message: &str, cipher: *mut u8) -> u64
str object without any padding in CTR (CounTeR) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
nonce: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, nonce: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str without any padding in CTR (CounTeR)
mode, and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
nonce: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, nonce: T, message: &str, cipher: &mut [U; N], ) -> u64
str object without any padding in CTR (CounTeR) mode, and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, nonce: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, nonce: T, message: &String, cipher: *mut u8) -> u64
String object without any padding
in CTR (CounTeR) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
nonce: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, nonce: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object without any padding in
CTR (CounTeR) mode, and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
nonce: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, nonce: T, message: &String, cipher: &mut [U; N], ) -> u64
String object without any padding in CTR
(CounTeR) mode, and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, nonce: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, nonce: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object without any padding
in CTR (CounTeR) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
nonce: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, nonce: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object without any padding in
CTR (CounTeR) mode, and stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
nonce: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, nonce: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object without any padding in CTR
(CounTeR) mode, and stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
nonce: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, nonce: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object without any
padding in CTR (CounTeR) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
nonce: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, nonce: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object without any padding
in CTR (CounTeR) mode, and stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
nonce: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, nonce: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object without any padding
in CTR (CounTeR) mode, and stores the encrypted data
in array [V; M]. Read moreSource§fn decrypt(
&mut self,
nonce: T,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, nonce: T, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn decrypt_into_vec<U>(
&mut self,
nonce: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, nonce: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
nonce: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, nonce: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, nonce: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, nonce: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object without any padding
in CTR (CounTeR) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
nonce: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, nonce: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object without any padding in
CTR (CounTeR) mode, and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
nonce: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, nonce: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object without any padding in CTR
(CounTeR) mode, and stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
nonce: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, nonce: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str without any padding in CTR (CounTeR)
mode, and stores the decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
nonce: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, nonce: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object without any padding
in CTR (CounTeR) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
nonce: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, nonce: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object without any padding
in CTR (CounTeR) mode, and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
nonce: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, nonce: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object without any padding
in CTR (CounTeR) mode, and stores the decrypted data
in array [V; M]. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> Clone for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> Clone for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn clone(
&self,
) -> DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
fn clone( &self, ) -> DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> ECB_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> ECB_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, message: &str, cipher: *mut u8) -> u64
str object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_str_into_vec<U>(&mut self, message: &str, cipher: &mut Vec<U>) -> u64
fn encrypt_str_into_vec<U>(&mut self, message: &str, cipher: &mut Vec<U>) -> u64
str with the padding defined according to
ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the
encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, message: &str, cipher: &mut [U; N], ) -> u64
str object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, message: &String, cipher: *mut u8) -> u64
String object with the padding
according to ISO 7816-4 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, message: &String, cipher: &mut Vec<U>, ) -> u64
String object with the padding
according to ISO 7816-4 in ECB (Electronic CodeBook) mode,
and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, message: &String, cipher: &mut [U; N], ) -> u64
String object with the padding
according to ISO 7816-4 in ECB (Electronic CodeBook) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and
stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and
stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object with the padding
according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the
encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object with the padding
according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the
encrypted data in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and
stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in ECB (Electronic CodeBook) mode, and
stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, cipher: &Vec<U>, message: &mut String, ) -> u64
str with the padding defined according to
ISO 7816-4 in ECB (Electronic CodeBook) mode, and stores the
decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode,
and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in ECB (Electronic CodeBook) mode,
and stores the decrypted data in array [V; M]. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> ECB_PKCS7<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> ECB_PKCS7<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, message: &str, cipher: *mut u8) -> u64
str object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_str_into_vec<U>(&mut self, message: &str, cipher: &mut Vec<U>) -> u64
fn encrypt_str_into_vec<U>(&mut self, message: &str, cipher: &mut Vec<U>) -> u64
str with the padding defined according to
PKCS #7 in ECB (Electronic CodeBook) mode, and stores the
encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, message: &str, cipher: &mut [U; N], ) -> u64
str object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, message: &String, cipher: *mut u8) -> u64
String object with the padding
according to PKCS #7 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, message: &String, cipher: &mut Vec<U>, ) -> u64
String object with the padding
according to PKCS #7 in ECB (Electronic CodeBook) mode,
and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, message: &String, cipher: &mut [U; N], ) -> u64
String object with the padding
according to PKCS #7 in ECB (Electronic CodeBook) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode, and
stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode, and
stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in ECB (Electronic CodeBook) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object with the padding
according to PKCS #7 in ECB (Electronic CodeBook) mode, and stores the
encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object with the padding
according to PKCS #7 in ECB (Electronic CodeBook) mode, and stores the
encrypted data in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode, and
stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in ECB (Electronic CodeBook) mode, and
stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, cipher: &Vec<U>, message: &mut String, ) -> u64
str with the padding defined according to
PKCS #7 in ECB (Electronic CodeBook) mode, and stores the
decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in ECB (Electronic CodeBook) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in ECB (Electronic CodeBook) mode,
and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in ECB (Electronic CodeBook) mode,
and stores the decrypted data in array [V; M]. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> Neg for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> Neg for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§type Output = DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
type Output = DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
- operator.Source§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> OFB<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> OFB<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
str object without any padding in OFB (Output
FeedBack) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
iv: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, iv: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str without any padding in OFB (Output FeedBack)
mode, and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, iv: T, message: &str, cipher: &mut [U; N], ) -> u64
str object without any padding in OFB (Output
FeedBack) mode, and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
String object without any padding
in OFB (Output FeedBack) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
iv: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, iv: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object without any padding in
OFB (Output FeedBack) mode, and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, iv: T, message: &String, cipher: &mut [U; N], ) -> u64
String object without any padding in OFB
(Output FeedBack) mode, and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object without any padding
in OFB (Output FeedBack) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, iv: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object without any padding in
OFB (Output FeedBack) mode, and stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object without any padding in OFB
(Output FeedBack) mode, and stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object without any
padding in OFB (Output FeedBack) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object without any padding
in OFB (Output FeedBack) mode, and stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object without any padding
in OFB (Output FeedBack) mode, and stores the encrypted data
in array [V; M]. Read moreSource§fn decrypt(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn decrypt_into_vec<U>(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object without any padding
in OFB (Output FeedBack) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, iv: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object without any padding in
OFB (Output FeedBack) mode, and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object without any padding in OFB
(Output FeedBack) mode, and stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, iv: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str without any padding in OFB (Output FeedBack)
mode, and stores the decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object without any padding
in OFB (Output FeedBack) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object without any padding
in OFB (Output FeedBack) mode, and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object without any padding
in OFB (Output FeedBack) mode, and stores the decrypted data
in array [V; M]. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> PCBC_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> PCBC_ISO<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
str object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
iv: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, iv: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str with the padding defined according to
ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, iv: T, message: &str, cipher: &mut [U; N], ) -> u64
str object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
String object with the padding
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
iv: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, iv: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object with the padding
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, iv: T, message: &String, cipher: &mut [U; N], ) -> u64
String object with the padding
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, iv: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object with the padding
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object with the padding
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
encrypted data in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, iv: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, iv: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str with the padding defined according to
ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the decrypted data in array [V; M]. Read moreSource§fn decrypt_array_into_string<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut String,
) -> u64
fn decrypt_array_into_string<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut String, ) -> u64
[U; N] object with the padding
defined according to ISO 7816-4 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the decrypted data in String. Read moreSource§impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> PCBC_PKCS7<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
impl<const ROUND: usize, const SHIFT: u128, const PC101: u8, const PC102: u8, const PC103: u8, const PC104: u8, const PC105: u8, const PC106: u8, const PC107: u8, const PC108: u8, const PC109: u8, const PC110: u8, const PC111: u8, const PC112: u8, const PC113: u8, const PC114: u8, const PC115: u8, const PC116: u8, const PC117: u8, const PC118: u8, const PC119: u8, const PC120: u8, const PC121: u8, const PC122: u8, const PC123: u8, const PC124: u8, const PC125: u8, const PC126: u8, const PC127: u8, const PC128: u8, const PC129: u8, const PC130: u8, const PC131: u8, const PC132: u8, const PC133: u8, const PC134: u8, const PC135: u8, const PC136: u8, const PC137: u8, const PC138: u8, const PC139: u8, const PC140: u8, const PC141: u8, const PC142: u8, const PC143: u8, const PC144: u8, const PC145: u8, const PC146: u8, const PC147: u8, const PC148: u8, const PC149: u8, const PC150: u8, const PC151: u8, const PC152: u8, const PC153: u8, const PC154: u8, const PC155: u8, const PC156: u8, const PC201: u8, const PC202: u8, const PC203: u8, const PC204: u8, const PC205: u8, const PC206: u8, const PC207: u8, const PC208: u8, const PC209: u8, const PC210: u8, const PC211: u8, const PC212: u8, const PC213: u8, const PC214: u8, const PC215: u8, const PC216: u8, const PC217: u8, const PC218: u8, const PC219: u8, const PC220: u8, const PC221: u8, const PC222: u8, const PC223: u8, const PC224: u8, const PC225: u8, const PC226: u8, const PC227: u8, const PC228: u8, const PC229: u8, const PC230: u8, const PC231: u8, const PC232: u8, const PC233: u8, const PC234: u8, const PC235: u8, const PC236: u8, const PC237: u8, const PC238: u8, const PC239: u8, const PC240: u8, const PC241: u8, const PC242: u8, const PC243: u8, const PC244: u8, const PC245: u8, const PC246: u8, const PC247: u8, const PC248: u8, const IP01: u8, const IP02: u8, const IP03: u8, const IP04: u8, const IP05: u8, const IP06: u8, const IP07: u8, const IP08: u8, const IP09: u8, const IP10: u8, const IP11: u8, const IP12: u8, const IP13: u8, const IP14: u8, const IP15: u8, const IP16: u8, const IP17: u8, const IP18: u8, const IP19: u8, const IP20: u8, const IP21: u8, const IP22: u8, const IP23: u8, const IP24: u8, const IP25: u8, const IP26: u8, const IP27: u8, const IP28: u8, const IP29: u8, const IP30: u8, const IP31: u8, const IP32: u8, const IP33: u8, const IP34: u8, const IP35: u8, const IP36: u8, const IP37: u8, const IP38: u8, const IP39: u8, const IP40: u8, const IP41: u8, const IP42: u8, const IP43: u8, const IP44: u8, const IP45: u8, const IP46: u8, const IP47: u8, const IP48: u8, const IP49: u8, const IP50: u8, const IP51: u8, const IP52: u8, const IP53: u8, const IP54: u8, const IP55: u8, const IP56: u8, const IP57: u8, const IP58: u8, const IP59: u8, const IP60: u8, const IP61: u8, const IP62: u8, const IP63: u8, const IP64: u8, const EP01: u8, const EP02: u8, const EP03: u8, const EP04: u8, const EP05: u8, const EP06: u8, const EP07: u8, const EP08: u8, const EP09: u8, const EP10: u8, const EP11: u8, const EP12: u8, const EP13: u8, const EP14: u8, const EP15: u8, const EP16: u8, const EP17: u8, const EP18: u8, const EP19: u8, const EP20: u8, const EP21: u8, const EP22: u8, const EP23: u8, const EP24: u8, const EP25: u8, const EP26: u8, const EP27: u8, const EP28: u8, const EP29: u8, const EP30: u8, const EP31: u8, const EP32: u8, const EP33: u8, const EP34: u8, const EP35: u8, const EP36: u8, const EP37: u8, const EP38: u8, const EP39: u8, const EP40: u8, const EP41: u8, const EP42: u8, const EP43: u8, const EP44: u8, const EP45: u8, const EP46: u8, const EP47: u8, const EP48: u8, const TP01: u8, const TP02: u8, const TP03: u8, const TP04: u8, const TP05: u8, const TP06: u8, const TP07: u8, const TP08: u8, const TP09: u8, const TP10: u8, const TP11: u8, const TP12: u8, const TP13: u8, const TP14: u8, const TP15: u8, const TP16: u8, const TP17: u8, const TP18: u8, const TP19: u8, const TP20: u8, const TP21: u8, const TP22: u8, const TP23: u8, const TP24: u8, const TP25: u8, const TP26: u8, const TP27: u8, const TP28: u8, const TP29: u8, const TP30: u8, const TP31: u8, const TP32: u8, const S000: u8, const S001: u8, const S002: u8, const S003: u8, const S004: u8, const S005: u8, const S006: u8, const S007: u8, const S008: u8, const S009: u8, const S010: u8, const S011: u8, const S012: u8, const S013: u8, const S014: u8, const S015: u8, const S016: u8, const S017: u8, const S018: u8, const S019: u8, const S020: u8, const S021: u8, const S022: u8, const S023: u8, const S024: u8, const S025: u8, const S026: u8, const S027: u8, const S028: u8, const S029: u8, const S030: u8, const S031: u8, const S032: u8, const S033: u8, const S034: u8, const S035: u8, const S036: u8, const S037: u8, const S038: u8, const S039: u8, const S040: u8, const S041: u8, const S042: u8, const S043: u8, const S044: u8, const S045: u8, const S046: u8, const S047: u8, const S048: u8, const S049: u8, const S050: u8, const S051: u8, const S052: u8, const S053: u8, const S054: u8, const S055: u8, const S056: u8, const S057: u8, const S058: u8, const S059: u8, const S060: u8, const S061: u8, const S062: u8, const S063: u8, const S100: u8, const S101: u8, const S102: u8, const S103: u8, const S104: u8, const S105: u8, const S106: u8, const S107: u8, const S108: u8, const S109: u8, const S110: u8, const S111: u8, const S112: u8, const S113: u8, const S114: u8, const S115: u8, const S116: u8, const S117: u8, const S118: u8, const S119: u8, const S120: u8, const S121: u8, const S122: u8, const S123: u8, const S124: u8, const S125: u8, const S126: u8, const S127: u8, const S128: u8, const S129: u8, const S130: u8, const S131: u8, const S132: u8, const S133: u8, const S134: u8, const S135: u8, const S136: u8, const S137: u8, const S138: u8, const S139: u8, const S140: u8, const S141: u8, const S142: u8, const S143: u8, const S144: u8, const S145: u8, const S146: u8, const S147: u8, const S148: u8, const S149: u8, const S150: u8, const S151: u8, const S152: u8, const S153: u8, const S154: u8, const S155: u8, const S156: u8, const S157: u8, const S158: u8, const S159: u8, const S160: u8, const S161: u8, const S162: u8, const S163: u8, const S200: u8, const S201: u8, const S202: u8, const S203: u8, const S204: u8, const S205: u8, const S206: u8, const S207: u8, const S208: u8, const S209: u8, const S210: u8, const S211: u8, const S212: u8, const S213: u8, const S214: u8, const S215: u8, const S216: u8, const S217: u8, const S218: u8, const S219: u8, const S220: u8, const S221: u8, const S222: u8, const S223: u8, const S224: u8, const S225: u8, const S226: u8, const S227: u8, const S228: u8, const S229: u8, const S230: u8, const S231: u8, const S232: u8, const S233: u8, const S234: u8, const S235: u8, const S236: u8, const S237: u8, const S238: u8, const S239: u8, const S240: u8, const S241: u8, const S242: u8, const S243: u8, const S244: u8, const S245: u8, const S246: u8, const S247: u8, const S248: u8, const S249: u8, const S250: u8, const S251: u8, const S252: u8, const S253: u8, const S254: u8, const S255: u8, const S256: u8, const S257: u8, const S258: u8, const S259: u8, const S260: u8, const S261: u8, const S262: u8, const S263: u8, const S300: u8, const S301: u8, const S302: u8, const S303: u8, const S304: u8, const S305: u8, const S306: u8, const S307: u8, const S308: u8, const S309: u8, const S310: u8, const S311: u8, const S312: u8, const S313: u8, const S314: u8, const S315: u8, const S316: u8, const S317: u8, const S318: u8, const S319: u8, const S320: u8, const S321: u8, const S322: u8, const S323: u8, const S324: u8, const S325: u8, const S326: u8, const S327: u8, const S328: u8, const S329: u8, const S330: u8, const S331: u8, const S332: u8, const S333: u8, const S334: u8, const S335: u8, const S336: u8, const S337: u8, const S338: u8, const S339: u8, const S340: u8, const S341: u8, const S342: u8, const S343: u8, const S344: u8, const S345: u8, const S346: u8, const S347: u8, const S348: u8, const S349: u8, const S350: u8, const S351: u8, const S352: u8, const S353: u8, const S354: u8, const S355: u8, const S356: u8, const S357: u8, const S358: u8, const S359: u8, const S360: u8, const S361: u8, const S362: u8, const S363: u8, const S400: u8, const S401: u8, const S402: u8, const S403: u8, const S404: u8, const S405: u8, const S406: u8, const S407: u8, const S408: u8, const S409: u8, const S410: u8, const S411: u8, const S412: u8, const S413: u8, const S414: u8, const S415: u8, const S416: u8, const S417: u8, const S418: u8, const S419: u8, const S420: u8, const S421: u8, const S422: u8, const S423: u8, const S424: u8, const S425: u8, const S426: u8, const S427: u8, const S428: u8, const S429: u8, const S430: u8, const S431: u8, const S432: u8, const S433: u8, const S434: u8, const S435: u8, const S436: u8, const S437: u8, const S438: u8, const S439: u8, const S440: u8, const S441: u8, const S442: u8, const S443: u8, const S444: u8, const S445: u8, const S446: u8, const S447: u8, const S448: u8, const S449: u8, const S450: u8, const S451: u8, const S452: u8, const S453: u8, const S454: u8, const S455: u8, const S456: u8, const S457: u8, const S458: u8, const S459: u8, const S460: u8, const S461: u8, const S462: u8, const S463: u8, const S500: u8, const S501: u8, const S502: u8, const S503: u8, const S504: u8, const S505: u8, const S506: u8, const S507: u8, const S508: u8, const S509: u8, const S510: u8, const S511: u8, const S512: u8, const S513: u8, const S514: u8, const S515: u8, const S516: u8, const S517: u8, const S518: u8, const S519: u8, const S520: u8, const S521: u8, const S522: u8, const S523: u8, const S524: u8, const S525: u8, const S526: u8, const S527: u8, const S528: u8, const S529: u8, const S530: u8, const S531: u8, const S532: u8, const S533: u8, const S534: u8, const S535: u8, const S536: u8, const S537: u8, const S538: u8, const S539: u8, const S540: u8, const S541: u8, const S542: u8, const S543: u8, const S544: u8, const S545: u8, const S546: u8, const S547: u8, const S548: u8, const S549: u8, const S550: u8, const S551: u8, const S552: u8, const S553: u8, const S554: u8, const S555: u8, const S556: u8, const S557: u8, const S558: u8, const S559: u8, const S560: u8, const S561: u8, const S562: u8, const S563: u8, const S600: u8, const S601: u8, const S602: u8, const S603: u8, const S604: u8, const S605: u8, const S606: u8, const S607: u8, const S608: u8, const S609: u8, const S610: u8, const S611: u8, const S612: u8, const S613: u8, const S614: u8, const S615: u8, const S616: u8, const S617: u8, const S618: u8, const S619: u8, const S620: u8, const S621: u8, const S622: u8, const S623: u8, const S624: u8, const S625: u8, const S626: u8, const S627: u8, const S628: u8, const S629: u8, const S630: u8, const S631: u8, const S632: u8, const S633: u8, const S634: u8, const S635: u8, const S636: u8, const S637: u8, const S638: u8, const S639: u8, const S640: u8, const S641: u8, const S642: u8, const S643: u8, const S644: u8, const S645: u8, const S646: u8, const S647: u8, const S648: u8, const S649: u8, const S650: u8, const S651: u8, const S652: u8, const S653: u8, const S654: u8, const S655: u8, const S656: u8, const S657: u8, const S658: u8, const S659: u8, const S660: u8, const S661: u8, const S662: u8, const S663: u8, const S700: u8, const S701: u8, const S702: u8, const S703: u8, const S704: u8, const S705: u8, const S706: u8, const S707: u8, const S708: u8, const S709: u8, const S710: u8, const S711: u8, const S712: u8, const S713: u8, const S714: u8, const S715: u8, const S716: u8, const S717: u8, const S718: u8, const S719: u8, const S720: u8, const S721: u8, const S722: u8, const S723: u8, const S724: u8, const S725: u8, const S726: u8, const S727: u8, const S728: u8, const S729: u8, const S730: u8, const S731: u8, const S732: u8, const S733: u8, const S734: u8, const S735: u8, const S736: u8, const S737: u8, const S738: u8, const S739: u8, const S740: u8, const S741: u8, const S742: u8, const S743: u8, const S744: u8, const S745: u8, const S746: u8, const S747: u8, const S748: u8, const S749: u8, const S750: u8, const S751: u8, const S752: u8, const S753: u8, const S754: u8, const S755: u8, const S756: u8, const S757: u8, const S758: u8, const S759: u8, const S760: u8, const S761: u8, const S762: u8, const S763: u8> PCBC_PKCS7<u64> for DES_Generic<ROUND, SHIFT, PC101, PC102, PC103, PC104, PC105, PC106, PC107, PC108, PC109, PC110, PC111, PC112, PC113, PC114, PC115, PC116, PC117, PC118, PC119, PC120, PC121, PC122, PC123, PC124, PC125, PC126, PC127, PC128, PC129, PC130, PC131, PC132, PC133, PC134, PC135, PC136, PC137, PC138, PC139, PC140, PC141, PC142, PC143, PC144, PC145, PC146, PC147, PC148, PC149, PC150, PC151, PC152, PC153, PC154, PC155, PC156, PC201, PC202, PC203, PC204, PC205, PC206, PC207, PC208, PC209, PC210, PC211, PC212, PC213, PC214, PC215, PC216, PC217, PC218, PC219, PC220, PC221, PC222, PC223, PC224, PC225, PC226, PC227, PC228, PC229, PC230, PC231, PC232, PC233, PC234, PC235, PC236, PC237, PC238, PC239, PC240, PC241, PC242, PC243, PC244, PC245, PC246, PC247, PC248, IP01, IP02, IP03, IP04, IP05, IP06, IP07, IP08, IP09, IP10, IP11, IP12, IP13, IP14, IP15, IP16, IP17, IP18, IP19, IP20, IP21, IP22, IP23, IP24, IP25, IP26, IP27, IP28, IP29, IP30, IP31, IP32, IP33, IP34, IP35, IP36, IP37, IP38, IP39, IP40, IP41, IP42, IP43, IP44, IP45, IP46, IP47, IP48, IP49, IP50, IP51, IP52, IP53, IP54, IP55, IP56, IP57, IP58, IP59, IP60, IP61, IP62, IP63, IP64, EP01, EP02, EP03, EP04, EP05, EP06, EP07, EP08, EP09, EP10, EP11, EP12, EP13, EP14, EP15, EP16, EP17, EP18, EP19, EP20, EP21, EP22, EP23, EP24, EP25, EP26, EP27, EP28, EP29, EP30, EP31, EP32, EP33, EP34, EP35, EP36, EP37, EP38, EP39, EP40, EP41, EP42, EP43, EP44, EP45, EP46, EP47, EP48, TP01, TP02, TP03, TP04, TP05, TP06, TP07, TP08, TP09, TP10, TP11, TP12, TP13, TP14, TP15, TP16, TP17, TP18, TP19, TP20, TP21, TP22, TP23, TP24, TP25, TP26, TP27, TP28, TP29, TP30, TP31, TP32, S000, S001, S002, S003, S004, S005, S006, S007, S008, S009, S010, S011, S012, S013, S014, S015, S016, S017, S018, S019, S020, S021, S022, S023, S024, S025, S026, S027, S028, S029, S030, S031, S032, S033, S034, S035, S036, S037, S038, S039, S040, S041, S042, S043, S044, S045, S046, S047, S048, S049, S050, S051, S052, S053, S054, S055, S056, S057, S058, S059, S060, S061, S062, S063, S100, S101, S102, S103, S104, S105, S106, S107, S108, S109, S110, S111, S112, S113, S114, S115, S116, S117, S118, S119, S120, S121, S122, S123, S124, S125, S126, S127, S128, S129, S130, S131, S132, S133, S134, S135, S136, S137, S138, S139, S140, S141, S142, S143, S144, S145, S146, S147, S148, S149, S150, S151, S152, S153, S154, S155, S156, S157, S158, S159, S160, S161, S162, S163, S200, S201, S202, S203, S204, S205, S206, S207, S208, S209, S210, S211, S212, S213, S214, S215, S216, S217, S218, S219, S220, S221, S222, S223, S224, S225, S226, S227, S228, S229, S230, S231, S232, S233, S234, S235, S236, S237, S238, S239, S240, S241, S242, S243, S244, S245, S246, S247, S248, S249, S250, S251, S252, S253, S254, S255, S256, S257, S258, S259, S260, S261, S262, S263, S300, S301, S302, S303, S304, S305, S306, S307, S308, S309, S310, S311, S312, S313, S314, S315, S316, S317, S318, S319, S320, S321, S322, S323, S324, S325, S326, S327, S328, S329, S330, S331, S332, S333, S334, S335, S336, S337, S338, S339, S340, S341, S342, S343, S344, S345, S346, S347, S348, S349, S350, S351, S352, S353, S354, S355, S356, S357, S358, S359, S360, S361, S362, S363, S400, S401, S402, S403, S404, S405, S406, S407, S408, S409, S410, S411, S412, S413, S414, S415, S416, S417, S418, S419, S420, S421, S422, S423, S424, S425, S426, S427, S428, S429, S430, S431, S432, S433, S434, S435, S436, S437, S438, S439, S440, S441, S442, S443, S444, S445, S446, S447, S448, S449, S450, S451, S452, S453, S454, S455, S456, S457, S458, S459, S460, S461, S462, S463, S500, S501, S502, S503, S504, S505, S506, S507, S508, S509, S510, S511, S512, S513, S514, S515, S516, S517, S518, S519, S520, S521, S522, S523, S524, S525, S526, S527, S528, S529, S530, S531, S532, S533, S534, S535, S536, S537, S538, S539, S540, S541, S542, S543, S544, S545, S546, S547, S548, S549, S550, S551, S552, S553, S554, S555, S556, S557, S558, S559, S560, S561, S562, S563, S600, S601, S602, S603, S604, S605, S606, S607, S608, S609, S610, S611, S612, S613, S614, S615, S616, S617, S618, S619, S620, S621, S622, S623, S624, S625, S626, S627, S628, S629, S630, S631, S632, S633, S634, S635, S636, S637, S638, S639, S640, S641, S642, S643, S644, S645, S646, S647, S648, S649, S650, S651, S652, S653, S654, S655, S656, S657, S658, S659, S660, S661, S662, S663, S700, S701, S702, S703, S704, S705, S706, S707, S708, S709, S710, S711, S712, S713, S714, S715, S716, S717, S718, S719, S720, S721, S722, S723, S724, S725, S726, S727, S728, S729, S730, S731, S732, S733, S734, S735, S736, S737, S738, S739, S740, S741, S742, S743, S744, S745, S746, S747, S748, S749, S750, S751, S752, S753, S754, S755, S756, S757, S758, S759, S760, S761, S762, S763>
Source§fn encrypt(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: *mut u8,
) -> u64
fn encrypt( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: *mut u8, ) -> u64
Source§fn decrypt(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: *mut u8,
) -> u64
fn decrypt( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: *mut u8, ) -> u64
Source§fn encrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut [U; N],
) -> u64
fn encrypt_into_array<U, const N: usize>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_into_vec<U>(
&mut self,
iv: u64,
message: *const u8,
length_in_bytes: u64,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_into_vec<U>( &mut self, iv: u64, message: *const u8, length_in_bytes: u64, cipher: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_array<U, const N: usize>(
&mut self,
iv: u64,
cipher: *const u8,
length_in_bytes: u64,
message: &mut [U; N],
) -> u64
fn decrypt_into_array<U, const N: usize>( &mut self, iv: u64, cipher: *const u8, length_in_bytes: u64, message: &mut [U; N], ) -> u64
[U; N]. Read moreSource§fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
fn encrypt_str(&mut self, iv: T, message: &str, cipher: *mut u8) -> u64
str object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_str_into_vec<U>(
&mut self,
iv: T,
message: &str,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_str_into_vec<U>( &mut self, iv: T, message: &str, cipher: &mut Vec<U>, ) -> u64
str with the padding defined according to
PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<U>. Read moreSource§fn encrypt_str_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &str,
cipher: &mut [U; N],
) -> u64
fn encrypt_str_into_array<U, const N: usize>( &mut self, iv: T, message: &str, cipher: &mut [U; N], ) -> u64
str object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
fn encrypt_string(&mut self, iv: T, message: &String, cipher: *mut u8) -> u64
String object with the padding
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_string_into_vec<U>(
&mut self,
iv: T,
message: &String,
cipher: &mut Vec<U>,
) -> u64
fn encrypt_string_into_vec<U>( &mut self, iv: T, message: &String, cipher: &mut Vec<U>, ) -> u64
String object with the padding
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the encrypted data in Vec<U>. Read moreSource§fn encrypt_string_into_array<U, const N: usize>(
&mut self,
iv: T,
message: &String,
cipher: &mut [U; N],
) -> u64
fn encrypt_string_into_array<U, const N: usize>( &mut self, iv: T, message: &String, cipher: &mut [U; N], ) -> u64
String object with the padding
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the encrypted data in array [U; N]. Read moreSource§fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
fn encrypt_vec<U>(&mut self, iv: T, message: &Vec<U>, cipher: *mut u8) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut Vec<V>,
) -> u64
fn encrypt_vec_into_vec<U, V>( &mut self, iv: T, message: &Vec<U>, cipher: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the encrypted data in Vec<V>. Read moreSource§fn encrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
message: &Vec<U>,
cipher: &mut [V; N],
) -> u64
fn encrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, message: &Vec<U>, cipher: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the encrypted data in array [V; N]. Read moreSource§fn encrypt_array<U, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: *mut u8,
) -> u64
fn encrypt_array<U, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: *mut u8, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn encrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut Vec<V>,
) -> u64
fn encrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut Vec<V>, ) -> u64
[U; N] object with the padding
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
encrypted data in Vec<V>. Read moreSource§fn encrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
message: &[U; N],
cipher: &mut [V; M],
) -> u64
fn encrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, message: &[U; N], cipher: &mut [V; M], ) -> u64
[U; N] object with the padding
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
encrypted data in array [V; M]. Read moreSource§fn decrypt_into_vec<U>(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut Vec<U>,
) -> u64
fn decrypt_into_vec<U>( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut Vec<U>, ) -> u64
Vec<U>. Read moreSource§fn decrypt_into_string(
&mut self,
iv: T,
cipher: *const u8,
length_in_bytes: u64,
message: &mut String,
) -> u64
fn decrypt_into_string( &mut self, iv: T, cipher: *const u8, length_in_bytes: u64, message: &mut String, ) -> u64
String. Read moreSource§fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
fn decrypt_vec<U>(&mut self, iv: T, cipher: &Vec<U>, message: *mut u8) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn decrypt_vec_into_vec<U, V>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut Vec<V>,
) -> u64
fn decrypt_vec_into_vec<U, V>( &mut self, iv: T, cipher: &Vec<U>, message: &mut Vec<V>, ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_vec_into_array<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut [V; N],
) -> u64
fn decrypt_vec_into_array<U, V, const N: usize>( &mut self, iv: T, cipher: &Vec<U>, message: &mut [V; N], ) -> u64
Vec<U> object with the padding defined
according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and
stores the decrypted data in array [V; N]. Read moreSource§fn decrypt_vec_into_string<U>(
&mut self,
iv: T,
cipher: &Vec<U>,
message: &mut String,
) -> u64
fn decrypt_vec_into_string<U>( &mut self, iv: T, cipher: &Vec<U>, message: &mut String, ) -> u64
str with the padding defined according to
PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode, and stores the
decrypted data in String. Read moreSource§fn decrypt_array<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: *mut u8,
) -> u64
fn decrypt_array<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: *mut u8, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode. Read moreSource§fn decrypt_array_into_vec<U, V, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut Vec<V>,
) -> u64
fn decrypt_array_into_vec<U, V, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut Vec<V>, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the decrypted data in Vec<V>. Read moreSource§fn decrypt_array_into_array<U, V, const N: usize, const M: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut [V; M],
) -> u64
fn decrypt_array_into_array<U, V, const N: usize, const M: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut [V; M], ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the decrypted data in array [V; M]. Read moreSource§fn decrypt_array_into_string<U, const N: usize>(
&mut self,
iv: T,
cipher: &[U; N],
message: &mut String,
) -> u64
fn decrypt_array_into_string<U, const N: usize>( &mut self, iv: T, cipher: &[U; N], message: &mut String, ) -> u64
[U; N] object with the padding
defined according to PKCS #7 in PCBC (Propagation Cipher-Block Chaining) mode,
and stores the decrypted data in String. Read more