Skip to content

Instantly share code, notes, and snippets.

@einblicker
Created February 18, 2012 16:23
Show Gist options
  • Save einblicker/1860037 to your computer and use it in GitHub Desktop.
Save einblicker/1860037 to your computer and use it in GitHub Desktop.
リードソロモン符号を用いた符号化
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