Jump to content

Recommended Posts

Posted (edited)

This is not a "Request Forum", this is a "Support Forum" as the name suggests.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • Moderators
Posted

ChenYangHuan,

Topics merged. How about sticking to just the one at a time. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

What effort have you put in so far? Did you read the help file?

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

ChenYangHuan,

I don't get your point about c#...

How much experience do you have with Autoit?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

  • Moderators
Posted

ChenYangHuan,

I have merged your topics again - you have now started 3 on the same subject. This time I am telling you: Do NOT start another one or sanctions will follow! :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Please post the AutoIt code you have written so far! That's the way we try to help users here!

No code - no help!

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Mr.Chen,please post your script here & some others will try to answer your problems.At least I'm not good at coding.But I would rack my brain to solve my problems.At last,I still thank so many teachers from here who want to solve my problems. :thumbsup: Here is the place where you can learn many new things ,etc...! :rambo:

Posted

What everyone is trying to get at is that you are not going to get any help if you do not wish to learn. People on this forum do not write code for you. If you want that, search google for rent-a-coder.

If you are interested in getting help, then you must first try to learn a bit about autoit. Once you have an example of some kind of attempt, then people will help you. We fix Broken scripts, not write the entire thing for people.

  Reveal hidden contents
 
Posted (edited)

I try to read understanding_sms.pdf and try to write but then i don't know if sms length >8T

This code:

#include <String.au3>
MsgBox(0,"",Encode("SMS RulzSMS Rulz"))



;~ Code
Func Encode($Text)
$x=StringLen($Text)/8
If StringLen($Text)/8<>Round(StringLen($Text)/8) Then $x=$x+1
$Result=""
For $i=1 To $x
$Result&=To7bit(StringLeft($Text,8))
    If $i<>$x Then $Text=StringMid($Text,9)
Next
Return $Result
EndFunc
Func To7bit($Text)
$Text=_StringToHex($Text)
Local $Array[StringLen($Text)/2+1]
Local $Array2[StringLen($Text)/2]
$S=StringLen($Text)/2-1
For $i=1 to StringLen($Text)/2
$Array[$i]=StringMid(_HexToBinaryString(StringLeft($Text,2)),2)
$Text=StringMid($Text,3)
Next
For $i=1 to $S
$Array2[$i]=StringRight($Array[$i+1],$i)&$Array[$i]
If $i<>StringLen($Text)/2-2 Then $Array[$i+1]=StringMid($Array[$i+1],1,StringLen($Array[$i+1])-$i)
Next
Return _BinaryToHexString($Array2[1]&$Array2[2]&$Array2[3]&$Array2[4]&$Array2[5]&$Array2[6]&$Array2[7])
EndFunc
Func _BinaryToHexString($BinaryValue)
Local $test, $Result = '',$numbytes,$nb
If StringRegExp($BinaryValue,'[0-1]') then
if $BinaryValue = '' Then
SetError(-2)
Return
endif
Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111"
$bits = stringsplit($bits,'|')
#region check string is binary
$test = stringreplace($BinaryValue,'1','')
$test = stringreplace($test,'0','')
if $test <> '' Then
SetError(-1);non binary character detected
Return
endif
#endregion check string is binary
#region make binary string an integral multiple of 4 characters
While 1
$nb = Mod(StringLen($BinaryValue),4)
if $nb = 0 then exitloop
$BinaryValue = '0' & $BinaryValue
WEnd
#endregion make binary string an integral multiple of 4 characters
$numbytes = Int(StringLen($BinaryValue)/4);the number of bytes
Dim $bytes[$numbytes],$Deci[$numbytes]
For $j = 0 to $numbytes - 1;for each byte
;extract the next byte
$bytes[$j] = StringMid($BinaryValue,1+4*$j,4)
;find what the dec value of the byte is
for $k = 0 to 15;for all the 16 possible hex values
if $bytes[$j] = $bits[$k+1] Then
$Deci[$j] = $k
                ExitLoop
