最終的なエンコードコード(^ 2 に修正)
javascript
コードをコピーする
let str = "https://x.gd";

// 奇数番目の文字にXOR演算を適用
let encoded = str
    .split("")  // 文字列を1文字ずつ分解
    .map((char, ind) => {
        // 奇数番目の文字にXOR演算(charCodeAt()で文字コード取得)
        if (ind % 2 !== 0) {
            return String.fromCharCode(char.charCodeAt() ^ 2); // XOR演算(^2に変更)
        }
        return char; // 偶数番目の文字はそのまま
    })
    .join("");  // 文字列に戻す

// URLエンコード
encoded = encodeURIComponent(encoded);

console.log(encoded);  // 期待されるエンコード結果を表示
最終的なデコードコード
javascript
コードをコピーする
function decode(encodedStr) {
  // URLデコード
  let decodedStr = decodeURIComponent(encodedStr);
  
  // 文字列を1文字ずつ処理
  return decodedStr
    .split("")
    .map((char, ind) => {
      // 奇数番目の文字に対してXOR演算を戻す
      if (ind % 2 !== 0) {
        return String.fromCharCode(char.charCodeAt() ^ 2); // XOR演算(^2に変更)
      }
      // 偶数番目の文字はそのまま
      return char;
    })
    .join("");  // 文字列に戻す
}

// 使用例
let encoded = "hvtrs8%2F-x%2Cgf%2F"; // エンコードされた文字列
console.log(decode(encoded));  // 元の文字列 "https://x.gd" を表示