0% found this document useful (0 votes)
45 views3 pages

Private Sub HalfByte

This document describes a subroutine called HalfByte() that performs compression and decompression of text. It takes in a text string, converts each character to a number, combines character numbers into binary values, and encodes the binary values into a compressed string. For decompression, it reverses these steps to reconstruct the original text string from the compressed values. Key steps include using bit shifting and logical operators to combine character codes, and conditionally adding or subtracting values during encoding and decoding. The subroutine has an if/else structure to handle compression or decompression based on a compres flag.

Uploaded by

alls_alls
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

Private Sub HalfByte

This document describes a subroutine called HalfByte() that performs compression and decompression of text. It takes in a text string, converts each character to a number, combines character numbers into binary values, and encodes the binary values into a compressed string. For decompression, it reverses these steps to reconstruct the original text string from the compressed values. Key steps include using bit shifting and logical operators to combine character codes, and conditionally adding or subtracting values during encoding and decoding. The subroutine has an if/else structure to handle compression or decompression based on a compres flag.

Uploaded by

alls_alls
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Private Sub HalfByte() // apelarea subrutinei HalfByte ( funcie ?!

) // declararea variabilelor ce vor fi folosite n program; // forma de declarare Dim Variable Name As Data Type // // Dim n(255) As Integer // declararea unui vector de 255 de elemente n care vor fi // introduse date de tip ntreg Dim c(255) As String // declararea unui vector de 255 de elemente n care vor fi // introduse date de tip caracter Dim n1 As Integer Dim n2 As Integer Dim n11 As Integer Dim n112 As Integer Dim sir1 As String Dim sir2 As String Dim i As Integer Dim parimpar As Integer sir1 = Text1.text r = Len(sir1) parimpar = r Mod 2 If compres = 0 Then 'Compresie For i = 1 To r n(i) = Mid(sir1, i, 1) Next sir2 = Chr(35) If parimpar = 0 Then For i = 1 To r Step 2 n1 = n(i) n2 = n(i + 1) n11 = LShiftLong(n1, 4) n112 = n11 Or n2 If n112 <= 62 Or n112 >= 97 Then sir2 = sir2 + Chr(n112 + 64) Else sir2 = sir2 + Chr(n112 - 32) End If Next Else For i = 1 To r - 1 Step 2 n1 = n(i) n2 = n(i + 1)

n11 = LShiftLong(n1, 4) n112 = n11 Or n2 If n112 <= 62 Or n112 >= 97 Then sir2 = sir2 + Chr(n112 + 64) Else sir2 = sir2 + Chr(n112 - 32) End If Next sir2 = sir2 + CStr(n(r)) End If 'Text2.text = sir2 Text2.text = Polialfabetica(sir2, 0) End If If compres = 1 Then 'Decompresie sir1 = Polialfabetica(sir1, 1) For i = 1 To r c(i) = Mid(sir1, i, 1) Next sir2 = "" If Asc(c(r)) >= Asc(0) And Asc(c(r)) <= Asc(9) Then For i = 2 To r - 1 If Asc(c(i)) >= 64 Or Asc(c(i)) >= 161 Then n11 = Asc(c(i)) - 64 Else n11 = Asc(c(i)) + 32 End If n1 = RShiftLong(n11, 4) n2 = n11 And 15 sir2 = sir2 + CStr(n1) + CStr(n2) Next sir2 = sir2 + c(r) Else For i = 2 To r If Asc(c(i)) >= 64 Or Asc(c(i)) >= 161 Then n11 = Asc(c(i)) - 64 Else n11 = Asc(c(i)) + 32 End If n1 = RShiftLong(n11, 4) n2 = n11 And 15 sir2 = sir2 + CStr(n1) + CStr(n2) Next End If Text2.text = sir2 End If

Text2.SaveFile fd, rtfText Call fisier(fd, False) End Sub

You might also like