#N88BASIC

'データを暗号化
Function EnC(in As *Byte, out As *Byte, l As Long) As Long
  Dim Cind As Long
  out[0] = in[0]
  For Cind = 1 To l-1
    out[Cind] = in[Cind]-in[Cind-1]
  Next  

End Function

'データを複合化
Function DeC(in As *Byte, out As *Byte, l As Long) As Long
  Dim Cind As Long
  out[0] = in[0]
  For Cind = 1 To l-1
    out[Cind] = in[Cind]+out[Cind-1]
  Next  
End Function


Function Show(in As *Byte, l As Long) As Long
  Dim Cind As Long
  Dim ele[45] As Byte

  For Cind = 0 To l-1
    wsprintf(ele, "%02x ", in[Cind])
    Print  MakeStr(ele);
  Next
  Print ""
End Function

'testo
Dim in[10] As Byte'元
Dim out[10] As Byte'暗号
Dim out2[10] As Byte'複合

wsprintf(in, "阿部高和")
Show(in, 10)

EnC(in, out, 10)
Show(out, 10)

DeC(out, out2, 10)
Show(out2, 10)

別解

APIにEncryptFile関数があり「ファイルまたはディレクトリを暗号化します。」とある。解除はDecryptFile関数を使う。
これはファイル、フォルダのプロバティにある[属性]->[詳細設定]で暗号化するもの。
  • win2000異常でないと使えない。
MSDNにはインポートライブラリ:kernel32.lib を使用と書いてあるけどウソ。Advapi32.libが正解。

#N88BASIC
Declare Function EncryptFile Lib"Advapi32" Alias "EncryptFileA" (lpFileName As *Byte) As Long
Declare Function DecryptFile Lib"Advapi32" Alias "DecryptFileA" (lpFileName As *Byte,dwReserved As DWord) As Long
Dim h As String
Print EncryptFile("eeeee.txt")
input h
Print DecryptFile("eeeee.txt",0)
最終更新:2010年01月29日 10:00