EndIf
next
Next
;now we have the decimal value for each byte, so stitch the string together again
$Result = ''
for $l = 0 to $numbytes - 1
$Result &= Hex($Deci[$l],1)
    Next
return $Result
Else
    MsgBox(0,"Error","Wrong input, try again ...")
    Return
EndIf
EndFunc


; Hex To Binary
Func _HexToBinaryString($HexValue)
Local $Allowed = '0123456789ABCDEF'
Local $Test,$n
Local $Result = ''
if $hexValue = '' then
SetError(-2)
Return
EndIf

$hexvalue = StringSplit($hexvalue,'')
for $n = 1 to $hexValue[0]
if not StringInStr($Allowed,$hexvalue[$n]) Then
SetError(-1)
return 0
EndIf
Next

Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111"
$bits = stringsplit($bits,'|')
for $n = 1 to $hexvalue[0]
$Result &= $bits[Dec($hexvalue[$n])+1]
Next

Return $Result

EndFunc

understanding_sms.pdf

Edited by ChenYangHuan
Posted

I try http://twit88.com/home/utility/sms-pdu-encode-decode

Then I see SMS Rulz->D3E61424ADB3F5

and SMS RulzSMS Rulz->D3E61424ADB3F5D3E61424ADB3F5

So, I think get length/8 is encode one time...

I think i can do it!

Thank for reply me!

Posted

This complete code: :sweating: :sweating:

$var=_Encode("Chen Yang Huan")
ClipPut(_Encode("Chen Yang Huan"))
MsgBox(0,"",_Decode("4374D90DCA86DD6710B21E7603"))
;~ /////////////////////////////////////////////////////
;~ /////////////////////////////////////////////////////
Func _Encode($Text)
Local $Result=""
$x=Int(StringLen($Text)/8)
If $x<>StringLen($Text)/8 Then $x+=1
For $i=1 To $x
$Result&=_8bitTo7bit(StringLeft($Text,8))
If $i<>$x Then $Text=StringMid($Text,9)
Next
Return $Result
EndFunc

Func _Decode($Text)
Local $Result=""
$x=Int(StringLen($Text)/14)
If $x<>StringLen($Text)/14 Then $x+=1
For $i=1 To $x
$Result&=_HexToString(_7bitTo8bit(StringLeft($Text,14)))
If $i<>$x Then $Text=StringMid($Text,15)
Next
Return $Result
EndFunc
Func _7bitTo8bit($Text)
Local $Result=""
Local $Septets[7], $Octets[8]
For $i=0 To 6
$Septets[$i]=_HexToBinaryString(StringMid($Text,$i*2+1,2))
If $Septets[$i]="" Then ExitLoop
Next
$LengTh=0
If $i=7 And StringLeft($Septets[$i-1],7)="0001101" Then
$LengTh=7
EndIf
If $i=7 And StringLeft($Septets[$i-1],7)<>"0001101" Then
$LengTh=8
EndIf
For $j=$i-1 To 0 Step -1
If $j=0 Then
$Octets[$j]=StringRight($Septets[$j],7)
$Result=_BinaryToHexString($Octets[$j])&$Result
ExitLoop
EndIf
If $LengTh=7 Then
$LengTh=0
EndIf
If $LengTh=8 Then
$LengTh=0
$Octets[7]=StringLeft($Septets[6],7)
EndIf
If $LengTh=0 Then
$Octets[$j]=StringRight($Septets[$j],7-$j)&StringLeft($Septets[$j-1],$j)
$Result=_BinaryToHexString($Octets[$j])&$Result
EndIf
Next
If $Octets[7]<>"" Then $Result&=_BinaryToHexString($Octets[7])
Return $Result
EndFunc


