Created
February 18, 2012 16:23
-
-
Save einblicker/1860037 to your computer and use it in GitHub Desktop.
リードソロモン符号を用いた符号化
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object RSEncoder { | |
def encode(raw_code: Array[Int]) = { | |
val gf = GaloisField.a8 | |
val g_index = Array( | |
43, 139, 206, 78, 43, 239, 123, 206, 214, | |
147, 24, 99, 150, 39, 243, 163, 136 | |
) | |
val code = | |
Array.fill(math.max(raw_code.length, g_index.length) + 1)(0) | |
for(i <- 0 until raw_code.length) | |
code(i) = raw_code(i) | |
for (_ <- 0 until raw_code.length) { | |
if (code(0) != 0) { | |
val div = gf.root(code(0)) | |
for (i <- 0 until code.length - 1) { | |
code(i) = | |
if (i < g_index.length) code(i + 1) ^ gf.pow((g_index(i) + div) % 255) | |
else code(i + 1) | |
} | |
} else { | |
for(i <- 0 until code.length - 1) code(i) = code(i + 1) | |
} | |
} | |
for (i <- 0 until g_index.length) | |
print(code(i) + " ") | |
} | |
def test = { | |
val raw_code = Array(32, 65, 205, 69, 41, 220, 46, 128, 236) | |
encode(raw_code) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment