5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CODE39 のチェックデジット

Last updated at Posted at 2015-10-29

モジュラス43。

調べたページで、堂々と中黒が入ってて「???」ってなった。

perl

my $i = 0 ;
my %h = map{ $_, $i ++ } split //, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%';
my %hr = reverse %h ;

print $hr{ +( eval join '+', map{ $h{$_} } split //, 'PIYOPIYO'  )  % 43 } ;
  • アホだ、ダブルコーテーションになってた。変数展開するじゃん。

VBA

Function modulus43(ByVal d As String)
    Dim str As String
    str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
    Dim i As Integer
    Dim j As Integer
    Dim o As Integer

    For i = 1 To Len(d)
        For j = 0 To 42
            If Mid(d, i, 1) = Mid(str, j + 1, 1) Then
                o = o + j
                Exit For
            End If
        Next j
    Next i
    modulus43 = Mid(str, (o Mod 43) + 1, 1)
End Function

適当なセルにて =modulus43(A1) とかする、、、

ruby

a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%".split("") 
h = (a).zip(0...a.size).to_h 
hr = h.invert
p hr[ "PIYOPIYO" .split("").map{|x| h[x] }.inject(:+) % 43 ]

.to_h は、ruby 2.1 からだそーで。

5
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?