String and binary transformation (not including Chinese characters)

zhaozj2021-02-16  63

For the interchange of binary and characters, it is because I want to do a DES encrypted program, and now I will release my source originate now:

First create a project to draw two TextBox on the frame, named Text1, Text2 two commandbutton, named Command1, Command1 Other definitions Go to it! Rem This program is made by qthinker, free, can be modified, please keep this information Option Base 1Private Function Byte2bit (S AS String) AS STRINGDIM I AS INTEGER, J AS INTEGER, K AS INTEGER, ILEN AS INTEGERDIM BY () AS STRINGDIM B () AS INTEGERILEN = LEN (S) Redim BY (ILEN) Redim B Ilen / 8) for K = 1 To Ilen By (K) = MID $ (S, K, 1) Next K

For i = 1 to (Ilen / 8) IF BY (1 8 * (i - 1)) = "1" THENB (I) = B (i) OR & H80ELSEB (i) = b (i) AND & H7f End IFIF BY (2 8 * (i - 1)) = "1" THEN B (I) = B (i) OR & H40 ELSE B (i) = b (i) AND HBFEND IF BY (3 8 * (i - 1) = "1" THEN B (I) = B (i) or & H20 else b (i) = b (i) AND HDFEND IF IF BY (4 8 * (i - 1)) = "1" THEN B (I) = B (i) OR & H10 ELSE B (I) = B (i) and & hef end if IF by (5 8 * (i - 1)) = "1" THEN B (I) = B (i) OR & H8 ELSE B (I) = b (i) and & hf7 end if IF by (6 8 * (i - 1)) = "1" THEN B (I) = B (i) OR & H4 ELSE B (i) = b (i) and & hfbend if IF by (7 8 * (i - 1)) = "1" THEN B (i) = b (i) or & h2 else b (i) = b (i) AND & HFD END IFIF BY (8 8 * (i - 1)) = "1" THEN B (I) = B (i) or "1" ELSE B (i) = B (i) And & HFEEND IFBYTE2BIT = Byte2bit & CHR $ (b (i))

NEXT IEND FUNCTIONPRIVATE FUNCTION Bit2byte (S AS String) AS STRINGDIM S2 AS STRINGDIM X AS STRINGDIM I AS ILEN AS INTEGER

Ilen = LEN (S) DIM B () DIM S1 () Redim S1 (Ilen) Redim B (Ilen * 8) S2 = "" for i = 1 to Ilen x = MID $ (S, I, 1) S1 (I ) = ASC (x) IF S1 (i) and & h80 THEN B (1 8 * (i - 1)) = 1 else b (1 8 * (i - 1)) = 0 end if

IF S1 (i) and & H40 THEN B (2 8 * (i - 1)) = 1 else b (2 8 * (i - 1)) = 0 END IF IF S1 (i) AND & H20 THEN B (3 8 * (i - 1)) = 1 else b (3 8 * (i - 1)) = 0 END IF

IF S1 (i) AND & H10 THEN B (4 8 * (i - 1)) = 1 ELSE B (4 8 * (i - 1)) = 0 END IF

IF S1 (i) and & h8 THEN B (5 8 * (i - 1)) = 1 else b (5 8 * (i - 1)) = 0 END IF IF S1 (i) AND & H4 THEN B (6 8 * (i - 1)) = 1 else b (6 8 * (i - 1)) = 0 END IF IF S1 (i) AND & H2 THEN B (7 8 * (i - 1)) = 1 ELSE B (7 8 * (i - 1)) = 0 END IF IF S1 (i) and "1" THEN B (8 8 * (i - 1)) = 1ELSE B (8 8 * (i - 1)) = 0 end if Next I

For K = 1 to Ilen * 8 S2 = S2 & B (K) IF K MOD 8 = 0 THEN S2 = S2 end if next kbit2byte = s2nd function

Private Sub Command1_Click () DIM S AS STRINGDIM S2 AS STRINGS = TEXT1.TEXTS2 = bit2byte (s) text2.text = S2END SUB

PRIVATE SUB Command2_Click () DIM S AS STRINGDIM S1 AS STRINGS = text2.texts1 = byte2bit (s) text2.text = S1END SUB

转载请注明原文地址:https://www.9cbs.com/read-22404.html

New Post(0)