Func _8bitTo7bit($Text)
Local $Result=""
Local $Septets[7], $Octets[8]
For $i=0 To 7
$Octets[$i]=StringMid(_HexToBinaryString(StringMid(_StringToHex($Text),$i*2+1,2)),2)
If $Octets[$i]="" Then
If $i=7 Then $Octets[$i]="0001101"
ExitLoop
EndIf
Next
For $i=0 To 6
$Septets[$i]=StringRight($Octets[$i+1],$i+1)&StringLeft($Octets[$i],7-$i)
If $Septets[$i]<>"" Then
If StringLen($Septets[$i])<8 Then
For $j=1 To 8 - StringLen($Septets[$i])
$Septets[$i]="0"&$Septets[$i]
Next
EndIf
$Result&=_BinaryToHexString($Septets[$i])
Else
ExitLoop
EndIf
Next
Return $Result
EndFunc

Func _BinaryToHexString($BinaryValue)
Local $test, $Result = '',$numbytes,$nb
If StringRegExp($BinaryValue,'[0-1]') then
if $BinaryValue = '' Then
SetError(-2)
Return
endif
Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111"
$bits = stringsplit($bits,'|')
#region check string is binary
$test = stringreplace($BinaryValue,'1','')
$test = stringreplace($test,'0','')
if $test <> '' Then
SetError(-1);non binary character detected
Return
endif
#endregion check string is binary
#region make binary string an integral multiple of 4 characters
While 1
$nb = Mod(StringLen($BinaryValue),4)
if $nb = 0 then exitloop
$BinaryValue = '0' & $BinaryValue
WEnd
#endregion make binary string an integral multiple of 4 characters
$numbytes = Int(StringLen($BinaryValue)/4);the number of bytes
Dim $bytes[$numbytes],$Deci[$numbytes]
For $j = 0 to $numbytes - 1;for each byte
;extract the next byte
$bytes[$j] = StringMid($BinaryValue,1+4*$j,4)
;find what the dec value of the byte is
for $k = 0 to 15;for all the 16 possible hex values
if $bytes[$j] = $bits[$k+1] Then
$Deci[$j] = $k
ExitLoop
EndIf
next
Next
;now we have the decimal value for each byte, so stitch the string together again
$Result = ''
for $l = 0 to $numbytes - 1
$Result &= Hex($Deci[$l],1)
Next
return $Result
Else
Return
EndIf
EndFunc


; Hex To Binary
Func _HexToBinaryString($HexValue)
Local $Allowed = '0123456789ABCDEF'
Local $Test,$n
Local $Result = ''
if $hexValue = '' then
SetError(-2)
Return
EndIf

$hexvalue = StringSplit($hexvalue,'')
for $n = 1 to $hexValue[0]
if not StringInStr($Allowed,$hexvalue[$n]) Then
SetError(-1)
return 0
EndIf
Next

Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111"
$bits = stringsplit($bits,'|')
for $n = 1 to $hexvalue[0]
$Result &= $bits[Dec($hexvalue[$n])+1]
Next

Return $Result

EndFunc

Func _HexToString($strHex)
If StringLeft($strHex, 2) = "0x" Then Return BinaryToString($strHex)
Return BinaryToString("0x" & $strHex)
EndFunc

Func _StringToHex($strChar)
Return Hex(StringToBinary($strChar))
EndFunc
Posted (edited)

ChenYangHuan,

If you continue to maintain that level of persistence you will not only go far as a coder but also on this Forum. Well done and nice code.

Note: Look at the Bit* functions in the help file.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 7 years later...
Posted

 

Dear Mr. Melba23
I apologize for my childhood actions 😆😆 When I reviewed the posts, I thought it was weird!

Thank you guinness!
It may have been a long time since I returned to this forum. That day I was just a student, and now I am a programmer with a stable income.
Starting with AutoIT, when I look back there are many shortcomings in thinking, but that is the foundation.
Once again thank everyone!

 

  • Moderators
Posted

ChenYangHuan,

Delighted to hear of your success.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...