Works on Android to Android, or iOS to iOS (with limited cross-platform support).

Warning: Do not delete the codes from the old phone until you have successfully signed into Gmail on the new phone using the ported code.

First, understanding what this code is—and isn’t—is essential. When you enable two-factor authentication (2FA) on your Gmail account, Google offers several methods: SMS text messages, Google Prompt (tap “Yes” on a trusted device), or an authenticator app that generates a rotating six-digit code. The most common standard for these apps is TOTP (Time-based One-Time Password) , defined in RFC 6238.

A TOTP code is derived from a shared secret key (usually a 16–32 character base32 string) and the current Unix time, sliced into 30-second windows. The algorithm produces a six-digit number. This code changes every 30 seconds, and the server (Google) independently computes the same code based on the shared secret and the same time window. If your entered code matches, access is granted.

# portable_totp.py - requires only Python + pyotp
import pyotp
import getpass
import base64

Despite the rise of biometrics (fingerprints and face scans), the six-digit code remains a crucial layer of security because it relies on something you know (or possess), rather than something you are.

Biometrics are convenient, but they cannot be changed. If a database of fingerprints is hacked, you can't get new fingers. A six-digit code, however, is dynamic. It changes every 30 seconds. This transience is what makes it so powerful. Even if a hacker looks over your shoulder and sees the code, it becomes useless within half a minute.

secret = "JBSWY3DPEHPK3PXP" # example base32 secret for Gmail

totp = pyotp.TOTP(secret) print(f"Current 6-digit code: totp.now()")

To make it truly portable:


Before we talk about portability, we must understand the code itself. When you enable 2-Step Verification (2SV) on your Google account, you link a physical device (usually a smartphone) to your account. Every 30 seconds, that device generates a fresh, one-time password (OTP) consisting of six digits.

Why six digits?
Math. Six digits provide 1 million possible combinations (000,000 to 999,999). Given that the code expires every 30 seconds, brute-forcing it is statistically impossible.

This code is required after you enter your correct password. It acts as "something you have" (your phone) in addition to "something you know" (your password).

Share.

5 Comments

Leave A Reply