Skip to content

Commit

Permalink
StringObfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Jan 28, 2024
1 parent aa881ab commit 55ebf8d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package pricemigrationengine.util
import java.time.LocalDate

object StringObfuscation {

val string1: String = "0123456789AST-" // Do not edit this string!
val string2: String = "456789AST0123&" // Do not edit this string!

def obfuscate(x: Char): Char = {
val index = string1.indexOf(x)
if (index >= 0) {
string2.charAt(index)
} else {
x
}
}

def obfuscate(s: String): String = s.toList.map(obfuscate).mkString("")

def recover(x: Char): Char = {
val index = string2.indexOf(x)
if (index >= 0) {
string1.charAt(index)
} else {
x
}
}

def recover(s: String): String = s.toList.map(recover).mkString("")
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package pricemigrationengine.migrations

import pricemigrationengine.model._

import java.time.LocalDate
import pricemigrationengine.Fixtures
import pricemigrationengine.migrations.newspaper2024Migration.Estimation._
import pricemigrationengine.migrations.newspaper2024Migration.Amendment._
import pricemigrationengine.migrations.newspaper2024Migration.{Estimation, StaticData}
import pricemigrationengine.migrations.newspaper2024Migration.StaticData.{ChargeDistribution2024, IndividualCharge2024}
import pricemigrationengine.util.StringObfuscation

/*
Correspondence between product names in Salesforce versus Zuora
Expand Down Expand Up @@ -1619,4 +1621,9 @@ class Newspaper2024MigrationTest extends munit.FunSuite {
)
}

test("String Obfuscation") {
assertEquals(StringObfuscation.obfuscate("A-Testing0"), "1&3esting4")
assertEquals(StringObfuscation.recover("1&3esting4"), "A-Testing0")
}

}

0 comments on commit 55ebf8d

Please sign in to comment.