作爲其中一個標準Java庫的一部分,是否已有rot13()
和unrot13()
實現?還是我必須自己寫和「重新發明輪子」?java中的ROT-13函數?
它可能是這個樣子:
int rot13 (int c) {
if ((c >= 'A') && (c <= 'Z'))
c=(((c-'A')+13)%26)+'A';
if ((c >= 'a') && (c <= 'z'))
c=(((c-'a')+13)%26)+'a';
return c;
}
@BNL我個人比較喜歡rot104。需要專用協處理器 –
@BNL LOL誰說這是出於安全目的?請參閱[這](http://stackoverflow.com/questions/3928903/what-are-some-practical-applications-of-the-rot13-algorithm) –
順便說一句,rot13是它自己的逆,所以你不'實際上需要一個「unrot13」方法。 –